Пример #1
0
 public function update()
 {
     $xml = '';
     $errorMessages = '';
     $notifyMessage = '';
     $logMessage = '';
     $outstr = '';
     $doiObjects = null;
     $response1 = "OK";
     $response2 = "OK";
     $app_id = $this->input->get('app_id');
     //passed as a parameter
     $urlValue = $this->input->get('url');
     //passed as a parameter
     $doiValue = $this->input->get('doi');
     //passed as a parameter
     $doi = getxml($doiValue);
     // check if doi is a valid doi and get information about it
     $ip_address = trim($_SERVER['REMOTE_ADDR']);
     if ($doi->num_rows() > 0) {
         //we need to get the xml if that is to be updated as well
         if ($_POST) {
             if (str_replace("<?xml version=", "", implode($_POST)) == implode($_POST)) {
                 $xml = "<?xml version=" . implode($_POST);
                 // passed as posted content
             } else {
                 $xml = implode($_POST);
                 // passed as posted content
             }
         }
         //first up, lets check that this client is permitted to update this doi.
         $client_id = checkDoisValidClient($ip_address, $app_id);
         if (!$client_id) {
             $errorMessages .= $this->doisGetUserMessage("MT009", $doi_id = NULL);
             header("HTTP/1.0 415 Authentication Error");
         } else {
             if (!checkDoisClientDoi($doiValue, $client_id)) {
                 $errorMessages .= $this->doisGetUserMessage("MT008", $doiValue);
                 header("HTTP/1.0 415 Authentication Error");
             }
         }
         if ($xml) {
             $doiObjects = new DOMDocument();
             $result = $doiObjects->loadXML($xml);
             $errors = error_get_last();
             if ($errors) {
                 $errorMessages .= "Document Load Error: " . $errors['message'] . "\n";
                 header("HTTP/1.0 500 Internal Server Error");
             } else {
                 // Validate it against the datacite schema.
                 error_reporting(0);
                 // Create temporary file and save manually created DOMDocument.
                 $tempFile = "/tmp/" . time() . '-' . rand() . '-document.tmp';
                 $doiObjects->save($tempFile);
                 // Create temporary DOMDocument and re-load content from file.
                 $doiObjects = new DOMDocument();
                 $doiObjects->load($tempFile);
                 //Delete temporary file.
                 if (is_file($tempFile)) {
                     unlink($tempFile);
                 }
                 //$result = $doiObjects->schemaValidate(gCMD_SCHEMA_URI);
                 $xml = $doiObjects->saveXML();
                 $errors = error_get_last();
                 if ($errors) {
                     $errorMessages .= $this->doisGetUserMessage("MT007", $doi_id = NULL);
                     $errorMessages .= "Document Validation Error: " . $errors['message'] . "\n";
                     header("HTTP/1.0 500 Internal Server Error");
                 }
             }
         }
         if ($errorMessages == '') {
             // Update doi information
             $updateError = updateDoiObject($doiValue, $doiObjects, $urlValue, $xml);
             if (!$updateError) {
                 // Update the DOI.
                 if ($urlValue) {
                     $response1 = $this->doisRequest("mint", $doiValue, $urlValue, $xml, $client_id);
                 }
                 if ($doiObjects) {
                     $response2 = $this->doisRequest("update", $doiValue, $urlValue, $xml, $client_id);
                 }
                 if ($response1 && $response2) {
                     if ($response1 == gDOIS_RESPONSE_SUCCESS && $response2 == gDOIS_RESPONSE_SUCCESS) {
                         // We have successfully updated the doi through datacite.
                         $notifyMessage = $this->doisGetUserMessage("MT002", $doiValue);
                         header("HTTP/1.0 200 OK");
                     } else {
                         $errorMessages .= $this->doisGetUserMessage("MT010", $doi = NULL);
                         $logMessage = "MT010 " . $response;
                         header("HTTP/1.0 500 Internal Server Error");
                     }
                 } else {
                     $errorMessages .= $this->doisGetUserMessage("MT005", $doi = NULL);
                     header("HTTP/1.0 500 Internal Server Error");
                 }
             } else {
                 $errorMessages .= '<br />' . $updateError;
                 header("HTTP/1.0 500 Internal Server Error");
             }
         }
     } else {
         $errorMessages .= $this->doisGetUserMessage("MT011", $doi_id = $doiValue);
     }
     echo $errorMessages;
     echo $notifyMessage;
 }
