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; }
function update() { $xml = ''; $errorMessages = ''; $notifyMessage = ''; $logMessage = ''; $verbosemessage = ''; $outstr = ''; $doiObjects = null; $response1 = "OK"; $response2 = "OK"; $testing = 'no'; $dataciteSchema = $this->config->item('gCMD_SCHEMA_URIS'); $debug = $this->input->get('debug'); if ($debug && $debug == 'true') { $this->debugOn(); } $manual_update = $this->input->get('manual_update'); if ($manual_update) { $client_id = rawurldecode($this->input->get_post('client_id')); } $app_id = $this->getAppId(); if (substr($app_id, 0, 4) == 'TEST') { $app_id = substr($app_id, 4, strlen($app_id)); $testing = 'yes'; } $urlValue = $this->input->get('url'); //passed as a parameter $urlValue = rawurldecode($urlValue); $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); } 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"; } } } if ($errorMessages == '') { if (!$manual_update) { $client_id = checkDoisValidClient($ip, $app_id); } $client_domains = getClientDomains($client_id); if ($client_id === false) { $errorMessages = doisGetUserMessage("MT009", $doiValue, $response_type, $app_id, $verbosemessage, $urlValue); } else { if (checkDoisClientDoi($doiValue, $client_id) === false) { $errorMessages = doisGetUserMessage("MT008", $doiValue, $response_type, $app_id, $verbosemessage, $urlValue); } } } if ($errorMessages == '') { $doidata = getxml($doiValue); // check if doi is a valid doi and get information about it if ($doidata->num_rows() > 0) { $xml = $this->getXmlInput(); //first up, lets check that this client is permitted to update this doi. $xml_row = $doidata->row(); $old_xml = $xml_row->datacite_xml; if (trim($xml) === trim($old_xml)) { $xml = ''; } if (isset($xml) && $xml) { $doiObjects = new DOMDocument(); $result = $doiObjects->loadXML($xml); $errors = error_get_last(); if ($errors) { $errorMessages = "Document Load Error: " . $errors['message'] . "\n"; } 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); } $resources = $doiObjects->getElementsByTagName('resource'); $theSchema = 'unknown'; if ($resources->length > 0) { if (isset($resources->item(0)->attributes->item(0)->name)) { $theSchema = $this->getXmlSchema($resources->item(0)->attributes->item(0)->nodeValue); } } $result = $doiObjects->schemaValidate(asset_url('schema') . $dataciteSchema[$theSchema]); $xml = $doiObjects->saveXML(); $errors = error_get_last(); if ($errors || !$result) { $verbosemessage = "Document Validation Error: " . $errors['message'] . "\n"; $errorMessages = doisGetUserMessage("MT007", doiValue, $response_type, $app_id, $verbosemessage, $urlValue); } } } if (!$this->validDomain($urlValue, $client_domains)) { $verbosemessage = 'URL not permitted.'; $errorMessages = doisGetUserMessage("MT014", $doi_id = NULL, $response_type, $app_id, $verbosemessage, $urlValue); } if ($errorMessages == '') { // Update doi information $updateError = updateDoiObject($doiValue, $doiObjects, $urlValue, $xml); if (!$updateError) { /* Fix: 09/01/2013, DataCite requires metadata FIRST, then DOI call */ // Send DataCite the metadata first // Update the DOI if ($doiObjects && $xml) { $response2 = $this->doisRequest("update", $doiValue, $urlValue, $xml, $client_id); } if ($urlValue) { $response1 = $this->doisRequest("mint", $doiValue, $urlValue, $xml, $client_id); } if ($response1 && $response2) { if (doisGetResponseType($response1) == gDOIS_RESPONSE_SUCCESS && doisGetResponseType($response2) == gDOIS_RESPONSE_SUCCESS) { // We have successfully updated the doi through datacite. $verbosemessage = $response1 . " / " . $response2; $notifyMessage = doisGetUserMessage("MT002", $doiValue, $response_type, $app_id, $verbosemessage, $urlValue); } else { $verbosemessage = $response1 . " / " . $response2; $errorMessages = doisGetUserMessage("MT010", $doiValue, $response_type, $app_id, $verbosemessage, $urlValue); } } else { $verbosemessage = ''; if ($response1 != gDOIS_RESPONSE_SUCCESS) { $verbosemessage .= $response1; } if ($response2 != gDOIS_RESPONSE_SUCCESS) { $verbosemessage .= $response2; } $errorMessages = doisGetUserMessage("MT005", $doi = NULL, $response_type, $app_id, $verbosemessage, $urlValue); } } else { $verbosemessage = $updateError; $errorMessages = doisGetUserMessage("MT010", $doi = NULL, $response_type, $app_id, $verbosemessage, $urlValue); } } } else { $errorMessages = doisGetUserMessage("MT011", $doi_id = $doiValue, $response_type, $app_id, $verbosemessage, $urlValue); } } if ($errorMessages) { $outstr = $errorMessages; //We need to log this activity as errorred insertDoiActivity("UPDATE", $doiValue, "FAILURE", $client_id, $errorMessages); } if ($notifyMessage) { //We need to log this activity insertDoiActivity("UPDATE", $doiValue, "SUCCESS", $client_id, $notifyMessage); $outstr = $notifyMessage; } echo $errorMessages; echo $notifyMessage; }