drush_print("Example: drush php-script editMODSTopics.php islandora:collection_name_here"); return; } // include all Tuque php files $tuquePath = libraries_get_path('tuque') . '/*.php'; foreach (glob($tuquePath) as $filename) { require_once $filename; } # repository connection parameters $url = 'localhost:8080/fedora'; $username = '******'; $password = '******'; # set up connection and repository variables $connection = new RepositoryConnection($url, $username, $password); $api = new FedoraApi($connection); $repository = new FedoraRepository($api, new SimpleCache()); # query to grab all pdf collection objects from the repository $sparqlQuery = "SELECT ?s\n FROM <#ri>\n WHERE {\n ?s <info:fedora/fedora-system:def/relations-external#isMemberOfCollection> \n <info:fedora/{$collection}> .\n }"; # run query drush_print("\n*****Querying repository for all PDF objects..."); $allPDFObjects = $repository->ri->sparqlQuery($sparqlQuery); drush_print("\n*****Query complete*****\n"); // how many total objects are there in the collection? $totalNumObjects = count($allPDFObjects); drush_print("There are {$totalNumObjects} objects to be processed"); // establish a counter for how many objects we edit $objectsChanged = 0; // keep track of how many troublesome objects we had to skip $skippedObjects = array(); // main loop for ALL PDF OBJECTS in the collection drush_print("\n******Beginning main processing loop*****\n");
/** * @param FedoraRepository $repository * @param string $identifier * @return array */ function getObjectForIdentifier($identifier, $repository) { global $fedoraPassword, $fedoraUser, $solrUrl; //Check Solr to see if we have created the compound object yet $escapedIdentifer = str_replace(':', '\\:', $identifier); $solrQuery = "?q=mods_identifier_ms:\"{$escapedIdentifer}\"&fl=PID,dc.title"; $context = stream_context_create(array('http' => array('header' => "Authorization: Basic " . base64_encode("{$fedoraUser}:{$fedoraPassword}")))); //echo("checking solr ".$solrUrl . $solrQuery."<br/>"); $ch = curl_init(); $connectTimeout = 5; $timeout = 20; curl_setopt($ch, CURLOPT_URL, $solrUrl . $solrQuery); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $connectTimeout); curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $curTry = 0; $maxTries = 3; while ($curTry < $maxTries) { $solrResponse = curl_exec($ch); if ($solrResponse !== false) { //We got a good response, stop looking. break; } $curTry++; } curl_close($ch); if (!$solrResponse) { die("Solr is currently down"); } else { $solrResponse = json_decode($solrResponse); if ($solrResponse->response->numFound == 0) { $newObject = true; $existingPID = false; } else { $newObject = false; $existingPID = $solrResponse->response->docs[0]->PID; } } //Basic settings for this content type $namespace = 'fortlewis'; //Create an object (this will create a new PID) /** @var AbstractFedoraObject $object */ if ($newObject) { $object = $repository->constructObject($namespace); } else { $object = $repository->getObject($existingPID); } return array($object, $newObject); }
// $nodeList = $domdoc->getElementsByTagName('namePart'); // foreach ($domdoc->getElementsByTagName('namePart') as $entry) // { // $entryType = $entry->getAttribute('type'); // print $entry->nodeValue . " " . $entry->getAttribute('type') . "\n"; // } print $domdoc->saveXML($domdoc->documentElement); // $modsDatastream->setContentFromString($domdoc); return; $url = 'localhost:8080/fedora'; $username = '******'; $password = '******'; # set up connection and repository variables $connection = new RepositoryConnection($url, $username, $password); $api = new FedoraApi($connection); $repository = new FedoraRepository($api, new SimpleCache()); # what is the pid you want? $pid = 'islandora:3'; # what to change the name to? $givenName = "Mickey"; $familyName = "Mouse"; $wholeName = $givenName . ' ' . $familyName; # try to fetch PID from repo try { $object = $repository->getObject($pid); } catch (Exception $e) { drush_print('****************ERROR***************'); exit; } # grab the data streams $dublinCoreDS = $object['DC'];
/** * @param FedoraRepository $repository * @param string $personPid * * @return FedoraObject */ function getFedoraObjectByPid($repository, $personPid) { //echo ("Loading Fedora object $personPid"); $fedoraObject = $repository->getObject($personPid); return $fedoraObject; }
require_once ROOT_DIR . '/tuque/Cache.php'; require_once ROOT_DIR . '/tuque/FedoraApi.php'; require_once ROOT_DIR . '/tuque/FedoraApiSerializer.php'; require_once ROOT_DIR . '/tuque/Object.php'; require_once ROOT_DIR . '/tuque/HttpConnection.php'; require_once ROOT_DIR . '/tuque/Repository.php'; require_once ROOT_DIR . '/tuque/RepositoryConnection.php'; require_once ROOT_DIR . '/utils.php'; //Connect to tuque try { $serializer = new FedoraApiSerializer(); $cache = new SimpleCache(); $connection = new RepositoryConnection($fedoraUrl, $fedoraUser, $fedoraPassword); $connection->verifyPeer = false; $api = new FedoraApi($connection, $serializer); $repository = new FedoraRepository($api, $cache); echo "Connected to Tuque OK<br/>\r\n"; ob_flush(); flush(); usleep(100); } catch (Exception $e) { echo "We could not connect to the fedora repository."; die; } //Process each record $i = 0; $numPeopleLoaded = 0; $numRead = 0; global $existingEntities; /** @var SimpleXMLElement $exportedItem */ foreach ($xml->export as $exportedItem) {
<?php //set fits.sh executable first... it could be at /opt/fits //usage //drush php-script regen-obj [root of book object] # repository connection parameters $url = 'localhost:8080/fedora'; $username = '******'; $password = '******'; # set up connection and repository variables $connection = new RepositoryConnection($url, $username, $password); $repository = new FedoraRepository(new FedoraApi($connection), new SimpleCache()); $root_pid = drush_shift(); $parent_obj = $repository->getObject($root_pid); $itql = 'select $page_itql from <#ri> where $page_itql <fedora-rels-ext:isMemberOf> <info:fedora/' . $root_pid . '> order by $page_itql'; $page_objects = $repository->ri->itqlQuery($itql, 'unlimited', '0'); foreach ($page_objects as $page) { $page_pid = $page['page_itql']['value']; $object = islandora_object_load($page_pid); if (!$object->getDataStream('JP2')) { echo "regenerating OBJ for {$page_pid}\n"; $obj_ds = $object['OBJ']; //url of image... http://fedora_repo_url:8080/objects/[pid]/datastreams/OBJ/content $file_url = $repo_url . '/objects/' . $page_pid . '/datastreams/OBJ/content'; $drupal_result = drupal_http_request($file_url); if (!empty($drupal_result->data)) { //create a temporary file $new_file = file_save_data($drupal_result->data, file_default_scheme() . '://'); $path = drupal_realpath($new_file->uri);
require_once ROOT_DIR . '/tuque/Cache.php'; require_once ROOT_DIR . '/tuque/FedoraApi.php'; require_once ROOT_DIR . '/tuque/FedoraApiSerializer.php'; require_once ROOT_DIR . '/tuque/Object.php'; require_once ROOT_DIR . '/tuque/HttpConnection.php'; require_once ROOT_DIR . '/tuque/Repository.php'; require_once ROOT_DIR . '/tuque/RepositoryConnection.php'; require_once ROOT_DIR . '/utils.php'; //Connect to tuque try { $serializer = new FedoraApiSerializer(); $cache = new SimpleCache(); $connection = new RepositoryConnection($fedoraUrl, $fedoraUser, $fedoraPassword); $connection->verifyPeer = false; $api = new FedoraApi($connection, $serializer); $repository = new FedoraRepository($api, $cache); echo "Connected to Tuque OK"; } catch (Exception $e) { echo "We could not connect to the fedora repository."; die; } //Process each record $recordsProcessed = 0; $recordsRead = 0; /** @var SimpleXMLElement $exportedItem */ foreach ($xml->export as $exportedItem) { $recordsRead++; if ($recordsRead <= $recordsToSkip) { continue; } //Check to see if we have the image
/** * @param $fileToLoad * @param $datastream * @param $datastreamLabel * @param $mimeType * @param $existingPID * @param $objectId * @param $datastreamFile * @param FedoraRepository $repository */ function addDatastream($fileToLoad, $datastream, $datastreamLabel, $mimeType, $existingPID, $objectId, $datastreamFile, $repository) { if (!file_exists($fileToLoad)) { fwrite($datastreamFile, "{$existingPID},{$objectId},{$datastream},file does not exist\r\n"); } else { $newPhoto = $repository->getObject($existingPID); $imageDatastream = $newPhoto->constructDatastream($datastream); $imageDatastream->label = $datastreamLabel; $imageDatastream->mimetype = $mimeType; set_time_limit(1600); $imageDatastream->setContentFromFile($fileToLoad); $newPhoto->ingestDatastream($imageDatastream); unset($imageDatastream); fwrite($datastreamFile, "{$existingPID},{$objectId},{$datastream},uploaded\r\n"); } }
require_once ROOT_DIR . '/tuque/Cache.php'; require_once ROOT_DIR . '/tuque/FedoraApi.php'; require_once ROOT_DIR . '/tuque/FedoraApiSerializer.php'; require_once ROOT_DIR . '/tuque/Object.php'; require_once ROOT_DIR . '/tuque/HttpConnection.php'; require_once ROOT_DIR . '/tuque/Repository.php'; require_once ROOT_DIR . '/tuque/RepositoryConnection.php'; require_once ROOT_DIR . '/utils.php'; //Connect to tuque try { $serializer = new FedoraApiSerializer(); $cache = new SimpleCache(); $connection = new RepositoryConnection($fedoraUrl, $fedoraUser, $fedoraPassword); $connection->verifyPeer = false; $api = new FedoraApi($connection, $serializer); $repository = new FedoraRepository($api, $cache); echo "Connected to Tuque OK<br/>\r\n"; } catch (Exception $e) { echo "We could not connect to the fedora repository."; die; } //Open XML file $xml = simplexml_load_file($sourceXMLFile); if (!$xml) { echo "Failed to read XML, boo"; } else { //Loop through each file in XML file //$recordsProcessed = 0; //$recordsRead = 0; //For each record, find the record in Islandora using a Solr query (158 to 191 in evld_past_perfect.php $replacementPids = array();
require_once ROOT_DIR . '/tuque/Cache.php'; require_once ROOT_DIR . '/tuque/FedoraApi.php'; require_once ROOT_DIR . '/tuque/FedoraApiSerializer.php'; require_once ROOT_DIR . '/tuque/Object.php'; require_once ROOT_DIR . '/tuque/HttpConnection.php'; require_once ROOT_DIR . '/tuque/Repository.php'; require_once ROOT_DIR . '/tuque/RepositoryConnection.php'; require_once ROOT_DIR . '/utils.php'; //Connect to tuque try { $serializer = new FedoraApiSerializer(); $cache = new SimpleCache(); $connection = new RepositoryConnection($fedoraUrl, $fedoraUser, $fedoraPassword); $connection->verifyPeer = false; $api = new FedoraApi($connection, $serializer); $repository = new FedoraRepository($api, $cache); echo "Connected to Tuque OK<br/>\r\n"; } catch (Exception $e) { echo "We could not connect to the fedora repository."; die; } //Query Solr for all basic images that need to be replaced with large images $solrQuery = "?q=RELS_EXT_hasModel_uri_s:\"info:fedora/islandora:sp_basic_image\"+AND+PID:evld*&fl=PID,dc.title,RELS_EXT_hasModel_uri_s,fedora_datastreams_ms"; $solrResponse = file_get_contents($solrUrl . $solrQuery . "&limit=1", false); if (!$solrResponse) { die; } else { $solrResponse = json_decode($solrResponse); if (!$solrResponse->response || $solrResponse->response->numFound == 0) { fwrite($logFile, 'No basic images found'); } else {