Пример #2
0
 function activate()
 {
     $errorMessages = '';
     $notifyMessage = '';
     $outstr = '';
     $urlValue = '';
     $verbosemessage = '';
     $client_id = '';
     if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) {
         $ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
     } else {
         if (isset($_SERVER["HTTP_CLIENT_IP"])) {
             $ip = $_SERVER["HTTP_CLIENT_IP"];
         } else {
             if (isset($_SERVER["REMOTE_ADDR"])) {
                 $ip = $_SERVER["REMOTE_ADDR"];
             } else {
                 // Run by command line??
                 $ip = "127.0.0.1";
             }
         }
     }
     $debug = $this->input->get('debug');
     if ($debug && $debug == 'true') {
         $this->debugOn();
     }
     //$app_id = $this->input->get('app_id');		//passed as a parameter
     $app_id = $this->getAppId();
     if (substr($app_id, 0, 4) == 'TEST') {
         $app_id = substr($app_id, 4, strlen($app_id));
         $testing = 'yes';
     }
     $doiValue = $this->input->get('doi');
     //passed as a parameter
     $doiValue = rawurldecode($doiValue);
     $response_type = $this->input->get('response_type');
     //passed as a parameter
     if (!$response_type) {
         $response_type = 'string';
     }
     $api_version = $this->input->get('api_version');
     if (!$api_version) {
         $api_version = '1.0';
     }
     if (!$app_id) {
         $errorMessages = doisGetUserMessage("MT010", $doiValue, $response_type, $app_id, "You must provide an app id to update a doi", $urlValue);
     }
     if (!$doiValue) {
         $errorMessages = doisGetUserMessage("MT010", $doiValue, $response_type, $app_id, "You must provide the doi value to update a doi", $urlValue);
     }
     //first up, lets check that this client is permitted to update this doi.
     if ($errorMessages == '') {
         $client_id = checkDoisValidClient($ip, $app_id);
         if ($client_id === false) {
             $verbosemessage = '';
             $errorMessages = doisGetUserMessage("MT009", $doiValue, $response_type, $app_id, $verbosemessage, $urlValue);
         } else {
             if (checkDoisClientDoi($doiValue, $client_id) === false) {
                 $verbosemessage = '';
                 $errorMessages = doisGetUserMessage("MT008", $doiValue, $response_type, $app_id, $verbosemessage, $urlValue);
             }
         }
     }
     if ($errorMessages == '') {
         if (getDoiStatus($doiValue) != "INACTIVE") {
             $verbosemessage = "DOI " . $doiValue . " is not set to inactive so cannot activate it.<br />";
             $errorMessages = doisGetUserMessage("MT010", $doiValue, $response_type, $app_id, $verbosemessage, $urlValue);
         }
         if ($errorMessages == '') {
             // Update doi information
             $status = "ACTIVE";
             $activateResult = setDoiStatus($doiValue, $status);
             $doidata = getxml($doiValue);
             if ($doidata->num_rows() > 0) {
                 foreach ($doidata->result() as $row) {
                     $xml = $row->datacite_xml;
                 }
             }
             if (!$activateResult) {
                 // Activate the DOI.
                 $response = $this->doisRequest("update", $doiValue, $urlValue = NULL, $xml, $client_id);
                 if ($response) {
                     if (doisGetResponseType($response) == gDOIS_RESPONSE_SUCCESS || $response == gDOIS_RESPONSE_SUCCESS) {
                         // We have successfully activated the doi through datacite.
                         $notifyMessage = doisGetUserMessage("MT004", $doiValue, $response_type, $app_id, $response, $urlValue);
                     } else {
                         $activateResult = setDoiStatus($doiValue, 'INACTIVE');
                         $errorMessages = doisGetUserMessage("MT010", $doiValue, $response_type, $app_id, $response, $urlValue);
                     }
                 } else {
                     $errorMessages = doisGetUserMessage("MT005", $doiValue, $response_type, $app_id, $verbosemessage, $urlValue);
                 }
             } else {
                 $verbosemessage = $response;
                 $errorMessages = doisGetUserMessage("MT010", $doiValue, $response_type, $app_id, $verbosemessage, $urlValue);
             }
         }
     }
     if ($errorMessages) {
         $outstr = $errorMessages;
         //We need to log this activity as errorred
         insertDoiActivity("ACTIVATE", $doiValue, "FAILURE", $client_id, $errorMessages);
     }
     if ($notifyMessage) {
         //We need to log this activity as successful
         insertDoiActivity("ACTIVATE", $doiValue, "SUCCESS", $client_id, $notifyMessage);
         $outstr = $notifyMessage;
     }
     //we now need to return the result back to the calling program.
     echo $outstr;
 }