Created
November 12, 2020 02:01
-
-
Save dnwk/cdeb897cb27f3bd251d7c74ee653729c to your computer and use it in GitHub Desktop.
Update URLs for Portfolios in Alma using API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$array = array('53144697050001867'); | |
$collection_id = "61119399690001867"; | |
$service_id = "62119399680001867"; | |
$api_key = "l8xx"; | |
foreach ($array as $portfolio_id ){ | |
$url = 'https://api-na.hosted.exlibrisgroup.com/almaws/v1/electronic/e-collections/' . $collection_id . '/e-services/' . $service_id . '/portfolios/' . $portfolio_id . '?apikey=' . $api_key; | |
// Get portfolio XML | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); | |
curl_setopt($ch, CURLOPT_HEADER, FALSE); | |
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); | |
$response = curl_exec($ch); | |
curl_close($ch); | |
// Rewrite link | |
$xml = simplexml_load_string($response); | |
$mmsid = (string) $xml->resource_metadata->mms_id; | |
//$xml_url = (string) $xml->linking_details->url; | |
$xml_url = (string) $xml->linking_details->url ?: ((string) $xml->linking_details->static_url ?: (string) $xml->linking_details->static_url_override); | |
preg_match('/^(.)+doi\.org\/10.\d{4,9}\/[-._;()\/:A-Z0-9]+/i', $xml_url, $new_url_array); | |
if(!empty($new_url_array[0])){ | |
$new_url = $new_url_array[0] . '?locatt=mode:legacy'; | |
$xml->linking_details->url = $new_url; | |
$xml->linking_details->url_type = 'static'; | |
$xml->linking_details->static_url = $new_url; | |
$xml->linking_details->static_url_override = ""; | |
$portfolio_object = (string) $xml->asXML(); | |
// Update portfolio | |
$ch2 = curl_init(); | |
curl_setopt($ch2, CURLOPT_URL, $url); | |
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, TRUE); | |
curl_setopt($ch2, CURLOPT_HEADER, FALSE); | |
curl_setopt($ch2, CURLOPT_CUSTOMREQUEST, 'PUT'); | |
curl_setopt($ch2, CURLOPT_POSTFIELDS, $portfolio_object); | |
curl_setopt($ch2, CURLOPT_HTTPHEADER, array('Content-Type: application/xml')); | |
$response2 = curl_exec($ch2); | |
curl_close($ch2); | |
}else{ | |
echo "error".$portfolio_id ."\r\n"; | |
} | |
unset($$portfolio_id); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment