Browse Source

Merge branch '6.x' of dvr-web.mirc.sc.edu:/var/www/sites/all/modules/islandora/ into 6.x

Conflicts:
	fedora_repository.module
pull/95/head
Adam Vessey 13 years ago
parent
commit
5127f6a1a2
  1. 6
      CollectionPolicy.inc
  2. 7
      ConnectionHelper.inc
  3. 33
      ObjectHelper.inc
  4. 65
      api/fedora_item.inc
  5. 53
      fedora_repository.module
  6. 2
      fedora_repository.solutionpacks.inc
  7. 1
      formClass.inc
  8. 27
      plugins/FedoraObjectDetailedContent.inc

6
CollectionPolicy.inc

@ -44,8 +44,13 @@ class CollectionPolicy extends XMLDatastream {
if ($preFetch) {
$fedoraItem = new Fedora_Item($pid);
if (array_key_exists($dsid, $fedoraItem->get_datastreams_list_as_array())) {
$ds = $fedoraItem->get_datastream_dissemination($dsid);
}
else { //No collection policy stream (of the default name, anyway)
return FALSE;
}
}
else {
$ds = NULL;
}
@ -55,7 +60,6 @@ class CollectionPolicy extends XMLDatastream {
$ret = new CollectionPolicy($ds, $pid, $dsid);
}
} catch (SOAPException $e) {
$ret = FALSE;
}
return $ret;

7
ConnectionHelper.inc

