From 198e271a3befa92e3b48e4cabbc3febd9d51bf35 Mon Sep 17 00:00:00 2001 From: Jerry Kuang Date: Tue, 10 Sep 2024 16:24:48 +0000 Subject: [PATCH] [PURR][#2561]Fix issue that doi is created when submitting a publication that has been reverted before --- .../com_publications/models/doi.php | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/core/components/com_publications/models/doi.php b/core/components/com_publications/models/doi.php index 908501b252..cdef71a50d 100644 --- a/core/components/com_publications/models/doi.php +++ b/core/components/com_publications/models/doi.php @@ -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 @@ -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); @@ -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'); @@ -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 */ @@ -1083,7 +1084,7 @@ public function registerURL($doi, $resURL = "") } /** - * Update DOI metadata + * Update DOI metadata on DataCite * * @param string $doi * @@ -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); @@ -1125,6 +1126,7 @@ public function dataciteMetadataUpdate($doi) $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); + curl_close($ch); if ($code == 201 || $code == 200) @@ -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'); @@ -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; } /**