function updateMODSStream($pid, $version = NULL, $usage = NULL, $xmlString = NULL) { module_load_include('inc', 'fedora_repository', 'fedora_item'); $object = new Fedora_Item($pid); if (!isset($xmlString)) { $mods = $object->get_datastream_dissemination('MODS'); } else { $mods = $xmlString; } $doc = new DOMDocument('1.0', 'UTF-8'); $doc->substituteEntities = FALSE; try { $doc->loadXML($mods); } catch (exception $e) { drupal_set_message(t('Error loading MODS record! ') . $e->getMessage()); return ' '; } if (isset($usage)) { $usageNode = $doc->createElement('accessCondition', $usage); $usageNode->setAttribute('type', 'use and reproduction'); $nodeList = $doc->getElementsByTagName('mods'); foreach ($nodeList as $reference) { $reference->appendChild($usageNode); } } if (isset($version)) { //check if the physicalDescription element exists if ($doc->getElementsByTagName('physicalDescription')->length != 0) { //drupal_set_message(t('physicalDescription element already exists!')); $statusNode = $doc->getElementsByTagName('physicalDescription'); $form_node = $doc->createElement('form', $version); $form_node->setAttribute('authority', 'local'); foreach ($statusNode as $node) { $node->appendChild($form_node); } //add it to the reference node $reference_node_list = $doc->getElementsByTagName('mods'); } else { //create the useage element as it does not exist //drupal_set_message(t('physicalDescription element does not exist, creating...')); $statusNode = $doc->createElement('physicalDescription'); $form_node = $doc->createElement('form', $version); $form_node->setAttribute('authority', 'local'); $statusNode->appendChild($form_node); //add it to the reference node $reference_node_list = $doc->getElementsByTagName('mods'); foreach ($reference_node_list as $reference) { $reference->appendChild($statusNode); } } } $result = $object->modify_datastream_by_value($doc->saveXML(), 'MODS', 'MODS record', 'text/xml', TRUE, 'MODS datastream modified'); }
/** * Exports a fedora collection object and all of its children in a format * that will let you import them into another repository. * @param <type> $format */ function export_collection($collection_pid, $relationship = 'isMemberOfCollection', $format = 'info:fedora/fedora-system:FOXML-1.1') { $collection_item = new Fedora_Item($collection_pid); $foxml = $collection_item->export_as_foxml(); $file_dir = file_directory_path(); // Create a temporary directory to contain the exported FOXML files. $container = tempnam($file_dir, 'export_'); file_delete($container); print $container; if (mkdir($container) && mkdir($container . '/' . $collection_pid)) { $foxml_dir = $container . '/' . $collection_pid; $file = fopen($foxml_dir . '/' . $collection_pid . '.xml', 'w'); fwrite($file, $foxml); fclose($file); $member_pids = get_related_items_as_array($collection_pid, $relationship); foreach ($member_pids as $member) { $file = fopen($foxml_dir . '/' . $member . '.xml', 'w'); $item = new Fedora_Item($member); $item_foxml = $item->export_as_foxml(); fwrite($file, $item_foxml); fclose($file); } if (system("cd {$container};zip -r {$collection_pid}.zip {$collection_pid}/* >/dev/null") == 0) { header("Content-type: application/zip"); header('Content-Disposition: attachment; filename="' . $collection_pid . '.zip' . '"'); $fh = fopen($container . '/' . $collection_pid . '.zip', 'r'); $theData = fread($fh, filesize($container . '/' . $collection_pid . '.zip')); fclose($fh); echo $theData; } if (file_exists($container . '/' . $collection_pid)) { system("rm -rf {$container}"); // I'm sorry. } } else { drupal_set_message("Error creating temp directory for batch export.", 'error'); return false; } return true; }
function ingest_object_from_FOXML($dom) { module_load_include('php', 'Fedora_Repository', 'ConnectionHelper'); module_load_include('php', 'Fedora_Repository', 'api/fedora_item'); try { $object = Fedora_Item::ingest_from_FOXML($dom); return $object; } catch (exception $e) { drupal_set_message(t('Error Ingesting Object! ') . $e->getMessage(), 'error'); $msg = "Error Ingesting Object!" . $e->getMessage(); watchdog(t("Fedora_Repository"), $msg, WATCHDOG_ERROR); return false; } }
/** * Constructor that builds itself by retrieving the RELS-EXT stream from * the repository for the given Fedora_Item. * @param Fedora_Item $item */ function RelsExt($item) { $relsextxml = $item->get_datastream_dissemination('RELS-EXT'); }
/** * using the collection policies pid namespace get a new pid by calling fedora' get next pid and appending it to the namespace * $pid is the $pid of the content model * $dsid is the datastream id of the content model. */ function getNextPid($pid, $dsid) { module_load_include('php', 'Fedora_Repository', 'ConnectionHelper'); $pidNameSpace = $this->getPidNameSpace($pid, $dsid); $pname = substr($pidNameSpace, 0, strpos($pidNameSpace, ":")); module_load_include('php', 'fedora_repository', 'api/fedora_item'); // $pid = Fedora_Item::get_next_pid_in_namespace($pname); // $pid = Fedora_Item::get_next_pid_in_namespace($pname); // $pid = strstr($pid, ":"); // $pid = $pidNameSpace . '-' . substr($pid, 1); // return $pid; return Fedora_Item::get_next_pid_in_namespace($pname); }
function handleVideoCollectionForm($form_values) { $this->handleQDCForm($form_values); $pid = $form_values["pid"]; $object = new Fedora_Item($pid); $path = drupal_get_path('module', 'Fedora_Repository'); $stream = file_get_contents($path . "/epistemetec/xml/VIDEO_COLLECTION_POLICY.xml"); $object->add_datastream_from_string($stream, "COLLECTION_POLICY", "Collection Policy"); $file = $path . "/epistemetec/files/cover-video.png"; $object->add_datastream_from_file($file, "TN", "Thumbnail"); $this->createNode($form_values); }
function handleForm(&$form_values) { $errorMessage = NULL; module_load_include('php', 'Fedora_Repository', 'CollectionClass'); module_load_include('php', 'Fedora_Repository', 'ContentModel'); module_load_include('php', 'fedora_repository', 'api/fedora_item'); $content_model_pid = ContentModel::getPidFromIdentifier($form_values['models']); $content_model_dsid = ContentModel::getDSIDFromIdentifier($form_values['models']); $collectionHelper = new CollectionClass(); $startTime = time(); $collection_pid = $form_values['collection_pid']; $this->parse_refworks_item($form_values); $this->security_helper = new SecurityClass(); $collection_item = new Fedora_Item($collection_pid); $this->collection_policy_stream = $collection_item->get_datastream_dissemination('CHILD_SECURITY'); if (empty($this->collection_policy_stream)) { $this->collection_policy_stream = file_get_contents(drupal_get_path('module', 'fedora_repository') . '/policies/noObjectEditPolicy.xml'); } $success = 0; $errors = 0; foreach ($this->referencelist as $reference) { $dom = new DomDocument("1.0", "UTF-8"); $dom->substituteEntities = FALSE; $dom->formatOutput = true; $pid = $collectionHelper->getNextPid($collection_pid, $content_model_dsid); $rootElement = $dom->createElement("foxml:digitalObject"); $rootElement->setAttribute('VERSION', '1.1'); $rootElement->setAttribute('PID', "{$pid}"); $rootElement->setAttribute('xmlns:foxml', "info:fedora/fedora-system:def/foxml#"); $rootElement->setAttribute('xmlns:xsi', "http://www.w3.org/2001/XMLSchema-instance"); $rootElement->setAttribute('xsi:schemaLocation', "info:fedora/fedora-system:def/foxml# http://www.fedora.info/definitions/1/0/foxml1-1.xsd"); $dom->appendChild($rootElement); //create standard fedora stuff $qdc_element = $this->createQDCStream($dom, $rootElement, $reference); if (!$qdc_element) { drupal_set_message(t('Error Create DC for Refworks'), 'error'); continue; } $item_title = ''; foreach ($reference->t1 as $value) { $item_title .= ' --- ' . $value; } $this->createStandardFedoraStuff($form_values, $dom, $rootElement, $reference); $rootElement->appendChild($qdc_element); //create relationships $this->createRelationShips($form_values, $dom, $rootElement, $pid); //create dublin core $this->createFedoraDataStreams($form_values, $dom, $rootElement, $reference); if (!empty($this->collection_policy_stream)) { $this->create_security_policies($dom, $rootElement, $reference); } $params = array('objectXML' => $dom->saveXML(), 'format' => 'info:fedora/fedora-system:FOXML-1.1', 'logMessage' => "Fedora Object Ingested"); try { $soapHelper = new ConnectionHelper(); $client = $soapHelper->getSoapClient(variable_get('fedora_soap_manage_url', 'http://localhost:8080/fedora/services/management?wsdl')); if ($client == null) { drupal_set_message(t('Error Getting Soap Client.'), 'error'); watchdog(t("FEDORA_REPOSITORY"), t("Error Getting SOAP client") . $e, null, WATCHDOG_ERROR); return; } $object = $client->__soapCall('ingest', array($params)); watchdog(t("FEDORA_REPOSITORY"), t("Successfully added repository item ") . $pid . ' - ' . $item_title, null, WATCHDOG_INFO); $deleteFiles = $form_values['delete_file']; //remove files from drupal file system if ($deleteFiles > 0) { unlink($form_values['fullpath']); } } catch (exception $e) { $errors++; $errorMessage = 'yes'; //drupal_set_message(t('Error Ingesting Object! Check Drupal watchdog logs for more info' . $e->getMessage()), 'error'); watchdog(t("FEDORA_REPOSITORY"), t("Error during ingest") . $item_title . ' ' . $e, null, WATCHDOG_ERROR); //return ' '; } $success++; } if (isset($errorMessage)) { drupal_set_message(t('Error Ingesting one or more records! Check Drupal watchdog logs for more info'), 'error'); } $endTime = time(); drupal_set_message(t('Successfull ingest of %success records. %errors records failed. Ingest took %seconds seconds', array('%success' => $success - $errors, '%errors' => $errors, '%seconds' => $endTime - $startTime)), 'info'); //drupal_set_message(t('ingest took %seconds ',array('%seconds'=>$endTime-$startTime)),'info'); }
static function soap_call($function_name, $params_array) { if (!self::$connection_helper) { module_load_include('php', 'Fedora_Repository', 'ConnectionHelper'); self::$connection_helper = new ConnectionHelper(); } switch ($function_name) { case 'ingest': case 'addDataStream': case 'addRelationship': case 'export': case 'getDatastream': case 'getNextPID': case 'getRelationships': case 'modifyDatastreamByValue': case 'purgeDatastream': case 'purgeObject': $soap_client = self::$connection_helper->getSoapClient(variable_get('fedora_soap_manage_url', 'http://localhost:8080/fedora/services/management?wsdl')); try { $result = $soap_client->__soapCall($function_name, array('parameters' => $params_array)); } catch (exception $e) { drupal_set_message(t("Error trying to call SOAP function {$function_name}. Check watchdog logs for more information."), 'error'); watchdog(t("FEDORA_REPOSITORY"), t("Error Trying to call SOAP function {$function_name}") . $e, NULL, WATCHDOG_ERROR); return NULL; } break; default: try { $soap_client = self::$connection_helper->getSoapClient(variable_get('fedora_soap_url', 'http://localhost:8080/fedora/services/access?wsdl')); $result = $soap_client->__soapCall($function_name, array('parameters' => $params_array)); } catch (exception $e) { watchdog(t("FEDORA_REPOSITORY"), t("Error Trying to call SOAP function {$function_name}") . $e, null, WATCHDOG_ERROR); return null; } } return $result; }
function handleQDCForm($form_values) { module_load_include('php', 'Fedora_Repository', 'api/fedora_item'); $dom = new DomDocument("1.0", "UTF-8"); $dom->formatOutput = true; $pid = $form_values['pid']; $rootElement = $dom->createElement("foxml:digitalObject"); $rootElement->setAttribute('VERSION', '1.1'); $rootElement->setAttribute('PID', "{$pid}"); $rootElement->setAttribute('xmlns:foxml', "info:fedora/fedora-system:def/foxml#"); $rootElement->setAttribute('xmlns:xsi', "http://www.w3.org/2001/XMLSchema-instance"); $rootElement->setAttribute('xsi:schemaLocation', "info:fedora/fedora-system:def/foxml# http://www.fedora.info/definitions/1/0/foxml1-1.xsd"); $dom->appendChild($rootElement); //create standard fedora stuff $this->createStandardFedoraStuff($form_values, $dom, $rootElement); //create relationships $this->createRelationShips($form_values, $dom, $rootElement); //create dublin core $this->createQDCStream($form_values, $dom, $rootElement); if (!empty($form_values['ingest-file-location'])) { $this->createFedoraDataStreams($form_values, $dom, $rootElement); } $collectionPid = $form_values['collection_pid']; $this->createPolicy($collectionPid, &$dom, &$rootElement); try { $object = Fedora_Item::ingest_from_FOXML($dom); if (!empty($object->pid)) { drupal_set_message("Item " . l($object->pid, 'fedora/repository/' . $object->pid) . " created successfully.", "status"); } if (!empty($_SESSION['fedora_ingest_files'])) { foreach ($_SESSION['fedora_ingest_files'] as $dsid => $createdFile) { file_delete($createdFile); } } file_delete($form_values['ingest-file-location']); } catch (exception $e) { drupal_set_message(t('Error Ingesting Object! ') . $e->getMessage(), 'error'); watchdog(t("Fedora_Repository"), t("Error Ingesting Object!") . $e->getMessage(), NULL, WATCHDOG_ERROR); return; } }
function updateTags($pid, $terms) { $object = new Fedora_Item($pid); $stream = $object->get_datastream_dissemination("TAGS"); if (strcasecmp($stream, "")) { $object->purge_datastream("TAGS"); } $toinject = "<tags>"; foreach ($terms as $term) { $toinject .= "<tag>" . $term->name . "</tag>"; } $toinject .= "</tags>"; $object->add_datastream_from_string($toinject, "TAGS", "Tag Utenti"); }