@ -65,10 +65,11 @@ class ConnectionHelper {
//anonymous user. We will need an entry in the fedora users.xml file
//with the appropriate entry for a username of anonymous password of anonymous
try {
$client = new SoapClient($this->_fixURL($url, 'anonymous', 'anonymous'), array(
$client = new SoapClient($url, array(
'login' => 'anonymous',
'password' => 'anonymous',
'exceptions' => $exceptions,
'authentication' => SOAP_AUTHENTICATION_BASIC
));
} catch (SoapFault $e) {
drupal_set_message(t('@e', array('@e' => check_plain($e->getMessage()))));
@ -77,10 +78,12 @@ class ConnectionHelper {
}
else {
try {
$client = new SoapClient($this->_fixURL($url, $user->name, $user->pass), array(
$client = new SoapClient($url, array(
'login' => $user->name,
'password' => $user->pass,
'exceptions' => TRUE,
'authentication' => SOAP_AUTHENTICATION_BASIC,
'cache_wsdl' => WSDL_CACHE_MEMORY
));
} catch (SoapFault $e) {
drupal_set_message(t('@e', array('@e' => check_plain($e->getMessage()))));

33
ObjectHelper.inc

@ -139,7 +139,7 @@ class ObjectHelper {
curl_setopt($ch, CURLOPT_USERPWD, "$fedoraUser:$fedoraPass");
// There seems to be a bug in Fedora 3.1's REST authentication, removing this line fixes the authorization denied error.
// curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0); // return into a variable
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); // return into a variable
curl_setopt($ch, CURLOPT_URL, $url);
@ -151,7 +151,6 @@ class ObjectHelper {
fclose($fp);
}
else {
header("Content-type: $mimeType");
if ($contentSize > 0) {
header("Content-length: $contentSize");
@ -182,13 +181,39 @@ class ObjectHelper {
header('Content-Disposition: attachment; filename="' . $suggestedFileName . '"');
}
if ((isset($user) && $user->uid != 0) || $forceSoap || isset($_SERVER['HTTPS'])) {
curl_exec($ch);
curl_setopt($ch, CURLOPT_NOBODY, TRUE);
$curl_out = curl_exec($ch);
if ($curl_out !== FALSE) {
$info = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
//dd($info, 'effective URL');
if ($url !== $info) { //Handle redirect streams (the final URL is not the same as the Fedora URL)
//Add the parameters passed to Drupal, leaving out the 'q'
$query = array();
parse_str($_SERVER['QUERY_STRING'], $query);
if (isset($query['q'])) {
unset($query['q']);
}
header('HTTP/1.1 307 Moved Temporarily');
header('Location: ' . $info . '?' . http_build_query($query)); //Fedora seems to discard the query portion.
}
elseif ((isset($user) && $user->uid != 0) || $forceSoap || isset($_SERVER['HTTPS'])) { //If not anonymous, soap is force or we're using HTTPS
//Have the webserver mediate the transfer (download and restream)
curl_setopt($ch, CURLOPT_NOBODY, FALSE);
curl_setopt($ch, CURLOPT_HTTPGET, TRUE); //CURLOPT_NOBODY sets it to 'HEAD'
$toReturn = curl_exec($ch);
echo $toReturn;
}
else {
header('Location: ' . $url);
}
}
else {
//Curl error...
}
}
curl_close($ch);
}
else {

65
api/fedora_item.inc

@ -211,27 +211,39 @@ class Fedora_Item {
* @param type $namespaceURI
*/
function add_relationship($relationship, $object, $namespaceURI = RELS_EXT_URI) {
dd($this, 'The Fedora_Item');
$ds_list = $this->get_datastreams_list_as_array();
if (empty($ds_list['RELS-EXT'])) {
$this->add_datastream_from_string(' <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about="info:fedora/' . $this->pid . '">
$f_prefix = 'info:fedora/';
if (!array_key_exists('RELS-EXT', $ds_list)) {
$rdf_string = <<<RDF
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about="$f_prefix{$this->pid}">
</rdf:Description>
</rdf:RDF>', 'RELS-EXT', 'Fedora object-to-object relationship metadata', 'text/xml', 'X');
</rdf:RDF>
RDF;
dd($rdf_string, 'RELS-EXT RDF being added');
$this->add_datastream_from_string($rdf_string, 'RELS-EXT', 'Fedora object-to-object relationship metadata', 'application/rdf+xml', 'X');
dd('Added');
}
dd('Getting RELS-EXT');
$relsext = $this->get_datastream_dissemination('RELS-EXT');
dd('Got RELS-EXT');
if (substr($object, 0, 12) != 'info:fedora/') {
$object = "info:fedora/$object";
if (substr($object, 0, strlen($f_prefix)) !== $f_prefix) {
$object = $f_prefix . $object;
}
$relsextxml = new DomDocument();
$relsextxml = new DOMDocument();
$relsextxml->loadXML($relsext);
$description = $relsextxml->getElementsByTagNameNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'Description');
if ($description->length == 0) {
//XXX: This really shouldn't be done; lower case d doesn't fit the schema. Warn users to fix the data and generators, pending deprecation.
$description = $relsextxml->getElementsByTagNameNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'description');
if ($description->length > 0) {
drupal_set_message(t('RDF with lower case "d" in "description" encountered. Should be uppercase! PID: %pid', array('%pid' => $this->pid)), 'warning');
}
}
$description = $description->item(0);
@ -241,7 +253,7 @@ class Fedora_Item {
$newrel->setAttribute('rdf:resource', $object);
$description->appendChild($newrel);
$this->modify_datastream_by_value($relsextxml->saveXML(), 'RELS-EXT', "Fedora Object-to-Object Relationship Metadata", 'text/xml');
$this->modify_datastream_by_value($relsextxml->saveXML(), 'RELS-EXT', "Fedora Object-to-Object Relationship Metadata", 'application/rdf+xml');
//print ($description->dump_node());
/*
$params = array( 'pid' => $this->pid,
@ -287,7 +299,7 @@ class Fedora_Item {
break;
}
if (substr($object, 0, 12) != 'info:fedora/') {
if (!empty($object) && substr($object, 0, 12) != 'info:fedora/') {
$object = "info:fedora/$object";
}
@ -297,7 +309,7 @@ class Fedora_Item {
$rels = $relsextxml->getElementsByTagNameNS($namespaceURI, $relationship);
if (!empty($rels)) {
foreach ($rels as $rel) {
if ($rel->getAttributeNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'resource') == $object) {
if (empty($object) || $rel->getAttributeNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'resource') == $object) {
$rel->parentNode->removeChild($rel);
$modified = TRUE;
}
@ -307,7 +319,6 @@ class Fedora_Item {
$this->modify_datastream_by_value($relsextxml->saveXML(), 'RELS-EXT', "Fedora Object-to-Object Relationship Metadata", 'text/xml');
}
return $modified;
//print ($description->dump_node());
}
/**
@ -743,8 +754,9 @@ class Fedora_Item {
* @return type
*/
function url() {
global $base_url;
return $base_url . '/fedora/repository/' . $this->pid . (!empty($this->objectProfile) ? '/-/' . drupal_urlencode($this->objectProfile->objLabel) : '');
return url('fedora/repository/' . $this->pid . (!empty($this->objectProfile) ? '/-/' . drupal_urlencode($this->objectProfile->objLabel) : ''), array(
'absolute' => TRUE
));
}
/**
@ -780,9 +792,14 @@ class Fedora_Item {
* @param type $foxml
* @return Fedora_Item
*/
static function ingest_from_FOXML($foxml) {
$params = array('objectXML' => $foxml->saveXML(), 'format' => "info:fedora/fedora-system:FOXML-1.1", 'logMessage' => "Fedora Object Ingested");
static function ingest_from_FOXML(DOMDocument $foxml) {
$params = array(
'objectXML' => $foxml->saveXML(),
'format' => 'info:fedora/fedora-system:FOXML-1.1',
'logMessage' => 'Fedora Object Ingested'
);
$object = self::soap_call('ingest', $params);
dd($object, 'Soap return');
return new Fedora_Item($object->objectPID);
}
@ -982,25 +999,23 @@ class Fedora_Item {
}
}
$root_element = $foxml->createElement("foxml:digitalObject");
$root_element = $foxml->createElementNS("info:fedora/fedora-system:def/foxml#", "foxml:digitalObject");
$root_element->setAttribute("VERSION", "1.1");
$root_element->setAttribute("PID", $pid);
$root_element->setAttribute("xmlns:foxml", "info:fedora/fedora-system:def/foxml#");
$root_element->setAttribute("xmlns:xsl", "http://www.w3.org/2001/XMLSchema-instance");
$root_element->setAttribute("xsl:schemaLocation", "info:fedora/fedora-system:def/foxml# http://www.fedora.info/definitions/1/0/foxml1-1.xsd");
$root_element->setAttributeNS("http://www.w3.org/2001/XMLSchema-instance", "xsi:schemaLocation", "info:fedora/fedora-system:def/foxml# http://www.fedora.info/definitions/1/0/foxml1-1.xsd");
$foxml->appendChild($root_element);
// FOXML object properties section
$object_properties = $foxml->createElement("foxml:objectProperties");
$state_property = $foxml->createElement("foxml:property");
$object_properties = $foxml->createElementNS("info:fedora/fedora-system:def/foxml#", "foxml:objectProperties");
$state_property = $foxml->createElementNS("info:fedora/fedora-system:def/foxml#", "foxml:property");
$state_property->setAttribute("NAME", "info:fedora/fedora-system:def/model#state");
$state_property->setAttribute("VALUE", $state);
$label_property = $foxml->createElement("foxml:property");
$label_property = $foxml->createElementNS("info:fedora/fedora-system:def/foxml#", "foxml:property");
$label_property->setAttribute("NAME", "info:fedora/fedora-system:def/model#label");
$label_property->setAttribute("VALUE", $label);
$owner_property = $foxml->createElement("foxml:property");
$owner_property = $foxml->createElementNS("info:fedora/fedora-system:def/foxml#", "foxml:property");
$owner_property->setAttribute("NAME", "info:fedora/fedora-system:def/model#ownerId");
$owner_property->setAttribute("VALUE", $owner);
@ -1009,7 +1024,7 @@ class Fedora_Item {
$object_properties->appendChild($owner_property);
$root_element->appendChild($object_properties);
$foxml->appendChild($root_element);
//dd($foxml->saveXML(), 'XML to ingest'); Worked on 2012/01/16
return $foxml;
}

53
fedora_repository.module

@ -146,13 +146,13 @@ function fedora_repository_ingest_form_submit(array $form, array &$form_state) {
$form_state['submitted'] = FALSE;
return;
}
if ($form_state['storage']['xml']) {
if (module_exists('islandora_content_model_forms')) {
//ddebug_backtrace();
if ($form_state['storage']['xml'] && module_exists('islandora_content_model_forms')) {
module_load_include('inc', 'islandora_content_model_forms', 'IngestObjectMetadataForm');
IngestObjectMetadataForm::submit($form, $form_state);
}
$xml_form = new IngestObjectMetadataForm();
$xml_form->submit($form, $form_state);
}
elseif ($form_state['clicked_button']['#id'] == 'edit-submit') {
elseif (strpos($form_state['clicked_button']['#id'], 'edit-submit') === 0) {
global $base_url;
module_load_include('inc', 'fedora_repository', 'CollectionClass');
module_load_include('inc', 'fedora_repository', 'CollectionPolicy');
@ -187,7 +187,7 @@ function fedora_repository_ingest_form_submit(array $form, array &$form_state) {
}
if ($redirect) {
$form_state['redirect'] = ($err) ? ' ' : $base_url . "/fedora/repository/{$form_state['values']['collection_pid']}";
$form_state['redirect'] = ($err) ? ' ' : url("fedora/repository/{$form_state['values']['collection_pid']}");
}
}
}
@ -204,7 +204,7 @@ function fedora_repository_ingest_form_validate($form, &$form_state) {
$form_state['submitted'] = FALSE;
return;
}
if ($form_state['clicked_button']['#id'] == 'edit-submit' && $form_state['ahah_submission'] != 1) {
if (strpos($form_state['clicked_button']['#id'], 'edit-submit') === 0 && $form_state['ahah_submission'] != 1) {
switch ($form_state['storage']['step']) {
case 1:
$form_state['storage']['step']++;
@ -285,7 +285,8 @@ function fedora_repository_ingest_form(&$form_state, $collection_pid, $collectio
$ingestForm = new formClass();
$form_state['storage']['content_model'] = $content_model;
$form_state['storage']['collection_pid'] = $collection_pid;
return $ingestForm->createIngestForm($collection_pid, $collection_label, $form_state);
$form = $ingestForm->createIngestForm($collection_pid, $collection_label, $form_state);
return $form;
}
/**
@ -1704,22 +1705,22 @@ function fedora_repository_required_fedora_objects() {
'pid' => 'islandora:collectionCModel',
'label' => 'Islandora Collection Content Model',
'dsid' => 'ISLANDORACM',
'datastream_file' => "$module_path/content_models/COLLECTIONCM.xml",
'datastream_file' => "./$module_path/content_models/COLLECTIONCM.xml",
'dsversion' => 2,
'cmodel' => 'fedora-system:ContentModel-3.0',
'cmodel' => 'info:fedora/fedora-system:ContentModel-3.0',
),
array(
'pid' => 'islandora:root',
'label' => 'Islandora Top-level Collection',
'cmodel' => 'islandora:collectionCModel',
'cmodel' => 'info:fedora/islandora:collectionCModel',
'datastreams' => array(
array(
'dsid' => 'COLLECTION_POLICY',
'datastream_file' => "$module_path/collection_policies/COLLECTION-COLLECTION POLICY.xml",
'datastream_file' => "./$module_path/collection_policies/COLLECTION-COLLECTION POLICY.xml",
),
array(
'dsid' => 'TN',
'datastream_file' => "$module_path/images/Gnome-emblem-photos.png",
'datastream_file' => "./$module_path/images/Gnome-emblem-photos.png",
'mimetype' => 'image/png',
),
),
@ -2150,23 +2151,30 @@ function fedora_repository_display_schema($file) {
function fedora_repository_batch_reingest_object($object, &$context) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
module_load_include('inc', 'fedora_repository', 'api/fedora_utils');
dd($object, 'Object array');
if (!empty($object) && is_array($object)) {
$pid = $object['pid'];
if (!valid_pid($pid)) {
return NULL;
}
// Does the object exist? If so, purge it.
dd("About to test existence of PID: $pid");
$item = new Fedora_Item($pid);
if ($item->exists()) {
dd(' Found');
$item->purge(t('Remove during re-install batch job'));
dd(' Purged');
}
$new_item = NULL; //Need to have this a couple places... (After trying from FOXML and later for individual DSs)
$datastreams = array(); //Seems like this might be getting messed up due to scope?
// Ingest the object from the source file.
if (!empty($object['foxml_file'])) {
$foxml_file = $object['foxml_file'];
$new_item = Fedora_Item::ingest_from_FOXML_file($foxml_file);
if ($new_item->exists()) {
// Batch operation was successful.
// Batch operation was successful; can still add additional DSs, though
$context['message'][] = "$new_item->pid installed.";
}
}
@ -2182,18 +2190,29 @@ function fedora_repository_batch_reingest_object($object, &$context) {
$datastreams = $object['datastreams'];
}
if (!empty($datastreams) && is_array($datastreams)) {
$label = !empty($object['label']) ? $object['label'] : '';
if (empty($object['foxml_file']) && !isset($new_item)) {
$new_item = Fedora_Item::ingest_new_item($object['pid'], 'A', $label);
if (!isset($new_item)) {
dd(' Not found, creating');
$new_item = Fedora_Item::ingest_new_item($pid, 'A', $label);
dd(' Created');
}
elseif (!empty($label)) {
$new_item->modify_object($label);
}
if (isset($new_item)) {
if (!empty($object['cmodel'])) {
dd(' relating to cmodel');
$new_item->add_relationship('hasModel', $object['cmodel'], FEDORA_MODEL_URI);
dd(' related to cmodel');
}
if (!empty($object['parent'])) {
dd(' adding parent');
$new_item->add_relationship('isMemberOfCollection', $object['parent']);
dd(' parent added');
}
foreach ($datastreams as $ds) {
dd("trying to add ds: {$ds['dsid']}");
if ($ds['dsid'] == 'DC') {
$new_item->modify_datastream_by_value(file_get_contents($ds['datastream_file']), $ds['dsid'], $ds['label'], 'text/xml');
}

2
fedora_repository.solutionpacks.inc

@ -109,7 +109,7 @@ function fedora_repository_solution_pack_form(&$form_state, $solution_pack_modul
$object_status = 'Missing datastream';
break;
}
if (isset($ds['dsversion'])) {
elseif (isset($ds['dsversion'])) {
// Check if the datastream is versioned and needs updating.
$installed_version = fedora_repository_get_islandora_datastream_version($item, $ds['dsid']);
$available_version = fedora_repository_get_islandora_datastream_version(NULL, NULL, $ds['datastream_file']);

1
formClass.inc

@ -602,6 +602,7 @@ class formClass {
$form = new IngestObjectMetadataForm();
return $form->create($collection_pid, $collection_label, $form_state);
} catch (Exception $e) {
dd('An error occured; reverting to QDC form...');
$form_state['storage']['xml'] = FALSE; // An error occured revert back to the QDC Form.
}
}

27
plugins/FedoraObjectDetailedContent.inc

@ -43,6 +43,7 @@ class FedoraObjectDetailedContent {
'#type' => 'tabpage',
'#title' => t('Object Details'),
'#selected' => $details_selected,
'#weight' => 100, //XXX: Make the weight configurable?
);
$tabset['fedora_object_details']['tabset'] = array(
'#type' => 'tabset',
@ -51,12 +52,28 @@ class FedoraObjectDetailedContent {
$ds_list = $objectHelper->get_formatted_datastream_list($this->pid, NULL, $this->item);
$i = 0;
if (fedora_repository_access(OBJECTHELPER :: $VIEW_DETAILED_CONTENT_LIST, $this->pid, $user)) {
$tabset['fedora_object_details']['tabset']['view'] = array(
'#type' => 'tabpage',
'#title' => t('View'),
'#content' => $dc_html . $ds_list . $purge_form,
'dc' => array(
'#type' => 'markup',
'#value' => $dc_html, //XXX: This could easily be done in Drupal, instead of using an XSL
'#weight' => $i++
),
'list' => array(
'#type' => 'markup',
'#value' => $ds_list, //XXX: The function called here could be cleaned up a fair bit as well...
'#weight' => $i++
),
'purge' => array(
'#type' => 'markup',
'#value' => $purge_form,
'#weight' => $i++
)
);
}
if (fedora_repository_access(OBJECTHELPER :: $EDIT_FEDORA_METADATA, $this->pid, $user)) {
$editform = drupal_get_form('fedora_repository_edit_qdc_form', $this->pid, 'DC');
@ -68,7 +85,13 @@ class FedoraObjectDetailedContent {
);
}
$ts = $tabset['fedora_object_details']['tabset'];
if (array_key_exists('view', $ts) || array_key_exists('edit', $ts)) {
return $tabset;
}
else {
return array();
}
}
}

Loading…
Cancel
Save