Skip to content

Commit

Permalink
[PURR][#2561]Fix issue that doi is created when submitting a publicat…
Browse files Browse the repository at this point in the history
…ion that has been reverted before
  • Loading branch information
kuang5 authored and nkissebe committed Sep 10, 2024
1 parent f0a08e5 commit 198e271
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions core/components/com_publications/models/doi.php
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,8 @@ public function buildXml($doi = null)
}

/**
* Run cURL to register metadata. When input $doi is null, it is going to create DOI on DataCite.
* Run cURL to register metadata. When input $doi is null as well as only DOI shoulder is set in $url,
* it is going to create DOI on DataCite.
*
* @param string $url
* @param array $postVals
Expand All @@ -941,9 +942,9 @@ public function regMetadata($url, $postvals, &$doi)
curl_setopt($ch, CURLOPT_USERPWD, $this->_configs->dataciteUserPW);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postvals);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:text/plain;charset=UTF-8', 'Content-Length: ' . strlen($postvals)));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml;charset=UTF-8'));
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');

$response = curl_exec($ch);

Expand Down Expand Up @@ -992,7 +993,7 @@ public function regURL($url, $postvals)
curl_setopt($ch, CURLOPT_USERPWD, $this->_configs->dataciteUserPW);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postvals);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:text/plain;charset=UTF-8', 'Content-Length: ' . strlen($postvals)));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:text/plain;charset=UTF-8'));
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');

Expand Down Expand Up @@ -1020,7 +1021,7 @@ public function regURL($url, $postvals)
/**
* Register DOI metadata. This is the first step to create DOI name and register metadata on DataCite.
*
* @param string $doi - It is null when the function is used for DOI registration. Otherwise, the function is used for updating DOI state on DataCite.
* @param string $doi
*
* @return string $doi
*/
Expand Down Expand Up @@ -1083,7 +1084,7 @@ public function registerURL($doi, $resURL = "")
}

/**
* Update DOI metadata
* Update DOI metadata on DataCite
*
* @param string $doi
*
Expand All @@ -1105,16 +1106,16 @@ public function dataciteMetadataUpdate($doi)
return false;
}

$metadataURL = $this->_configs->dataciteServiceURL . DS . 'metadata';
$metadataURL = $this->_configs->dataciteServiceURL . DS . 'metadata' . DS . $doi;
$xml = $this->buildXml($doi);

$ch = curl_init($metadataURL);
curl_setopt($ch, CURLOPT_USERPWD, $this->_configs->dataciteUserPW);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:text/plain;charset=UTF-8', 'Content-Length: ' . strlen($xml)));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml;charset=UTF-8'));
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');

$response = curl_exec($ch);

Expand All @@ -1125,6 +1126,7 @@ public function dataciteMetadataUpdate($doi)

$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);


curl_close($ch);

if ($code == 201 || $code == 200)
Expand Down Expand Up @@ -1426,7 +1428,7 @@ public function dataciteDoiStatusUpdate($doi, $stateSwitch)
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_USERPWD, $this->_configs->dataciteUserPW);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:text/plain;charset=UTF-8'));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/plain;charset=UTF-8'));
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');

Expand All @@ -1445,10 +1447,8 @@ public function dataciteDoiStatusUpdate($doi, $stateSwitch)
return false;
}
}
elseif ($stateSwitch == self::STATE_FROM_DRAFTREADY_TO_PUBLISHED)
{
return $this->registerMetadata($doi);
}

return true;
}

/**
Expand Down

0 comments on commit 198e271

Please sign in to comment.