Browse Source

Merge pull request #164 from willtp87/ISLANDORA-743

ISLANDORA-743  Before the hook was not firing at the right time.
pull/170/head
Jonathan Green 12 years ago
parent
commit
7ba65a7411
  1. 63
      fedora_repository.module
  2. 28
      fedora_repository.solutionpacks.inc

63
fedora_repository.module

@ -2250,7 +2250,9 @@ function _is_added_to_basket($pid, $account = NULL) {
/**
* fedora repository display schema
*
* @param type $file
*
* @return type
*/
function fedora_repository_display_schema($file) {
@ -2266,15 +2268,24 @@ function fedora_repository_display_schema($file) {
/**
* fedora repository batch reingest object
* @param type $object
* @param type $context
* @return type
*
* @param array $object
* An array defining an object to ingest.
* @param string $module_name
* The string needed in the finished callback to be
* sent out in the postprocess hook.
* @param array $context
* Variables shared between batch iterations
* and finished callback
*/
function fedora_repository_batch_reingest_object($object, &$context) {
function fedora_repository_batch_reingest_object($object, $module_name, &$context) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
module_load_include('inc', 'fedora_repository', 'api/fedora_utils');
$context['results']['module_name'] = $module_name;
if (!empty($object) && is_array($object)) {
$pid = $object['pid'];
if (!valid_pid($pid)) {
@ -2282,23 +2293,22 @@ function fedora_repository_batch_reingest_object($object, &$context) {
}
// 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?
// Need to have this a couple places...
// (After trying from FOXML and later for individual DSs)
$new_item = NULL;
// Seems like this might be getting messed up due to scope?.
$datastreams = array();
// 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; can still add additional DSs, though
// Batch operation was successful; can still add additional DSs, though.
$context['message'][] = t('%pid installed.', array('%pid' => $new_item->pid));
}
}
@ -2315,9 +2325,7 @@ function fedora_repository_batch_reingest_object($object, &$context) {
$label = !empty($object['label']) ? $object['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);
@ -2325,17 +2333,12 @@ function fedora_repository_batch_reingest_object($object, &$context) {
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 ((array) $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');
}
@ -2348,7 +2351,21 @@ function fedora_repository_batch_reingest_object($object, &$context) {
}
/**
* Content model, collection view and collection policy datastreams may now optionally define a version
* This function will send the postprocess solution pack hook.
* It is referenced by the solution pack form's batch finished entry.
*
*/
function fedora_repository_solutionpack_send_postprocess($success, $results, $operations) {
// Hook to let solution pack objects be modified.
// Not using module_invoke so solution packs can be expanded by other modules.
if ($success) {
module_invoke_all('postprocess_solution_pack', $results['module_name']);
}
}
/**
* Content model, collection view and collection policy datastreams may
* now optionally define a version
* number in their top-level XML element as an attribute, as in:
* <content_model name="Collection" version="2" ...
*
@ -2375,7 +2392,9 @@ function fedora_repository_get_islandora_datastream_version($item = NULL, $dsid
/**
* theme fedora repository solution pack list
*
* @param type $solution_packs
*
* @return string
*/
function theme_fedora_repository_solution_packs_list($solution_packs) {
@ -2390,8 +2409,10 @@ function theme_fedora_repository_solution_packs_list($solution_packs) {
}
/**
* Implementation of hook_forms()
* Implements hook_forms()
*
* @param string $form_id
*
* @return array
*/
function fedora_repository_forms($form_id) {
@ -2405,7 +2426,7 @@ function fedora_repository_forms($form_id) {
}
/**
* Implementation of hook_imagecache_default_presets().
* Implements hook_imagecache_default_presets().
*/
function fedora_repository_imagecache_default_presets() {
return array(

28
fedora_repository.solutionpacks.inc

@ -57,7 +57,11 @@ function fedora_repository_solution_packs_page() {
* Check for installed objects and add a 'Update' or 'Install' button if
* some objects are missing.
*
* @param array $solution_pack
* @param array &$form_state
* @param unknown $solution_pack_module
* @param string $solution_pack_name
* @param array $objects
* Defaults to an empty array.
*/
function fedora_repository_solution_pack_form(&$form_state, $solution_pack_module, $solution_pack_name, $objects = array()) {
@ -198,21 +202,24 @@ function fedora_repository_solution_pack_form_submit($form, &$form_state) {
foreach ($solution_pack_info[$module_name]['objects'] as $object) {
// Add this object to the batch job queue.
$batch['operations'][] = array('fedora_repository_batch_reingest_object', array($object));
// Module name is needed in the finished callback.
$batch['operations'][] = array('fedora_repository_batch_reingest_object', array($object, $module_name));
}
batch_set($batch);
// Tell the batch to call the function to send out a postprocess hook.
$batch['finished'] = 'fedora_repository_solutionpack_send_postprocess';
// Hook to let solution pack objects be modified.
// Not using module_invoke so solution packs can be expanded by other modules.
module_invoke_all('postprocess_solution_pack', $module_name);
batch_set($batch);
}
/**
* Writes a form entry into the database.
*
* @param unknown_type $form_name
* @param string $form_name
* The name of the form.
* @param unknown_type $form_xml
* The form definition.
*/
function solution_pack_add_form($form_name, $form_xml) {
$result = db_result(db_query('Select name from {xml_forms} where name = "%s"', $form_name));
@ -226,9 +233,12 @@ function solution_pack_add_form($form_name, $form_xml) {
}
/**
* Writes a form association to the database
*
* @param unknown_type $content_model
* @param unknown_type $form_name
* @param string $content_model
* content model PID
* @param string $form_name
* Name of the form
*/
function solution_pack_add_form_association($content_model, $form_name) {
$result = db_result(db_query('Select content_model from {islandora_content_model_forms} where content_model = "%s" and form_name = "%s"',

Loading…
Cancel
Save