Jonathan Green
12 years ago
27 changed files with 2115 additions and 1413 deletions
@ -1,9 +1,59 @@ |
|||||||
|
CONTENTS OF THIS FILE |
||||||
|
--------------------- |
||||||
|
|
||||||
|
* summary |
||||||
|
* requirements |
||||||
|
* installation |
||||||
|
* configuration |
||||||
|
* customization |
||||||
|
* troubleshooting |
||||||
|
* faq |
||||||
|
* contact |
||||||
|
* sponsors |
||||||
|
|
||||||
|
|
||||||
|
SUMMARY |
||||||
|
------- |
||||||
|
|
||||||
Islandora Fedora Repository Module |
Islandora Fedora Repository Module |
||||||
|
|
||||||
For installation and customization instructions please see the documentation and the DuraSpace Wiki: |
For installation and customization instructions please see the documentation |
||||||
|
and the DuraSpace Wiki: |
||||||
|
|
||||||
https://wiki.duraspace.org/display/ISLANDORA/Islandora |
https://wiki.duraspace.org/display/ISLANDORA/Islandora |
||||||
|
|
||||||
All bugs, feature requests and improvement suggestions are tracked at the DuraSpace JIRA: |
All bugs, feature requests and improvement suggestions are tracked at the |
||||||
|
DuraSpace JIRA: |
||||||
|
|
||||||
https://jira.duraspace.org/browse/ISLANDORA |
https://jira.duraspace.org/browse/ISLANDORA |
||||||
|
|
||||||
|
REQUIREMENTS |
||||||
|
------------ |
||||||
|
|
||||||
|
|
||||||
|
INSTALLATION |
||||||
|
------------ |
||||||
|
|
||||||
|
|
||||||
|
CONFIGURATION |
||||||
|
------------- |
||||||
|
|
||||||
|
|
||||||
|
CUSTOMIZATION |
||||||
|
------------- |
||||||
|
|
||||||
|
|
||||||
|
TROUBLESHOOTING |
||||||
|
--------------- |
||||||
|
|
||||||
|
|
||||||
|
F.A.Q. |
||||||
|
------ |
||||||
|
|
||||||
|
|
||||||
|
CONTACT |
||||||
|
------- |
||||||
|
|
||||||
|
|
||||||
|
SPONSORS |
||||||
|
-------- |
@ -0,0 +1,55 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
/** |
||||||
|
* @file |
||||||
|
* |
||||||
|
* Wrapper around the tuque library, allows for autoloading of Islandora Tuque |
||||||
|
* Objects. |
||||||
|
* |
||||||
|
* @todo Overload functions and apply pre/post hooks. |
||||||
|
*/ |
||||||
|
|
||||||
|
class IslandoraFedoraRepository extends FedoraRepository { |
||||||
|
protected $queryClass = 'IslandoraRepositoryQuery'; |
||||||
|
protected $newObjectClass = 'IslandoraNewFedoraObject'; |
||||||
|
protected $objectClass = 'IslandoraFedoraObject'; |
||||||
|
} |
||||||
|
|
||||||
|
class IslandoraRepositoryQuery extends RepositoryQuery {} |
||||||
|
|
||||||
|
class IslandoraNewFedoraObject extends NewFedoraObject { |
||||||
|
protected $newFedoraDatastreamClass = 'IslandoraNewFedoraDatastream'; |
||||||
|
protected $fedoraDatastreamClass = 'IslandoraFedoraDatastream'; |
||||||
|
protected $fedoraRelsExtClass = 'IslandoraFedoraRelsExt'; |
||||||
|
} |
||||||
|
|
||||||
|
class IslandoraFedoraObject extends FedoraObject { |
||||||
|
protected $newFedoraDatastreamClass = 'IslandoraNewFedoraDatastream'; |
||||||
|
protected $fedoraDatastreamClass = 'IslandoraFedoraDatastream'; |
||||||
|
protected $fedoraRelsExtClass = 'IslandoraFedoraRelsExt'; |
||||||
|
} |
||||||
|
|
||||||
|
class IslandoraRepositoryConnection extends RepositoryConnection {} |
||||||
|
|
||||||
|
class IslandoraFedoraApi extends FedoraApi {} |
||||||
|
|
||||||
|
class IslandoraSimpleCache extends SimpleCache {} |
||||||
|
|
||||||
|
class IslandoraNewFedoraDatastream extends NewFedoraDatastream { |
||||||
|
protected $fedoraRelsIntClass = 'IslandoraFedoraRelsInt'; |
||||||
|
protected $fedoraDatastreamVersionClass = 'IslandoraFedoraDatastreamVersion'; |
||||||
|
} |
||||||
|
|
||||||
|
class IslandoraFedoraDatastream extends FedoraDatastream { |
||||||
|
protected $fedoraRelsIntClass = 'IslandoraFedoraRelsInt'; |
||||||
|
protected $fedoraDatastreamVersionClass = 'IslandoraFedoraDatastreamVersion'; |
||||||
|
} |
||||||
|
|
||||||
|
class IslandoraFedoraDatastreamVersion extends FedoraDatastreamVersion { |
||||||
|
protected $fedoraRelsIntClass = 'IslandoraFedoraRelsInt'; |
||||||
|
protected $fedoraDatastreamVersionClass = 'IslandoraFedoraDatastreamVersion'; |
||||||
|
} |
||||||
|
|
||||||
|
class IslandoraFedoraRelsExt extends FedoraRelsExt {} |
||||||
|
|
||||||
|
class IslandoraFedoraRelsInt extends FedoraRelsInt {} |
@ -0,0 +1,231 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
/** |
||||||
|
* @file |
||||||
|
* |
||||||
|
* Functions for generating/validating/submitting the add datastream form. |
||||||
|
*/ |
||||||
|
|
||||||
|
/** |
||||||
|
* The admin add datastream form. |
||||||
|
* |
||||||
|
* @param array $form |
||||||
|
* The Drupal form. |
||||||
|
* @param array $form_state |
||||||
|
* The Drupal form state. |
||||||
|
* @param FedoraObject $object |
||||||
|
* The object to be deleted. |
||||||
|
* |
||||||
|
* @return array |
||||||
|
* The drupal form definition. |
||||||
|
*/ |
||||||
|
function islandora_add_datastream_form(array $form, array &$form_state, FedoraObject $object) { |
||||||
|
module_load_include('inc', 'islandora', 'includes/content_model'); |
||||||
|
module_load_include('inc', 'islandora', 'includes/utilities'); |
||||||
|
form_load_include($form_state, 'inc', 'islandora', 'includes/add_datastream.form'); |
||||||
|
$form_state['object'] = $object; |
||||||
|
$form_state['datastream_requirements'] = islandora_get_missing_datastreams_requirements($object); |
||||||
|
$unused_datastreams = array_keys($form_state['datastream_requirements']); |
||||||
|
$unused_datastreams = array_map(function($o) { return "'$o'"; }, $unused_datastreams); |
||||||
|
$unused_datastreams = implode(', ', $unused_datastreams); |
||||||
|
$upload_size = min((int)ini_get('post_max_size'), (int)ini_get('upload_max_filesize')); |
||||||
|
return array( |
||||||
|
'#redirect' => "islandora/object/{$object->id}", |
||||||
|
'#attributes' => array( |
||||||
|
'enctype' => 'multipart/form-data' |
||||||
|
), |
||||||
|
'fieldset' => array( |
||||||
|
'#type' => 'fieldset', |
||||||
|
'#title' => 'Add a datastream', |
||||||
|
'#collapsible' => FALSE, |
||||||
|
'#collapsed' => FALSE, |
||||||
|
'dsid' => array( |
||||||
|
'#title' => 'Datastream ID', |
||||||
|
'#description' => t('An ID for this stream that is unique to this object.' . |
||||||
|
'Must start with a letter and contain only alphanumeric ' . |
||||||
|
'characters and dashes and underscores. Datastreams that ' . |
||||||
|
'are defined by the content model don\'t currently exist: ' . |
||||||
|
'<b>@unused_dsids</b>.', |
||||||
|
array('@unused_dsids' => $unused_datastreams) |
||||||
|
), |
||||||
|
'#type' => 'textfield', |
||||||
|
'#size' => 64, |
||||||
|
'#maxlength' => 64, |
||||||
|
'#required' => TRUE, |
||||||
|
'#element_validate' => array( |
||||||
|
'islandora_add_datastream_form_field_is_not_an_existing_datastream_id', |
||||||
|
'islandora_add_datastream_form_field_starts_with_a_letter', |
||||||
|
'islandora_add_datastream_form_field_is_valid_dsid', |
||||||
|
), |
||||||
|
'#autocomplete_path' => "islandora/object/{$object->id}/manage/datastreams/add/autocomplete" |
||||||
|
), |
||||||
|
'label' => array( |
||||||
|
'#title' => 'Datastream Label', |
||||||
|
'#required' => TRUE, |
||||||
|
'#size' => 64, |
||||||
|
'#maxlength' => 64, |
||||||
|
'#description' => t('A Human readable label'), |
||||||
|
'#type' => 'textfield', |
||||||
|
'#element_validate' => array('islandora_add_datastream_form_field_does_not_contain_a_forward_slash') |
||||||
|
), |
||||||
|
'file' => array( |
||||||
|
'#type' => 'managed_file', |
||||||
|
'#required' => TRUE, |
||||||
|
'#title' => t('Upload Document'), |
||||||
|
'#size' => 48, |
||||||
|
'#description' => t('Select a file to upload.<br/>Files must be less than <b>@size MB.</b>', array('@size' => $upload_size)), |
||||||
|
'#default_value' => isset($form_state['values']['files']) ? $form_state['values']['files'] : NULL, |
||||||
|
'#upload_location' => 'temporary://', |
||||||
|
'#upload_validators' => array( |
||||||
|
'file_validate_extensions' => array(NULL), |
||||||
|
// Assume its specified in MB |
||||||
|
'file_validate_size' => array($upload_size * 1024 * 1024), |
||||||
|
), |
||||||
|
), |
||||||
|
'submit' => array( |
||||||
|
'#type' => 'submit', |
||||||
|
'#value' => t('Add Datastream') |
||||||
|
), |
||||||
|
) |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Checks if the given form field doesn't already repersent a Datastream ID. |
||||||
|
* |
||||||
|
* @param array $element |
||||||
|
* The form field to check. |
||||||
|
* @param array $form_state |
||||||
|
* The Drupal form state. |
||||||
|
* @param array $form |
||||||
|
* The Drupal form. |
||||||
|
*/ |
||||||
|
function islandora_add_datastream_form_field_is_not_an_existing_datastream_id(array $element, array &$form_state, array $form) { |
||||||
|
if (isset($form_state['object'][$element['#value']])) { |
||||||
|
form_error($element, t("@title already exists in the object.", array('@title' => $element['#title']))); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Checks if the given form field starts with a letter. |
||||||
|
* |
||||||
|
* @param array $element |
||||||
|
* The form field to check. |
||||||
|
* @param array $form_state |
||||||
|
* The Drupal form state. |
||||||
|
* @param array $form |
||||||
|
* The Drupal form. |
||||||
|
*/ |
||||||
|
function islandora_add_datastream_form_field_starts_with_a_letter(array $element, array &$form_state, array $form) { |
||||||
|
if (!(preg_match("/^[a-zA-Z]/", $element['#value']))) { |
||||||
|
form_error($element, t("@title has to start with a letter.", array('@title' => $element['#title']))); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Checks if the given form field contains only valid characters for a |
||||||
|
* datastream id. |
||||||
|
* |
||||||
|
* @param array $element |
||||||
|
* The form field to check. |
||||||
|
* @param array $form_state |
||||||
|
* The Drupal form state. |
||||||
|
* @param array $form |
||||||
|
* The Drupal form. |
||||||
|
*/ |
||||||
|
function islandora_add_datastream_form_field_is_valid_dsid(array $element, array &$form_state, array $form) { |
||||||
|
module_load_include('inc', 'islandora', 'includes/utilities'); |
||||||
|
if (!islandora_is_valid_dsid($element['#value'])) { |
||||||
|
form_error($element, t("@title contains invalid characters.", array('@title' => $element['#title']))); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Checks if the given form field contains a "/" character. |
||||||
|
* |
||||||
|
* @param array $element |
||||||
|
* The form field to check. |
||||||
|
* @param array $form_state |
||||||
|
* The Drupal form state. |
||||||
|
* @param array $form |
||||||
|
* The Drupal form. |
||||||
|
*/ |
||||||
|
function islandora_add_datastream_form_field_does_not_contain_a_forward_slash(array $element, array &$form_state, array $form) { |
||||||
|
if (strpos($element['#value'], '/') !== FALSE) { |
||||||
|
form_error($element, t('@title cannot contain a "/" character.', array('@title' => $element['#title']))); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Checks if the given datastream id requires that the upload file be of a |
||||||
|
* certian MIME type. |
||||||
|
* |
||||||
|
* @param array $form |
||||||
|
* The Drupal form. |
||||||
|
* @param array $form_state |
||||||
|
* The Drupal form state. |
||||||
|
*/ |
||||||
|
function islandora_add_datastream_form_validate(array $form, array &$form_state) { |
||||||
|
$file = file_load($form_state['values']['file']); |
||||||
|
$dsid = $form_state['values']['dsid']; |
||||||
|
if (isset($form_state['datastream_requirements'][$dsid]) && $file) { |
||||||
|
$allowed_types = $form_state['datastream_requirements'][$dsid]['mime']; |
||||||
|
$mime_detect = new MimeDetect(); |
||||||
|
$allowed_extensions = array_map(array($mime_detect, 'getExtension'), $allowed_types); |
||||||
|
$errors = file_validate_extensions($file, implode(' ', $allowed_extensions)); |
||||||
|
if (count($errors) > 0) { |
||||||
|
form_set_error('file', $errors[0]); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Adds the new datastream based on the submitted values, only creates managed |
||||||
|
* datastreams at the moment. |
||||||
|
* |
||||||
|
* @param array $form |
||||||
|
* The Drupal form. |
||||||
|
* @param array $form_state |
||||||
|
* The Drupal form state. |
||||||
|
*/ |
||||||
|
function islandora_add_datastream_form_submit(array $form, array &$form_state) { |
||||||
|
$object = $form_state['object']; |
||||||
|
$form_state['redirect'] = "islandora/object/{$object->id}"; |
||||||
|
$file = file_load($form_state['values']['file']); |
||||||
|
try { |
||||||
|
$ds = $object->constructDatastream($form_state['values']['dsid'], 'M'); |
||||||
|
$ds->label = $form_state['values']['label']; |
||||||
|
$ds->mimetype = $file->filemime; |
||||||
|
$path = drupal_realpath($file->uri); |
||||||
|
$ds->setContentFromFile($path); |
||||||
|
$object->ingestDatastream($ds); |
||||||
|
file_delete($file); |
||||||
|
} catch (exception $e) { |
||||||
|
drupal_set_message(t('@message', array('@message' => check_plain($e->getMessage()))), 'error'); |
||||||
|
file_delete($file); // Make sure to delete anyways. |
||||||
|
return; |
||||||
|
} |
||||||
|
drupal_set_message(t("Successfully Added Datastream!")); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Callback for an autocomplete field in the admin add datastream form. |
||||||
|
* It lists the missing required (may be optional) datastreams. |
||||||
|
* |
||||||
|
* @param FedoraObject $object |
||||||
|
* The object used to check for missing required datastreams used to populate |
||||||
|
* the options in this callback. |
||||||
|
* @param string $query |
||||||
|
* vThe user query to match against the missing required datastreams. |
||||||
|
*/ |
||||||
|
function islandora_add_datastream_form_autocomplete_callback(FedoraObject $object, $query = '') { |
||||||
|
module_load_include('inc', 'islandora', 'includes/content_model'); |
||||||
|
module_load_include('inc', 'islandora', 'includes/utilities'); |
||||||
|
$dsids = array_keys(islandora_get_missing_datastreams_requirements($object)); |
||||||
|
$dsids = array_combine($dsids, $dsids); |
||||||
|
$query = trim($query); |
||||||
|
if (!empty($query)) { |
||||||
|
$dsids = array_filter($dsids, function($id) use($query) { return stripos($id, $query) !== FALSE; }); |
||||||
|
} |
||||||
|
drupal_json_output($dsids); |
||||||
|
} |
@ -0,0 +1,66 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
/** |
||||||
|
* @file |
||||||
|
* |
||||||
|
* This file contains the admin (confirmation) form and callback functions to |
||||||
|
* delete/purge a datastream. |
||||||
|
*/ |
||||||
|
|
||||||
|
/** |
||||||
|
* The admin delete datastream form. |
||||||
|
* |
||||||
|
* @param array $form |
||||||
|
* The Drupal form. |
||||||
|
* @param array $form_state |
||||||
|
* The Drupal form state. |
||||||
|
* @param FedoraDatastream $datastream |
||||||
|
* The datastream to be deleted. |
||||||
|
* |
||||||
|
* @return array |
||||||
|
* The drupal form definition. |
||||||
|
*/ |
||||||
|
function islandora_delete_datastream_form(array $form, array &$form_state, FedoraDatastream $datastream) { |
||||||
|
$form_state['datastream'] = $datastream; |
||||||
|
return confirm_form($form, |
||||||
|
t('Are you sure you want to delete the %dsid datastream?', array('%dsid' => $datastream->id)), |
||||||
|
"islandora/object/{$datastream->parent->id}", |
||||||
|
t('This action cannot be undone.'), |
||||||
|
t('Delete'), |
||||||
|
t('Cancel') |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Submit handler for the delete datastream form. Purges/Delete's the given |
||||||
|
* FedoraDatastream if possible. |
||||||
|
* |
||||||
|
* The ISLANDORA_PRE_PURGE_DATASTREAM_HOOK will query other modules as to |
||||||
|
* whether the given FedoraDatastream |
||||||
|
* should be: blocked from purging; state set to 'Deleted'; or purged. |
||||||
|
* |
||||||
|
* @see islandora_delete_datastream(). |
||||||
|
* |
||||||
|
* @param string $object_id |
||||||
|
* ID of the object |
||||||
|
* @param string $datastream_id |
||||||
|
* ID of the datastream |
||||||
|
*/ |
||||||
|
function islandora_delete_datastream_form_submit(array $form, array &$form_state) { |
||||||
|
$datastream = $form_state['datastream']; |
||||||
|
$datastream_id = $datastream->id; |
||||||
|
$object = $datastream->parent; |
||||||
|
$deleted = FALSE; |
||||||
|
try { |
||||||
|
$deleted = islandora_delete_datastream($datastream); |
||||||
|
} catch (Exception $e) { |
||||||
|
drupal_set_message(t('Error deleting %s datastream from object %o %e', array('%s' => $datastream_id, '%o' => $object->label, '%e' => $e->getMessage())), 'error'); |
||||||
|
} |
||||||
|
if ($deleted) { |
||||||
|
drupal_set_message(t('%d datastream sucessfully deleted from Islandora object %o', array('%d' => $datastream_id, '%o' => $object->label))); |
||||||
|
} |
||||||
|
else { |
||||||
|
drupal_set_message(t('Error deleting %s datastream from object %o', array('%s' => $datastream_id, '%o' => $object->label)), 'error'); |
||||||
|
} |
||||||
|
$form_state['redirect'] = "islandora/object/{$object->id}"; |
||||||
|
} |
@ -0,0 +1,50 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
/** |
||||||
|
* @file |
||||||
|
* |
||||||
|
* This file contains the admin (confirmation) form and callback functions to |
||||||
|
* purge an object. |
||||||
|
*/ |
||||||
|
|
||||||
|
/** |
||||||
|
* The admin delete object form. |
||||||
|
* |
||||||
|
* @param array $form |
||||||
|
* The Drupal form. |
||||||
|
* @param array $form_state |
||||||
|
* The Drupal form state. |
||||||
|
* @param FedoraObject $object |
||||||
|
* The object to be deleted. |
||||||
|
* |
||||||
|
* @return array |
||||||
|
* The drupal form definition. |
||||||
|
*/ |
||||||
|
function islandora_delete_object_form(array $form, array &$form_state, FedoraObject $object) { |
||||||
|
$form_state['object'] = $object; |
||||||
|
return confirm_form($form, |
||||||
|
t('Are you sure you want to delete %title?', array('%title' => $object->label)), |
||||||
|
"islandora/object/$object->id", |
||||||
|
t('This action cannot be undone.'), |
||||||
|
t('Delete'), |
||||||
|
t('Cancel') |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Delete's the object in questionGives deloption of deleting or purging and object. |
||||||
|
* |
||||||
|
* @param array $form |
||||||
|
* The Drupal form. |
||||||
|
* @param array $form_state |
||||||
|
* The Drupal form state. |
||||||
|
*/ |
||||||
|
function islandora_delete_object_form_submit(array $form, array &$form_state) { |
||||||
|
module_load_include('inc', 'islandora', 'includes/datastream'); |
||||||
|
module_load_include('inc', 'islandora', 'includes/utilities'); |
||||||
|
$object = $form_state['object']; |
||||||
|
$parents = islandora_get_parents_from_rels_ext($object); |
||||||
|
$parent = array_pop($parents); |
||||||
|
$form_state['redirect'] = isset($parent) ? "islandora/object/{$parent->id}" : 'islandora'; |
||||||
|
islandora_delete_object($object); |
||||||
|
} |
@ -1,47 +0,0 @@ |
|||||||
<?php |
|
||||||
|
|
||||||
/** |
|
||||||
* @file |
|
||||||
* Menu callback functionality for islandora/ingest |
|
||||||
*/ |
|
||||||
|
|
||||||
/** |
|
||||||
* Callback function for islandora/ingest/%collection_pid |
|
||||||
* |
|
||||||
* @TODO: validate?: pid, registry return |
|
||||||
* @param string $pid |
|
||||||
*/ |
|
||||||
function islandora_ingest_callback($collection_object) { |
|
||||||
if (!$collection_object) { |
|
||||||
return drupal_not_found(); |
|
||||||
} |
|
||||||
|
|
||||||
$ingest_registry = module_invoke_all('islandora_ingest_registry', $collection_object); |
|
||||||
$registry_count = count($ingest_registry); |
|
||||||
|
|
||||||
if ($registry_count == 0) { |
|
||||||
// No ingest implementations. |
|
||||||
drupal_set_message(t('There are no ingest methods specified for @name.', array('@name', $collection_object->label))); |
|
||||||
drupal_goto('islandora/object/' . $collection_object->id); |
|
||||||
} |
|
||||||
elseif ($registry_count == 1) { |
|
||||||
// One registry implementation, go there |
|
||||||
drupal_goto($ingest_registry[0]['url']); |
|
||||||
} |
|
||||||
else { |
|
||||||
// Multiple ingest routes registered |
|
||||||
return islandora_ingest_registry_render($ingest_registry); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
// @TODO: theme |
|
||||||
function islandora_ingest_registry_render($ingest_registry) { |
|
||||||
$output = array( |
|
||||||
'#type' => 'markup', |
|
||||||
'#markup' => '', |
|
||||||
); |
|
||||||
foreach ($ingest_registry AS $ingest_route) { |
|
||||||
$output['#markup'] .= l($ingest_route['name'], $ingest_route['url']) . '<br/>'; |
|
||||||
} |
|
||||||
return $output; |
|
||||||
} |
|
@ -0,0 +1,428 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
/** |
||||||
|
* @file |
||||||
|
* |
||||||
|
* Defines the multi-page ingest form and any relevant hooks and functions for |
||||||
|
* defining the multi-page ingest forms. |
||||||
|
*/ |
||||||
|
|
||||||
|
/** |
||||||
|
* Ingest form build function. Initializes the form state, and builds the |
||||||
|
* initial list of steps, excutes the current step. |
||||||
|
* |
||||||
|
* @param array $form |
||||||
|
* The drupal form. |
||||||
|
* @param array $form_state |
||||||
|
* The drupal form state. |
||||||
|
* @param array $configuration |
||||||
|
* An associative array of configuration values that are used to build the |
||||||
|
* list of steps to be executed, including: |
||||||
|
* - id: The PID with which the object should be created. |
||||||
|
* - namespace: The PID namespace in which the object should be created. |
||||||
|
* (id is used first, if it is given). |
||||||
|
* - label: The initial label for the object. Defaults to "New Object". |
||||||
|
* - collections: An array of collection PIDs, to which the new object should |
||||||
|
* be related. |
||||||
|
* - models: An array of content model PIDs, to which the new object should |
||||||
|
* subscribe |
||||||
|
* |
||||||
|
* @return array |
||||||
|
* The form definition of the current step. |
||||||
|
*/ |
||||||
|
function islandora_ingest_form(array $form, array &$form_state, array $configuration) { |
||||||
|
islandora_ingest_form_init_form_state($form_state, $configuration); |
||||||
|
return islandora_ingest_form_execute_step($form, $form_state); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Prepares/Initializes the form state for use. |
||||||
|
* |
||||||
|
* Also cleans up or loads any data required. |
||||||
|
* |
||||||
|
* @param array $form_state |
||||||
|
* The drupal form state. |
||||||
|
* @param array $configuration |
||||||
|
* A list of key value pairs that are used to build the list of steps to be |
||||||
|
* executed. |
||||||
|
*/ |
||||||
|
function islandora_ingest_form_init_form_state(array &$form_state, array $configuration) { |
||||||
|
// First time initialization of storage. |
||||||
|
islandora_ingest_form_init_form_state_storage($form_state, $configuration); |
||||||
|
$steps = &islandora_ingest_form_get_steps($form_state); |
||||||
|
// Always re-sort the steps just incase any build/submit handlers have |
||||||
|
// appended new steps. |
||||||
|
usort($steps, 'drupal_sort_weight'); |
||||||
|
// Load any required files for the current step. |
||||||
|
islandora_ingest_form_step_form_load_include($form_state); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Initializes the form_state storage for use in the ingest multi-page forms. |
||||||
|
* |
||||||
|
* @param array $form_state |
||||||
|
* The drupal form state. |
||||||
|
* @param array $configuration |
||||||
|
* A list of key value pairs that are used to build the list of steps to be |
||||||
|
* executed. |
||||||
|
*/ |
||||||
|
function islandora_ingest_form_init_form_state_storage(array &$form_state, array $configuration) { |
||||||
|
module_load_include('inc', 'islandora', 'includes/utilities'); |
||||||
|
if (empty($form_state['islandora'])) { |
||||||
|
// Use ID if given. |
||||||
|
$id = isset($configuration['id']) ? $configuration['id'] : NULL; |
||||||
|
// Use namespace if ID not given. |
||||||
|
$namespace = isset($configuration['namespace']) && !isset($id) ? $configuration['namespace'] : $id; |
||||||
|
$label = isset($configuration['label']) ? $configuration['label'] : 'New Object'; |
||||||
|
$relationship_map = function($o) { return array('relationship' => 'isMemberOfCollection', 'pid' => $o); }; |
||||||
|
$relationships = empty($configuration['collections']) ? array() : array_map($relationship_map, $configuration['collections']); |
||||||
|
$object = islandora_prepare_new_object($namespace, $label, array(), array(), $relationships); |
||||||
|
$form_state['islandora'] = array( |
||||||
|
'step' => 0, |
||||||
|
'steps' => islandora_ingest_get_steps($configuration), |
||||||
|
'objects' => array($object), |
||||||
|
'configuration' => $configuration |
||||||
|
); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Executes the current step, building the form definition and appending on any |
||||||
|
* additonal elements required for the step to function. |
||||||
|
* |
||||||
|
* @param array $form |
||||||
|
* The drupal form. |
||||||
|
* @param array $form_state |
||||||
|
* The drupal form state. |
||||||
|
* |
||||||
|
* @return array |
||||||
|
* The form definition of the current step. |
||||||
|
*/ |
||||||
|
function islandora_ingest_form_execute_step(array $form, array &$form_state) { |
||||||
|
$step_info = islandora_ingest_form_get_step_info($form_state); |
||||||
|
switch ($step_info['type']) { |
||||||
|
case 'form': |
||||||
|
$args = array($form, &$form_state); |
||||||
|
$args = isset($step_info['args']) ? array_merge($args, $step_info['args']) : $args; |
||||||
|
$form = call_user_func_array($step_info['form_id'], $args); |
||||||
|
return islandora_ingest_form_stepify($form, $form_state, $step_info); |
||||||
|
case 'batch': |
||||||
|
// @todo Implement if possible. |
||||||
|
break; |
||||||
|
} |
||||||
|
return array(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Append Prev/Next buttons submit/validation handlers etc. |
||||||
|
* |
||||||
|
* @param array $form |
||||||
|
* The drupal form. |
||||||
|
* @param array $form_state |
||||||
|
* The drupal form state. |
||||||
|
* @param array $step_info |
||||||
|
* The info for building the current form step. |
||||||
|
* |
||||||
|
* @return array |
||||||
|
* The stepified drupal form definition for the given step. |
||||||
|
*/ |
||||||
|
function islandora_ingest_form_stepify(array $form, array &$form_state, array $step_info) { |
||||||
|
$step = islandora_ingest_form_get_step($form_state); |
||||||
|
$first_step = $step > 0; |
||||||
|
$last_step = $step == (islandora_ingest_form_get_step_count($form_state) - 1); |
||||||
|
$form['prev'] = $first_step ? islandora_ingest_form_previous_button() : NULL; |
||||||
|
$form['next'] = $last_step ? islandora_ingest_form_ingest_button($step_info) : islandora_ingest_form_next_button($step_info); |
||||||
|
return $form; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Defines the previous button for the ingest form. |
||||||
|
* |
||||||
|
* @return array |
||||||
|
* The previous button for the ingest form. |
||||||
|
*/ |
||||||
|
function islandora_ingest_form_previous_button() { |
||||||
|
return array( |
||||||
|
'#type' => 'submit', |
||||||
|
'#value' => t('Previous'), |
||||||
|
'#name' => 'prev', |
||||||
|
'#submit' => array('islandora_ingest_form_previous_submit'), |
||||||
|
// #limit_validation_errors, is why when the previous button is pressed no |
||||||
|
// values persisted in the form_state, but its also what allows us to go |
||||||
|
// back when validation errors occur. To have a better solution going |
||||||
|
// forward we can either limit validation only on required fields, or we can |
||||||
|
// convert all required fields to use #element_validation functions, and |
||||||
|
// Remove the need for #limit_validation_errors. Or maybe there is some |
||||||
|
// other solution, regardless of what it is, it won't be standard. |
||||||
|
'#limit_validation_errors' => array() |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* The submit handler for the ingest form previous button. |
||||||
|
* |
||||||
|
* Stores the current form steps values in the form storage. |
||||||
|
* Moves the focus of the multi-page ingest form back one step. |
||||||
|
* Restores the form values for the previous step. |
||||||
|
* |
||||||
|
* @param array $form |
||||||
|
* The drupal form. |
||||||
|
* @param array $form_state |
||||||
|
* The drupal form state. |
||||||
|
*/ |
||||||
|
function islandora_ingest_form_previous_submit(array $form, array &$form_state) { |
||||||
|
$step = &islandora_ingest_form_get_step($form_state); |
||||||
|
$step_info = &islandora_ingest_form_get_step_info($form_state, $step); |
||||||
|
$step_info['values'] = $form_state['values']; |
||||||
|
$step--; |
||||||
|
$step_info = &islandora_ingest_form_get_step_info($form_state, $step); |
||||||
|
$form_state['values'] = isset($step_info['values']) ? $step_info['values'] : NULL; |
||||||
|
$form_state['rebuild'] = TRUE; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Defines the next button for the ingest form. |
||||||
|
* |
||||||
|
* Adds submit/validate handlers for the form step if they exist. |
||||||
|
* |
||||||
|
* @return array |
||||||
|
* The next button for the ingest form. |
||||||
|
*/ |
||||||
|
function islandora_ingest_form_next_button(array $step_info) { |
||||||
|
$form_id = $step_info['form_id']; |
||||||
|
$validate_callback = $form_id . '_validate'; |
||||||
|
$validate = function_exists($validate_callback) ? array($validate_callback) : NULL; |
||||||
|
$submit_callback = $form_id . '_submit'; |
||||||
|
$submit = function_exists($submit_callback) ? array($submit_callback, 'islandora_ingest_form_next_submit') : array('islandora_ingest_form_next_submit'); |
||||||
|
return array( |
||||||
|
'#type' => 'submit', |
||||||
|
'#value' => t('Next'), |
||||||
|
'#name' => 'next', |
||||||
|
'#validate' => $validate, |
||||||
|
'#submit' => $submit |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* The submit handler for the ingest form next button. |
||||||
|
* |
||||||
|
* Stores the current form steps values in the form storage. |
||||||
|
* Moves the focus of the multi-page ingest form forward one step. |
||||||
|
* Restores the form values for the next step if present. |
||||||
|
* |
||||||
|
* @param array $form |
||||||
|
* The drupal form. |
||||||
|
* @param array $form_state |
||||||
|
* The drupal form state. |
||||||
|
*/ |
||||||
|
function islandora_ingest_form_next_submit(array $form, array &$form_state) { |
||||||
|
$step = &islandora_ingest_form_get_step($form_state); |
||||||
|
$step_info = &islandora_ingest_form_get_step_info($form_state, $step); |
||||||
|
$step_info['values'] = $form_state['values']; |
||||||
|
$step++; |
||||||
|
$step_info = &islandora_ingest_form_get_step_info($form_state, $step); |
||||||
|
$form_state['values'] = isset($step_info['values']) ? $step_info['values'] : array(); |
||||||
|
$form_state['rebuild'] = TRUE; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Defines the ingest button for the ingest form. |
||||||
|
* |
||||||
|
* This button is only shown on the last page of the multi-page ingest form. |
||||||
|
* |
||||||
|
* @return array |
||||||
|
* The ingest button for the ingest form. |
||||||
|
*/ |
||||||
|
function islandora_ingest_form_ingest_button(array $step_info) { |
||||||
|
$form_id = $step_info['form_id']; |
||||||
|
$validate_callback = $form_id . '_validate'; |
||||||
|
$validate = function_exists($validate_callback) ? array($validate_callback) : NULL; |
||||||
|
$submit_callback = $form_id . '_submit'; |
||||||
|
$submit = function_exists($submit_callback) ? array($submit_callback, 'islandora_ingest_form_submit') : array('islandora_ingest_form_submit'); |
||||||
|
return array( |
||||||
|
'#type' => 'submit', |
||||||
|
'#name' => 'ingest', |
||||||
|
'#value' => t('Ingest'), |
||||||
|
'#validate' => $validate, |
||||||
|
'#submit' => $submit |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* The submit handler for the ingest form. |
||||||
|
* |
||||||
|
* Attempts to ingest every object built by the previous steps. |
||||||
|
* |
||||||
|
* @param array $form |
||||||
|
* The drupal form. |
||||||
|
* @param array $form_state |
||||||
|
* The drupal form state. |
||||||
|
*/ |
||||||
|
function islandora_ingest_form_submit(array $form, array &$form_state) { |
||||||
|
foreach ($form_state['islandora']['objects'] as $object) { |
||||||
|
try { |
||||||
|
islandora_add_object($object); |
||||||
|
$form_state['redirect'] = "islandora/object/{$object->id}"; |
||||||
|
} catch (Exception $e) { |
||||||
|
// If post hooks throws it may already exist at this point but may be invalid, so don't say failed :P |
||||||
|
watchdog('islandora', $e->getMessage(), NULL, WATCHDOG_ERROR); |
||||||
|
drupal_set_message(t('A problem occured while ingesting "@label" (ID: @pid), please notifiy the administrator.', array('@label' => $object->label, '@pid' => $object->id)), 'error'); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Gets the configuration used to create the multi-page ingest form. |
||||||
|
* |
||||||
|
* @param array $form_state |
||||||
|
* The drupal form state. |
||||||
|
* |
||||||
|
* @return array |
||||||
|
* The configuration used to generate the multi-page ingest forms. |
||||||
|
*/ |
||||||
|
function islandora_ingest_form_get_configuration(array $form_state) { |
||||||
|
return $form_state['islandora']['configuration']; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Gets a reference to the stored NewFedoraObject's which are to be ingested |
||||||
|
* when the final step submits. |
||||||
|
* |
||||||
|
* @param array $form_state |
||||||
|
* The drupal form state. |
||||||
|
* |
||||||
|
* @return array |
||||||
|
* A reference to the stored NewFedoraObjects to be ingested when the final |
||||||
|
* step submits. |
||||||
|
*/ |
||||||
|
function &islandora_ingest_form_get_objects(array $form_state) { |
||||||
|
return $form_state['islandora']['objects']; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Gets a single object from the stored NewFedoraObject's. |
||||||
|
* |
||||||
|
* @note - In our current use case we are only dealing with a single object |
||||||
|
* ingest, this makes it convenient to access it. Ideally the steps |
||||||
|
* implementations will be abstracted to be indifferent to what object it's |
||||||
|
* currently working on. This will act as a placeholder for such |
||||||
|
* functionality. |
||||||
|
* |
||||||
|
* @param array $form_state |
||||||
|
* The drupal form state. |
||||||
|
* |
||||||
|
* @return array |
||||||
|
* Returns the 'current' object in the array of NewFedoraObjects, generally |
||||||
|
* this is only used when there is one object in the list of objects. |
||||||
|
*/ |
||||||
|
function islandora_ingest_form_get_object(array $form_state) { |
||||||
|
$objects = &islandora_ingest_form_get_objects($form_state); |
||||||
|
return current($objects); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get a reference to the current step index. |
||||||
|
* |
||||||
|
* @param array $form_state |
||||||
|
* The drupal form state. |
||||||
|
* |
||||||
|
* @return int |
||||||
|
* The current step index. |
||||||
|
*/ |
||||||
|
function &islandora_ingest_form_get_step(array &$form_state) { |
||||||
|
return $form_state['islandora']['step']; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get a reference to the step info of the given step or the current step if |
||||||
|
* none is given. |
||||||
|
* |
||||||
|
* @param array $form_state |
||||||
|
* The drupal form state. |
||||||
|
* @param int $step |
||||||
|
* The index of the step to get. |
||||||
|
* |
||||||
|
* @return integer |
||||||
|
* The step info of the requested step if found, NULL otherwise. |
||||||
|
*/ |
||||||
|
function &islandora_ingest_form_get_step_info(array &$form_state, $step = NULL) { |
||||||
|
$step = isset($step) ? $step : islandora_ingest_form_get_step($form_state); |
||||||
|
$steps = &islandora_ingest_form_get_steps($form_state); |
||||||
|
if (!empty($steps[$step])) { |
||||||
|
return $steps[$step]; |
||||||
|
} |
||||||
|
// @todo deal with unknown case. |
||||||
|
return NULL; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get a reference to the steps stored in the form state. |
||||||
|
* |
||||||
|
* @param array $form_state |
||||||
|
* The drupal form state. |
||||||
|
* |
||||||
|
* @return array |
||||||
|
* All the steps to be used in the ingest process. |
||||||
|
*/ |
||||||
|
function &islandora_ingest_form_get_steps(array &$form_state) { |
||||||
|
return $form_state['islandora']['steps']; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Call form_load_include, for the current step if it defines a required file. |
||||||
|
* |
||||||
|
* @param array $form_state |
||||||
|
* The drupal form state. |
||||||
|
*/ |
||||||
|
function islandora_ingest_form_step_form_load_include(array &$form_state) { |
||||||
|
form_load_include($form_state, 'inc', 'islandora', 'includes/ingest.form'); |
||||||
|
$step_info = islandora_ingest_form_get_step_info($form_state); |
||||||
|
// Load include files |
||||||
|
if (isset($step_info['file']) && isset($step_info['module'])) { |
||||||
|
$matches = array(); |
||||||
|
preg_match('/^(.*)\.(.*)$/', $step_info['file'], $matches); |
||||||
|
list($file, $name, $type) = $matches; |
||||||
|
form_load_include($form_state, $type, $step_info['module'], $name); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get the number of steps. |
||||||
|
* |
||||||
|
* @param array $form_state |
||||||
|
* The drupal form state. |
||||||
|
* |
||||||
|
* @return int |
||||||
|
* The number of steps. |
||||||
|
*/ |
||||||
|
function islandora_ingest_form_get_step_count(array $form_state) { |
||||||
|
$steps = islandora_ingest_form_get_steps($form_state); |
||||||
|
return count($steps); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Buildes the initial list of ingest steps. |
||||||
|
* |
||||||
|
* Sorted by weight expected range between -50 to 50. |
||||||
|
* |
||||||
|
* The sort order is undefined for steps which have the same weight. |
||||||
|
* |
||||||
|
* @param array $configuration |
||||||
|
* The configuration options used to build the multi-paged ingest process. |
||||||
|
* |
||||||
|
* @return array |
||||||
|
* The initial list of sorted ingest steps as defined by all implementers |
||||||
|
* of ISLANDORA_INGEST_STEP_HOOK. |
||||||
|
*/ |
||||||
|
function islandora_ingest_get_steps(array $configuration) { |
||||||
|
module_load_include('inc', 'islandora', 'includes/utilities'); |
||||||
|
$steps = array(); |
||||||
|
$models = isset($configuration['models']) ? $configuration['models'] : array(); |
||||||
|
foreach (islandora_build_hook_list(ISLANDORA_INGEST_STEP_HOOK, $models) as $hook) { |
||||||
|
$steps = array_merge($steps, module_invoke_all($hook, $configuration)); |
||||||
|
} |
||||||
|
// Remove NULL values. |
||||||
|
$steps = array_filter($steps); |
||||||
|
usort($steps, 'drupal_sort_weight'); |
||||||
|
return $steps; |
||||||
|
} |
@ -0,0 +1,66 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
/** |
||||||
|
* @file |
||||||
|
* |
||||||
|
* Ingest Menu callback hooks. |
||||||
|
*/ |
||||||
|
|
||||||
|
/** |
||||||
|
* Menu callback, Renders the multi-page ingest form if possible. |
||||||
|
* |
||||||
|
* @return string |
||||||
|
* HTML representing the mult-page ingest form. |
||||||
|
*/ |
||||||
|
function islandora_ingest_callback() { |
||||||
|
$configuration = islandora_ingest_get_configuration(); |
||||||
|
if ($configuration === FALSE) { |
||||||
|
drupal_set_message(t('Invalid ingest configuration.'), 'error'); |
||||||
|
$redirect = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '<front>'; |
||||||
|
// Redirect back to referer or top level collection. |
||||||
|
drupal_goto($redirect); |
||||||
|
} |
||||||
|
module_load_include('inc', 'islandora', 'includes/ingest.form'); |
||||||
|
return drupal_get_form('islandora_ingest_form', $configuration); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Fetches/validates the ingest configuration from the $_GET parameters. |
||||||
|
* |
||||||
|
* Generic parameters as accepted by all ingest processes, other modules may |
||||||
|
* add to this list. |
||||||
|
* id -> The pid of the object to create. optional. |
||||||
|
* models -> Comma delimited list of all the content models the created object |
||||||
|
* should have. |
||||||
|
* collections -> Comma delimited list of all the collections the created |
||||||
|
* object should belong to. |
||||||
|
* |
||||||
|
* @return array |
||||||
|
* The configuration options used to build the multi-paged ingest process. |
||||||
|
*/ |
||||||
|
function islandora_ingest_get_configuration() { |
||||||
|
$configuration = $_GET; |
||||||
|
unset($configuration['q']); |
||||||
|
$convert_to_array_keys = array_intersect(array('models', 'collections'), array_keys($configuration)); |
||||||
|
foreach ($convert_to_array_keys as $key) { |
||||||
|
$configuration[$key] = explode(',', $configuration[$key]); |
||||||
|
} |
||||||
|
// @todo add hook for manipulating/validating the configuration. |
||||||
|
return islandora_valid_ingest_configuration($configuration) ? $configuration : FALSE; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Validates the given ingest configuration. |
||||||
|
* |
||||||
|
* At the moment it requires that models and collections are present. |
||||||
|
* |
||||||
|
* @param array $configuration |
||||||
|
* The key value pairs that are used to build the multi-paged ingest process. |
||||||
|
* |
||||||
|
* @return boolean |
||||||
|
* TRUE if the configuration is valid, FALSE otherwise. |
||||||
|
*/ |
||||||
|
function islandora_valid_ingest_configuration(array $configuration) { |
||||||
|
// @todo Add more robust validation, add watchdog logs, etc. |
||||||
|
return isset($configuration['models']) && isset($configuration['collections']); |
||||||
|
} |
@ -1,237 +0,0 @@ |
|||||||
<?php |
|
||||||
|
|
||||||
/** |
|
||||||
* @file |
|
||||||
* This file contains ingest callback functions. |
|
||||||
*/ |
|
||||||
|
|
||||||
/** |
|
||||||
* @TODO: needs documentation |
|
||||||
*/ |
|
||||||
function islandora_ingest_get_information(AbstractFedoraObject $collection_object) { |
|
||||||
$models = $collection_object->models; |
|
||||||
$collection_info = module_invoke_all('islandora_ingest_get_information', $models, $collection_object); |
|
||||||
|
|
||||||
return $collection_info; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Get an ingestable object. |
|
||||||
* |
|
||||||
* @deprecated |
|
||||||
* Deprecated in favour of the more flexible |
|
||||||
* islandora_ingest_new_object_prepare()--which this function has been made |
|
||||||
* to call behind the scenes anyway. |
|
||||||
* |
|
||||||
* @param array $content_models |
|
||||||
* An array of content models to which the new object should subscribe, where |
|
||||||
* each content model is described by an associative array containing: |
|
||||||
* - pid: The Fedora PID of the content model. |
|
||||||
* @param string $collection_pid |
|
||||||
* The collection to which the new object should belong. |
|
||||||
* @param string $relationship |
|
||||||
* The relationship this object will have to the collection. |
|
||||||
* @param string $namespace |
|
||||||
* The namespace in which the PID for the new object will be created. |
|
||||||
* |
|
||||||
* @return NewFedoraObject |
|
||||||
* A NewFedoraObject which may be adjusted before ingesting. |
|
||||||
*/ |
|
||||||
function islandora_ingest_get_object($content_models, $collection_pid, $relationship, $namespace) { |
|
||||||
$models = array(); |
|
||||||
foreach ($content_models as $relation) { |
|
||||||
$models[] = $relation['pid']; |
|
||||||
} |
|
||||||
|
|
||||||
return islandora_ingest_new_object_prepare($namespace, NULL, array(), $models, array( |
|
||||||
array( |
|
||||||
'pid' => $collection_pid, |
|
||||||
'relationship' => $relationship, |
|
||||||
), |
|
||||||
), $collection_pid); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Prepare an ingestable object. |
|
||||||
* |
|
||||||
* @param string $namespace |
|
||||||
* The namespace in which the PID for the new object will be created. |
|
||||||
* @param string $label |
|
||||||
* An optional label to apply to the object. |
|
||||||
* @param array $datastreams |
|
||||||
* A array of datastreams to add, where each datastream definition is an |
|
||||||
* associative array containing: |
|
||||||
* - dsid: The datastream ID. |
|
||||||
* - label: An optional label for the datastream. |
|
||||||
* - mimetype: A MIMEtype for the datastream; defaults to text/xml. |
|
||||||
* - control_group: One of X, M, R and E; defaults to M. |
|
||||||
* - datastream_file: A web-accessible path, for which we try to get an |
|
||||||
* absolute path using url(). |
|
||||||
* @param array $content_models |
|
||||||
* An array of content model PIDs to which the new object should subscribe. |
|
||||||
* @param array $relationships |
|
||||||
* An array of relationships, where each relationship is an associative array |
|
||||||
* containing: |
|
||||||
* - relationship: The predicate for the relationship, from the Fedora |
|
||||||
* RELS-EXT namespace. |
|
||||||
* - pid: The object for the relationship, to which we are creating the |
|
||||||
* relationhsip. |
|
||||||
* |
|
||||||
* @return NewFedoraObject |
|
||||||
* An ingestable NewFedoraObject. |
|
||||||
*/ |
|
||||||
function islandora_ingest_new_object_prepare($namespace = NULL, $label = NULL, $datastreams = array(), $content_models = array(), $relationships = array(), $collection_pid = NULL) { |
|
||||||
// include Tuque library |
|
||||||
module_load_include('inc', 'islandora', 'includes/tuque'); |
|
||||||
global $user; |
|
||||||
// new connection |
|
||||||
try { |
|
||||||
$connection = new IslandoraTuque($user); |
|
||||||
} catch (Exception $e) { |
|
||||||
drupal_set_message(t('Unable to connect to the repository %e', array('%e' => $e)), 'error'); |
|
||||||
return; |
|
||||||
} |
|
||||||
// construct new object |
|
||||||
$object = $connection->repository->constructObject($namespace); |
|
||||||
|
|
||||||
// add label |
|
||||||
if (!empty($label)) { |
|
||||||
$object->label = $label; |
|
||||||
} |
|
||||||
// add content model relationship(s) |
|
||||||
foreach ($content_models as $content_model) { |
|
||||||
$object->relationships->add(FEDORA_MODEL_URI, 'hasModel', $content_model); |
|
||||||
} |
|
||||||
// add collection relationship(s) |
|
||||||
if (!empty($relationships)) { |
|
||||||
foreach ($relationships as $relationship) { |
|
||||||
$object->relationships->add(FEDORA_RELS_EXT_URI, $relationship['relationship'], $relationship['pid']); |
|
||||||
} |
|
||||||
} |
|
||||||
// add datastreams |
|
||||||
foreach ((array) $datastreams as $ds) { |
|
||||||
// variables |
|
||||||
$ds_id = $ds['dsid']; |
|
||||||
$ds_label = isset($ds['label']) ? $ds['label'] : ''; |
|
||||||
$ds_mimetype = isset($ds['mimetype']) ? $ds['mimetype'] : 'text/xml'; |
|
||||||
$ds_control_group = (isset($ds['control_group']) AND in_array($ds['control_group'], array('X', 'M', 'R', 'E'))) ? $ds['control_group'] : 'M'; |
|
||||||
$ds_datastream_file = url($ds['datastream_file'], array('absolute' => TRUE)); |
|
||||||
|
|
||||||
// datastream object |
|
||||||
$datastream = $object->constructDatastream($ds_id, $ds_control_group); |
|
||||||
$datastream->label = $ds_label; |
|
||||||
$datastream->mimetype = $ds_mimetype; |
|
||||||
switch ($ds_control_group) { |
|
||||||
case 'M': |
|
||||||
$datastream->setContentFromUrl($ds_datastream_file); |
|
||||||
break; |
|
||||||
case 'X': |
|
||||||
$datastream->setContentFromString(file_get_contents($ds_datastream_file)); |
|
||||||
break; |
|
||||||
} |
|
||||||
$object->ingestDatastream($datastream); |
|
||||||
} |
|
||||||
|
|
||||||
module_load_include('inc', 'islandora', 'includes/utilities'); |
|
||||||
foreach (islandora_build_hook_list('islandora_ingest_pre_ingest', $content_models) as $hook) { |
|
||||||
module_invoke_all($hook, $object, $content_models, $collection_pid); |
|
||||||
} |
|
||||||
|
|
||||||
return $object; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Ingest the given object into Fedora. |
|
||||||
* |
|
||||||
* @param NewFedoraObject $object |
|
||||||
* An ingestable FedoraObject. |
|
||||||
* |
|
||||||
* @return FedoraObject |
|
||||||
* The ingested FedoraObject, after running the post ingest hooks. |
|
||||||
*/ |
|
||||||
function islandora_ingest_add_object(&$object) { |
|
||||||
drupal_alter('islandora_pre_ingest', $object); |
|
||||||
|
|
||||||
$object->repository->ingestObject($object); |
|
||||||
|
|
||||||
module_load_include('inc', 'islandora', 'includes/utilities'); |
|
||||||
|
|
||||||
foreach (islandora_build_hook_list(ISLANDORA_POST_INGEST_HOOK, $object->models) as $hook) { |
|
||||||
module_invoke_all($hook, $object); |
|
||||||
} |
|
||||||
|
|
||||||
return $object; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Ingest an object. |
|
||||||
* |
|
||||||
* @param array $object_model |
|
||||||
* An associative array containing the necessary parameters to create the |
|
||||||
* desired object: |
|
||||||
* - pid: The PID with which the object will be created. |
|
||||||
* - label: An optional label to apply to the object. |
|
||||||
* - datastreams: Same as the "datastreams" array accepted by |
|
||||||
* islandora_ingest_new_object_prepare(). |
|
||||||
* - cmodel: Either an array of content models as accepted by |
|
||||||
* islandora_ingest_new_object_prepare(), or a single content model PID to add |
|
||||||
* to the object. |
|
||||||
* - parent: Either an array of parents, or a single parent PID to which to |
|
||||||
* relate to; uses isMemberOfCollection by default. |
|
||||||
* - relationships: An array of relationships as accepted by |
|
||||||
* islandora_ingest_new_object_prepare(). |
|
||||||
* |
|
||||||
* @return FedoraObject |
|
||||||
* An FedoraObject which has been ingested into Fedora. |
|
||||||
*/ |
|
||||||
function islandora_ingest_new_object($object_model) { |
|
||||||
// prepare variables |
|
||||||
// namespace |
|
||||||
$namespace = $object_model['pid']; |
|
||||||
// label |
|
||||||
$label = !empty($object_model['label']) ? $object_model['label'] : NULL; |
|
||||||
// datastreams |
|
||||||
$datastreams = array(); |
|
||||||
if (!empty($object_model['datastreams']) AND is_array($object_model['datastreams'])) { |
|
||||||
$datastreams = $object_model['datastreams']; |
|
||||||
} |
|
||||||
// content models |
|
||||||
$content_models = array(); |
|
||||||
if (!empty($object_model['cmodel'])) { |
|
||||||
if (is_array($object_model['cmodel'])) { |
|
||||||
$content_models = $object_model['cmodel']; |
|
||||||
} |
|
||||||
else { |
|
||||||
$content_models[] = $object_model['cmodel']; |
|
||||||
} |
|
||||||
} |
|
||||||
// relationships |
|
||||||
$relationships = array(); |
|
||||||
// single parent |
|
||||||
if (!empty($object_model['parent']) AND !is_array($object_model['parent'])) { |
|
||||||
$relationships[] = array('relationship' => 'isMemberOfCollection', 'pid' => $object_model['parent']); |
|
||||||
} |
|
||||||
// parents array |
|
||||||
if (!empty($object_model['parents']) AND is_array($object_model['parents'])) { |
|
||||||
foreach ($object_model['parents'] as $parent) { |
|
||||||
$relationships[] = array('relationship' => 'isMemberOfCollection', 'pid' => $parent); |
|
||||||
} |
|
||||||
} |
|
||||||
// other relationships |
|
||||||
if (!empty($object_model['relationships']) AND is_array($object_model['relationships'])) { |
|
||||||
foreach ($object_model['relationships'] as $relationship) { |
|
||||||
$relationships[] = array('relationship' => $relationship['relationship'], 'pid' => $relationship['pid']); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
// build new object |
|
||||||
$object = islandora_ingest_new_object_prepare($namespace, $label, $datastreams, $content_models, $relationships); |
|
||||||
|
|
||||||
// ingest (and return) new object |
|
||||||
return islandora_ingest_add_object($object); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,120 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
/** |
||||||
|
* @file |
||||||
|
* |
||||||
|
* Contains admin form functions for editing an object's properties. |
||||||
|
*/ |
||||||
|
|
||||||
|
/** |
||||||
|
* Object properties admin form. |
||||||
|
* |
||||||
|
* @param array $form |
||||||
|
* The Drupal form. |
||||||
|
* @param array $form_state |
||||||
|
* The Drupal form state. |
||||||
|
* @param FedoraObject $object |
||||||
|
* The object whose properties this form will modify. |
||||||
|
* |
||||||
|
* @return array |
||||||
|
* The drupal form definition. |
||||||
|
*/ |
||||||
|
function islandora_object_properties_form(array $form, array &$form_state, FedoraObject $object) { |
||||||
|
drupal_set_title($object->label); |
||||||
|
$form_state['object'] = $object; |
||||||
|
return array( |
||||||
|
'pid' => array( |
||||||
|
'#type' => 'hidden', |
||||||
|
'#value' => $object->id |
||||||
|
), |
||||||
|
'object_label' => array( |
||||||
|
'#title' => t('Item Label'), |
||||||
|
'#default_value' => $object->label, |
||||||
|
'#required' => 'TRUE', |
||||||
|
'#description' => t('A Human readable label'), |
||||||
|
// Double the normal length |
||||||
|
'#size' => 120, |
||||||
|
// Max length for a Fedora Label |
||||||
|
'#maxlength' => 255, |
||||||
|
'#type' => 'textfield' |
||||||
|
), |
||||||
|
// @todo Make this into an autocomplete field that list the users in the |
||||||
|
// system as well. |
||||||
|
'object_owner' => array( |
||||||
|
'#title' => t('Owner'), |
||||||
|
'#default_value' => $object->owner, |
||||||
|
'#required' => FALSE, |
||||||
|
'#description' => t('The owner id'), |
||||||
|
'#type' => 'textfield' |
||||||
|
), |
||||||
|
'object_state' => array( |
||||||
|
'#title' => t('State'), |
||||||
|
'#default_value' => $object->state, |
||||||
|
'#required' => TRUE, |
||||||
|
'#description' => t('The items state one of active, inactive or deleted'), |
||||||
|
'#type' => 'select', |
||||||
|
'#options' => array('A' => 'Active', 'I' => 'Inactive', 'D' => 'Deleted') |
||||||
|
), |
||||||
|
'submit' => array( |
||||||
|
'#type' => 'submit', |
||||||
|
'#value' => 'Update Properties' |
||||||
|
), |
||||||
|
'delete' => array( |
||||||
|
'#type' => 'submit', |
||||||
|
'#value' => t('Delete'), |
||||||
|
'#submit' => array('islandora_object_properties_form_delete'), |
||||||
|
'#limit_validation_errors' => array(array('pid')) |
||||||
|
) |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Submit handler for object properties admin form. |
||||||
|
* |
||||||
|
* @param array $form |
||||||
|
* The Drupal form. |
||||||
|
* @param array $form_state |
||||||
|
* The Drupal form state. |
||||||
|
*/ |
||||||
|
function islandora_object_properties_form_submit(array $form, array &$form_state) { |
||||||
|
$object = $form_state['object']; |
||||||
|
$owner = $form_state['values']['object_owner']; |
||||||
|
$state = $form_state['values']['object_state']; |
||||||
|
$label = $form_state['values']['object_label']; |
||||||
|
if (isset($owner) && $owner != $object->owner) { |
||||||
|
try { |
||||||
|
$object->owner = $owner; |
||||||
|
drupal_set_message(t('Successfully updated owner %s', array('%s' => $owner))); |
||||||
|
} catch (Exception $e) { |
||||||
|
form_set_error('object_owner', t('Error updating owner %s', array('%s' => $e->getMessage()))); |
||||||
|
} |
||||||
|
} |
||||||
|
if (isset($state) && $state != $object->state) { |
||||||
|
try { |
||||||
|
$object->state = $state; |
||||||
|
drupal_set_message(t('Successfully updated state %s', array('%s' => $state))); |
||||||
|
} catch (Exception $e) { |
||||||
|
form_set_error('object_state', t('Error updating state %s', array('%s' => $e->getMessage()))); |
||||||
|
} |
||||||
|
} |
||||||
|
if (isset($label) && $label != $object->label) { |
||||||
|
try { |
||||||
|
$object->label = $label; |
||||||
|
drupal_set_message(t('Successfully updated label %s', array('%s' => check_plain($label)))); |
||||||
|
} catch (Exception $e) { |
||||||
|
form_set_error(t('Error updating label %s', array('%s' => $e->getMessage()))); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Callback function for object properties admin form delete button. |
||||||
|
* |
||||||
|
* @param array $form |
||||||
|
* The Drupal form. |
||||||
|
* @param array $form_state |
||||||
|
* The Drupal form state. |
||||||
|
*/ |
||||||
|
function islandora_object_properties_form_delete(array $form, array &$form_state) { |
||||||
|
drupal_goto("islandora/object/{$form_state['values']['pid']}/delete"); |
||||||
|
} |
@ -1,125 +0,0 @@ |
|||||||
<?php |
|
||||||
|
|
||||||
/** |
|
||||||
* @file |
|
||||||
* Contains admin form functions for object properties |
|
||||||
*/ |
|
||||||
|
|
||||||
/** |
|
||||||
* Validate function for object properties admin form. |
|
||||||
* |
|
||||||
* @TODO: may want more validation here the only restrictions i see on |
|
||||||
* the object label and owner is the foxml schema says they should be |
|
||||||
* an xsd:string there maybe further restrictions such as length but they aren't |
|
||||||
* defined in the schema. |
|
||||||
* @param array $form |
|
||||||
* @param array $form_state |
|
||||||
* @return boolean |
|
||||||
*/ |
|
||||||
function islandora_edit_properties_form_validate($form, &$form_state) { |
|
||||||
$islandora_object = islandora_object_load($form_state['values']['pid']); |
|
||||||
if (!isset($islandora_object)) { |
|
||||||
form_set_error('', t('Could not update properties object not found.')); |
|
||||||
return FALSE; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Submit function for object properties admin form. |
|
||||||
* |
|
||||||
* @param array $form |
|
||||||
* @param array $form_state |
|
||||||
*/ |
|
||||||
function islandora_edit_properties_form_submit($form, &$form_state) { |
|
||||||
$islandora_object = islandora_object_load($form_state['values']['pid']); |
|
||||||
$owner = $form_state['values']['object_owner']; |
|
||||||
$state = $form_state['values']['object_state']; |
|
||||||
$label = $form_state['values']['object_label']; |
|
||||||
if (isset($owner) && $owner != $islandora_object->owner) { |
|
||||||
try { |
|
||||||
$islandora_object->owner = $owner; |
|
||||||
drupal_set_message(t('Successfully updated owner %s', array('%s' => $owner))); |
|
||||||
} catch (Exception $e) { |
|
||||||
form_set_error('object_owner', t('Error updating owner %s', array('%s' => $e->getMessage()))); |
|
||||||
} |
|
||||||
} |
|
||||||
if (isset($state) && $state != $islandora_object->state) { |
|
||||||
try { |
|
||||||
$islandora_object->state = $state; |
|
||||||
drupal_set_message(t('Successfully updated state %s', array('%s' => $state))); |
|
||||||
} catch (Exception $e) { |
|
||||||
form_set_error('object_state', t('Error updating state %s', array('%s' => $e->getMessage()))); |
|
||||||
} |
|
||||||
} |
|
||||||
if (isset($label) && $label != $islandora_object->label) { |
|
||||||
try { |
|
||||||
$islandora_object->label = $label; |
|
||||||
drupal_set_message(t('Successfully updated label %s', array('%s' => check_plain($label)))); |
|
||||||
} catch (Exception $e) { |
|
||||||
form_set_error(t('Error updating label %s', array('%s' => $e->getMessage()))); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Callback function for object properties admin form delete button. |
|
||||||
*/ |
|
||||||
function islandora_edit_properties_form_delete($form, &$form_state) { |
|
||||||
$islandora_object = $form_state['values']['pid']; |
|
||||||
drupal_goto("islandora/object/$islandora_object/delete"); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Object properties admin form. |
|
||||||
* |
|
||||||
* @param array $form |
|
||||||
* @param array $form_state |
|
||||||
* @param string $object_id |
|
||||||
* an object id |
|
||||||
* @return array |
|
||||||
*/ |
|
||||||
function islandora_edit_properties_form($form, &$form_state, $object) { |
|
||||||
$form = array(); |
|
||||||
if (!isset($object)) { |
|
||||||
return NULL; |
|
||||||
} |
|
||||||
drupal_set_title($object->label); |
|
||||||
$form['pid'] = array( |
|
||||||
'#type' => 'hidden', |
|
||||||
'#value' => $object->id, |
|
||||||
); |
|
||||||
|
|
||||||
$form['object_label'] = array( |
|
||||||
'#title' => t('Item Label'), |
|
||||||
'#default_value' => $object->label, |
|
||||||
'#required' => 'TRUE', |
|
||||||
'#description' => t('A Human readable label'), |
|
||||||
'#type' => 'textfield' |
|
||||||
); |
|
||||||
$form['object_owner'] = array( |
|
||||||
'#title' => t('Owner'), |
|
||||||
'#default_value' => $object->owner, |
|
||||||
'#required' => FALSE, |
|
||||||
'#description' => t('The owner id'), |
|
||||||
'#type' => 'textfield', |
|
||||||
); |
|
||||||
$form['object_state'] = array( |
|
||||||
'#title' => t('State'), |
|
||||||
'#default_value' => $object->state, |
|
||||||
'#required' => TRUE, |
|
||||||
'#description' => t('The items state one of active, inactive or deleted'), |
|
||||||
'#type' => 'select', |
|
||||||
'#options' => array('A' => 'Active', 'I' => 'Inactive', 'D' => 'Deleted'), |
|
||||||
); |
|
||||||
$form['submit'] = array( |
|
||||||
'#type' => 'submit', |
|
||||||
'#value' => 'Update Properties', |
|
||||||
); |
|
||||||
$form['delete'] = array( |
|
||||||
'#type' => 'submit', |
|
||||||
'#value' => t('Delete'), |
|
||||||
'#submit' => array('islandora_edit_properties_form_delete'), |
|
||||||
'#limit_validation_errors' => array(array('pid')), |
|
||||||
); |
|
||||||
return $form; |
|
||||||
} |
|
@ -1,138 +0,0 @@ |
|||||||
<?php |
|
||||||
|
|
||||||
/** |
|
||||||
* @file |
|
||||||
* This file contains the admin (confirmation) form and callback functions to purge an object. |
|
||||||
*/ |
|
||||||
|
|
||||||
/** |
|
||||||
* Gives the option of deleting or purging and object. |
|
||||||
* |
|
||||||
* The default behaviour is to purge the object to reduce maintenance. |
|
||||||
* If a solution pack wants to change this behaviour and have the object set to deleted then |
|
||||||
* it can respond to the 'islandora_pre_purge_object' hook with an array containing the pair |
|
||||||
* 'delete' => TRUE. |
|
||||||
* Once the object has been deleted/purged then a second call lets the solution packs know that |
|
||||||
* the object has been dealt with. In this call the object id and content models are sent out so |
|
||||||
* that the solution packs can act on this news. There is no guarantee that the object still exists |
|
||||||
* and so the object object isn't sent. |
|
||||||
* |
|
||||||
* @param string $object_id |
|
||||||
* ID of the object |
|
||||||
* @return type |
|
||||||
*/ |
|
||||||
function islandora_purge_object_submit($form, &$form_state) { |
|
||||||
|
|
||||||
$object_id = $form_state['values']['pid']; |
|
||||||
$collection = $form_state['values']['col']; |
|
||||||
|
|
||||||
// purge object |
|
||||||
islandora_object_purge($object_id); |
|
||||||
|
|
||||||
drupal_goto($collection); |
|
||||||
} |
|
||||||
|
|
||||||
function islandora_purge_object($form, &$form_state, $object) { |
|
||||||
module_load_include('inc', 'islandora', 'includes/datastream'); |
|
||||||
|
|
||||||
$parent = islandora_datastream_get_parents($object); |
|
||||||
$key = array_keys($parent); |
|
||||||
|
|
||||||
if (count($key) > 0) { |
|
||||||
$redirect = "islandora/object/$key[0]"; |
|
||||||
} |
|
||||||
else { |
|
||||||
$redirect = "islandora"; |
|
||||||
} |
|
||||||
|
|
||||||
$form['pid'] = array('#type' => 'value', '#value' => $object->id); |
|
||||||
$form['col'] = array('#type' => 'value', '#value' => $redirect); |
|
||||||
|
|
||||||
return confirm_form($form, |
|
||||||
t('Are you sure you want to delete %title?', array('%title' => $object->label)), |
|
||||||
"islandora/object/$object->id", |
|
||||||
t('This action cannot be undone.'), |
|
||||||
t('Delete'), |
|
||||||
t('Cancel') |
|
||||||
); |
|
||||||
} |
|
||||||
|
|
||||||
function islandora_purge_datastream($form, &$form_state, $object, $datastream_id) { |
|
||||||
module_load_include('inc', 'islandora', 'includes/datastream'); |
|
||||||
|
|
||||||
$datastream = $object->getDatastream($datastream_id); |
|
||||||
|
|
||||||
$redirect = "islandora/object/$object->id"; |
|
||||||
|
|
||||||
$form['pid'] = array('#type' => 'value', '#value' => $object->id); |
|
||||||
$form['dsid'] = array('#type' => 'value', '#value' => $datastream_id); |
|
||||||
$form['col'] = array('#type' => 'value', '#value' => $redirect); |
|
||||||
|
|
||||||
return confirm_form($form, |
|
||||||
t('Are you sure you want to delete the %dsid datastream?', array('%dsid' => $datastream->id)), |
|
||||||
"islandora/object/$object->id", |
|
||||||
t('This action cannot be undone.'), |
|
||||||
t('Delete'), |
|
||||||
t('Cancel') |
|
||||||
); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Gives the option of purging or deleting a datastream. |
|
||||||
* |
|
||||||
* The default behaviour is to purge the datastream but this can be overridden using the |
|
||||||
* 'islandora_pre_purge_datastream' hook. The returned array can include a 'block' => TRUE |
|
||||||
* pair which will prevent the datastream from being deleted if it particularly needed for |
|
||||||
* a certain function. Returning 'delete' => TRUE will cause the datastream to be put into |
|
||||||
* a deleted state. |
|
||||||
* |
|
||||||
* @param string $object_id |
|
||||||
* ID of the object |
|
||||||
* @param string $datastream_id |
|
||||||
* ID of the datastream |
|
||||||
* |
|
||||||
*/ |
|
||||||
function islandora_purge_datastream_submit($form, &$form_state) { |
|
||||||
$object_id = $form_state['values']['pid']; |
|
||||||
$datastream_id = $form_state['values']['dsid']; |
|
||||||
|
|
||||||
if (!isset($datastream_id)) { |
|
||||||
drupal_set_message(t('Cannot remove datastream, datastream id not set')); |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
$object = islandora_object_load($object_id); |
|
||||||
|
|
||||||
if (!isset($object)) { |
|
||||||
drupal_set_message(t('Could not remove object, object not found')); |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
//notify modules of pending deletion so we can update rels etc |
|
||||||
$arr = module_invoke_all('islandora_pre_purge_datastream', $object[$datastream_id]); |
|
||||||
|
|
||||||
if (isset($arr['block']) && $arr['block']) { |
|
||||||
drupal_set_message(t('Purging of the %d datastream was blocked', array('%d' => $datastream_id)), 'warning'); |
|
||||||
return; |
|
||||||
} |
|
||||||
if (isset($arr['delete']) && $arr['delete']) { |
|
||||||
try { |
|
||||||
$object[$datastream_id]->state = 'D'; |
|
||||||
} catch (Exception $e) { |
|
||||||
drupal_set_message(t('Error deleting %s datastream from Islandora object %o %e', array('%s' => $datastream_id, '%o' => $object->id, '%e' => $e)), 'error'); |
|
||||||
return; |
|
||||||
} |
|
||||||
} |
|
||||||
else { |
|
||||||
try { |
|
||||||
$object->purgeDatastream($datastream_id); |
|
||||||
} catch (Exception $e) { |
|
||||||
drupal_set_message(t('Error purging %s datastream from Islandora object %o %e', array('%s' => $datastream_id, '%o' => $object_id, '%e' => $e)), 'error'); |
|
||||||
return; |
|
||||||
} |
|
||||||
} |
|
||||||
//notify modules post deletion |
|
||||||
module_invoke_all('islandora_post_purge_datastream', $object, $datastream_id); |
|
||||||
drupal_set_message(t('%d datastream sucessfully purged from Islandora object %o', array('%d' => $datastream_id, '%o' => $object->label))); |
|
||||||
drupal_goto('islandora/object/' . $object->id); |
|
||||||
} |
|
Loading…
Reference in new issue