Browse Source

resolved conflicts

pull/307/head
Alan Stanley 12 years ago
parent
commit
1761d0c2ad
  1. 5
      .travis.yml
  2. 64
      includes/breadcrumb.inc
  3. 322
      includes/ingest.form.inc
  4. 103
      includes/solution_packs.inc
  5. 8
      includes/tuque_wrapper.inc
  6. 92
      includes/utilities.inc
  7. 50
      islandora.api.php
  8. 7
      islandora.module
  9. 10
      tests/hooks.test
  10. 2
      tests/islandora_manage_permissions.test
  11. 14
      tests/scripts/line_endings.sh
  12. 2
      tests/scripts/travis_setup.sh

5
.travis.yml

@ -9,10 +9,11 @@ env:
- FEDORA_VERSION="3.5" - FEDORA_VERSION="3.5"
before_install: before_install:
- export ISLANDORA_DIR=$TRAVIS_BUILD_DIR - export ISLANDORA_DIR=$TRAVIS_BUILD_DIR
- $TRAVIS_BUILD_DIR/tests/travis_setup.sh - $TRAVIS_BUILD_DIR/tests/scripts/travis_setup.sh
- cd $HOME/drupal-* - cd $HOME/drupal-*
script: script:
- ant -buildfile sites/all/modules/islandora/build.xml lint - ant -buildfile sites/all/modules/islandora/build.xml lint
- drush dcs sites/all/modules/islandora - $ISLANDORA_DIR/tests/scripts/line_endings.sh sites/all/modules/islandora
- drush coder-review --reviews=production,security,style,i18n,potx,sniffer islandora
- phpcpd --names *.module,*.inc,*.test sites/all/modules/islandora - phpcpd --names *.module,*.inc,*.test sites/all/modules/islandora
- drush test-run --uri=http://localhost:8081 Islandora - drush test-run --uri=http://localhost:8081 Islandora

64
includes/breadcrumb.inc

@ -25,13 +25,8 @@
* drupal_set_breadcrumb(). * drupal_set_breadcrumb().
*/ */
function islandora_get_breadcrumbs($object) { function islandora_get_breadcrumbs($object) {
$breadcrumbs = array(); $breadcrumbs = islandora_get_breadcrumbs_recursive($object->id, $object->repository);
islandora_get_breadcrumbs_recursive($object->id, $breadcrumbs, $object->repository); array_pop($breadcrumbs);
if (isset($breadcrumbs[0])) {
// Remove the actual object.
unset($breadcrumbs[0]);
}
$breadcrumbs = array_reverse($breadcrumbs);
return $breadcrumbs; return $breadcrumbs;
} }
@ -40,30 +35,32 @@ function islandora_get_breadcrumbs($object) {
* *
* @todo Make fully recursive... * @todo Make fully recursive...
* *
* @todo Could use some clean up, can't be called multiple times safely due to
* the use of static variables.
*
* @param string $pid * @param string $pid
* THe object id whose parent will be fetched for the next link. * The object id whose parent will be fetched for the next link.
* @param array $breadcrumbs
* The list of existing bread-crumb links in reverse order.
* @param FedoraRepository $repository * @param FedoraRepository $repository
* The fedora repository. * The fedora repository.
* @param array $context
* An associative array of context for internal use when recursing. Currently
* only used to track a single value:
* - level: The number of child-parent relationships to follow. Defaults to
* 10.
*
* @return array
* An array of links representing the breadcrumb trail, "root" first.
*/ */
function islandora_get_breadcrumbs_recursive($pid, array &$breadcrumbs, FedoraRepository $repository) { function islandora_get_breadcrumbs_recursive($pid, FedoraRepository $repository, array &$context = NULL) {
// Before executing the query, we have a base case of accessing the top-level // Before executing the query, we have a base case of accessing the top-level
// collection. // collection.
static $max_level = 10; if ($context === NULL) {
static $level = -1; $context['level'] = 10;
if (count($breadcrumbs) === 0) {
$level = $max_level;
} }
$root = variable_get('islandora_repository_pid', 'islandora:root'); $root = variable_get('islandora_repository_pid', 'islandora:root');
if ($pid == $root) { if ($pid == $root) {
$breadcrumbs[] = l(menu_get_active_title(), 'islandora'); return array(
$breadcrumbs[] = l(t('Home'), '<front>'); l(t('Home'), '<front>'),
l(menu_get_active_title(), 'islandora'),
);
} }
else { else {
$query_string = 'select $parentObject $title $content from <#ri> $query_string = 'select $parentObject $title $content from <#ri>
@ -82,7 +79,7 @@ function islandora_get_breadcrumbs_recursive($pid, array &$breadcrumbs, FedoraRe
order by $title desc'; order by $title desc';
$results = $repository->ri->itqlQuery($query_string); $results = $repository->ri->itqlQuery($query_string);
if (count($results) > 0 && $level > 0) { if (count($results) > 0 && $context['level'] > 0) {
$parent = $results[0]['parentObject']['value']; $parent = $results[0]['parentObject']['value'];
$this_title = $results[0]['title']['value']; $this_title = $results[0]['title']['value'];
@ -90,16 +87,23 @@ function islandora_get_breadcrumbs_recursive($pid, array &$breadcrumbs, FedoraRe
$this_title = t('-'); $this_title = t('-');
} }
$breadcrumbs[] = l($this_title, "islandora/object/$pid"); $context['level']--;
return array_merge(
$level--; islandora_get_breadcrumbs_recursive($parent, $repository, $context),
islandora_get_breadcrumbs_recursive($parent, $breadcrumbs, $repository); array(
l($this_title, "islandora/object/$pid"),
)
);
} }
else { else {
// Add an non-link, as we don't know how to get back to the root. // Add an non-link, as we don't know how to get back to the root, and
$breadcrumbs[] = '...'; // render the last two links and break (on the next pass).
// And render the last two links and break (on the next pass). return array_merge(
islandora_get_breadcrumbs_recursive($root, $breadcrumbs, $repository); islandora_get_breadcrumbs_recursive($root, $repository, $context),
array(
'...',
)
);
} }
} }
} }

322
includes/ingest.form.inc

@ -26,6 +26,8 @@
* be related. * be related.
* - models: An array of content model PIDs, to which the new object might * - models: An array of content model PIDs, to which the new object might
* subscribe * subscribe
* - parent: The parent of the child to be ingested. This is needed for XACML
* to correctly apply the parent's POLICY to children.
* *
* @return array * @return array
* The form definition of the current step. * The form definition of the current step.
@ -35,7 +37,7 @@ function islandora_ingest_form(array $form, array &$form_state, array $configura
islandora_ingest_form_init_form_state_storage($form_state, $configuration); islandora_ingest_form_init_form_state_storage($form_state, $configuration);
return islandora_ingest_form_execute_step($form, $form_state); return islandora_ingest_form_execute_step($form, $form_state);
} }
catch(Exception $e) { catch (Exception $e) {
drupal_set_message($e->getMessage(), 'error'); drupal_set_message($e->getMessage(), 'error');
return array(array( return array(array(
'#markup' => l(t('Back'), 'javascript:window.history.back();', array('external' => TRUE)))); '#markup' => l(t('Back'), 'javascript:window.history.back();', array('external' => TRUE))));
@ -82,9 +84,42 @@ function islandora_ingest_form_init_form_state_storage(array &$form_state, array
'shared_storage' => $configuration, 'shared_storage' => $configuration,
'step_storage' => array(), 'step_storage' => array(),
); );
// Must be called after $form_state['islandora'] is initialized, otherwise,
// the values in 'islandora' would not be availible to the step hooks.
$form_state['islandora']['step_id'] = islandora_ingest_form_get_first_step_id($form_state);
} }
} }
/**
* Get the first step ID.
*
* @param array $form_state
* The Drupal form state.
*
* @return string
* The 'id' of the very first step.
*/
function islandora_ingest_form_get_first_step_id(array &$form_state) {
$steps = islandora_ingest_form_get_steps($form_state);
$keys = array_keys($steps);
return array_shift($keys);
}
/**
* Get the last step ID.
*
* @param array $form_state
* The Drupal form state.
*
* @return string
* The 'id' of the very last step.
*/
function islandora_ingest_form_get_last_step_id(array &$form_state) {
$steps = islandora_ingest_form_get_steps($form_state);
$keys = array_keys($steps);
return array_pop($keys);
}
/** /**
* Prepares a new object based on the given configuration. * Prepares a new object based on the given configuration.
* *
@ -113,13 +148,12 @@ function islandora_ingest_form_prepare_new_object(array $configuration) {
/** /**
* Gets the given/current step. * Gets the given/current step.
* *
* The current step is returned if no step ID is given. If the current step is * If the current step is not defined it's assumed that all steps have executed.
* not defined it's assume to be the first step.
* *
* @param array $form_state * @param array $form_state
* The Drupal form state. * The Drupal form state.
* @param string $step_id * @param string $step_id
* The ID of the step. * The ID of the step. The current step is returned if no step ID is given.
* *
* @return array * @return array
* The given/current step if found, NULL otherwise. * The given/current step if found, NULL otherwise.
@ -133,10 +167,48 @@ function islandora_ingest_form_get_step(array &$form_state, $step_id = NULL) {
return NULL; return NULL;
} }
/**
* Gets the next step.
*
* If the current step is not defined it's assumed that all steps have executed.
*
* @param array $form_state
* The Drupal form state.
* @param string $step
* The step relative to the result, if not provided the current step is used.
*
* @return string
* The next step if found, NULL otherwise.
*/
function islandora_ingest_form_get_next_step(array &$form_state, array $step = NULL) {
$step = isset($step) ? $step : islandora_ingest_form_get_step($form_state);
$next_step_id = islandora_ingest_form_get_next_step_id($form_state, $step['id']);
return isset($next_step_id) ? islandora_ingest_form_get_step($form_state, $next_step_id) : NULL;
}
/**
* Gets the previous step.
*
* If the current step is not defined it's assumed that all steps have executed.
*
* @param array $form_state
* The Drupal form state.
* @param string $step
* The step relative to the result, if not provided the current step is used.
*
* @return string
* The next step if found, NULL otherwise.
*/
function islandora_ingest_form_get_previous_step(array &$form_state, array $step = NULL) {
$step = isset($step) ? $step : islandora_ingest_form_get_step($form_state);
$previous_step_id = islandora_ingest_form_get_previous_step_id($form_state, $step['id']);
return isset($previous_step_id) ? islandora_ingest_form_get_step($form_state, $previous_step_id) : NULL;
}
/** /**
* Gets the ID of the current step. * Gets the ID of the current step.
* *
* If a current step is not defined, its assumed to be the first step. * If the current step is not defined it's assumed that all steps have executed.
* *
* @param array $form_state * @param array $form_state
* The Drupal form state. * The Drupal form state.
@ -145,27 +217,25 @@ function islandora_ingest_form_get_step(array &$form_state, $step_id = NULL) {
* The step ID. * The step ID.
*/ */
function islandora_ingest_form_get_current_step_id(array &$form_state) { function islandora_ingest_form_get_current_step_id(array &$form_state) {
if (empty($form_state['islandora']['step_id'])) {
$steps = islandora_ingest_form_get_steps($form_state);
$keys = array_keys($steps);
return array_shift($keys);
}
return $form_state['islandora']['step_id']; return $form_state['islandora']['step_id'];
} }
/** /**
* Gets the ID of the next step. * Gets the ID of the next step.
* *
* If a current step is not defined, its assumed to be the first step. * If the current step is not defined it's assumed that all steps have executed.
* *
* @param array $form_state * @param array $form_state
* The Drupal form state. * The Drupal form state.
* @param string $step_id
* The ID of the step relative to the result, if not provided the current
* step_id is used.
* *
* @return string * @return string
* The next step ID if found, NULL otherwise. * The next step ID if found, NULL otherwise.
*/ */
function islandora_ingest_form_get_next_step_id(array &$form_state) { function islandora_ingest_form_get_next_step_id(array &$form_state, $step_id = NULL) {
$step_id = islandora_ingest_form_get_current_step_id($form_state); $step_id = isset($step_id) ? $step_id : islandora_ingest_form_get_current_step_id($form_state);
$step_ids = array_keys(islandora_ingest_form_get_steps($form_state)); $step_ids = array_keys(islandora_ingest_form_get_steps($form_state));
$index = array_search($step_id, $step_ids); $index = array_search($step_id, $step_ids);
$count = count($step_ids); $count = count($step_ids);
@ -178,16 +248,25 @@ function islandora_ingest_form_get_next_step_id(array &$form_state) {
/** /**
* Gets the ID of the previous step. * Gets the ID of the previous step.
* *
* If a current step is not defined, its assumed to be the first step. * If the current step is not defined it's assumed that all steps have executed.
* In such cases the last step will be returned.
* *
* @param array $form_state * @param array $form_state
* The Drupal form state. * The Drupal form state.
* @param string $step_id
* The ID of the step relative to the result, if not provided the current
* step_id is used.
* *
* @return string * @return string
* The previous step ID if found, NULL otherwise. * The previous step ID if found, NULL otherwise.
*/ */
function islandora_ingest_form_get_previous_step_id(array &$form_state) { function islandora_ingest_form_get_previous_step_id(array &$form_state, $step_id = NULL) {
$step_id = islandora_ingest_form_get_current_step_id($form_state); $step_id = isset($step_id) ? $step_id : islandora_ingest_form_get_current_step_id($form_state);
// If the current step is not defined it's assumed that all steps have
// executed. So return the very last step.
if ($step_id == NULL) {
return islandora_ingest_form_get_last_step_id($form_state);
}
$step_ids = array_keys(islandora_ingest_form_get_steps($form_state)); $step_ids = array_keys(islandora_ingest_form_get_steps($form_state));
$index = array_search($step_id, $step_ids); $index = array_search($step_id, $step_ids);
if ($index !== FALSE && --$index >= 0) { if ($index !== FALSE && --$index >= 0) {
@ -207,11 +286,9 @@ function islandora_ingest_form_increment_step(array &$form_state) {
// of the current step could have added/removed a step. // of the current step could have added/removed a step.
drupal_static_reset('islandora_ingest_form_get_steps'); drupal_static_reset('islandora_ingest_form_get_steps');
$next_step_id = islandora_ingest_form_get_next_step_id($form_state); $next_step_id = islandora_ingest_form_get_next_step_id($form_state);
if (isset($next_step_id)) {
islandora_ingest_form_stash_info($form_state); islandora_ingest_form_stash_info($form_state);
$form_state['islandora']['step_id'] = $next_step_id; $form_state['islandora']['step_id'] = $next_step_id;
islandora_ingest_form_grab_info($form_state); islandora_ingest_form_grab_info($form_state);
}
} }
/** /**
@ -222,6 +299,7 @@ function islandora_ingest_form_increment_step(array &$form_state) {
*/ */
function islandora_ingest_form_decrement_step(array &$form_state) { function islandora_ingest_form_decrement_step(array &$form_state) {
$previous_step_id = islandora_ingest_form_get_previous_step_id($form_state); $previous_step_id = islandora_ingest_form_get_previous_step_id($form_state);
// Don't decrement passed the first step.
if (isset($previous_step_id)) { if (isset($previous_step_id)) {
islandora_ingest_form_stash_info($form_state); islandora_ingest_form_stash_info($form_state);
$form_state['islandora']['step_id'] = $previous_step_id; $form_state['islandora']['step_id'] = $previous_step_id;
@ -233,16 +311,18 @@ function islandora_ingest_form_decrement_step(array &$form_state) {
* Build a list of steps given only configuration. * Build a list of steps given only configuration.
* *
* XXX: This is used to give an indication of whether there are any steps for a * XXX: This is used to give an indication of whether there are any steps for a
* given list of content models. * given configuration.
* *
* @param array $configuration * @param array $configuration
* The list of key/value pairs of configuration. * The list of key/value pairs of configuration.
*/ */
function islandora_ingest_get_approximate_steps(array $configuration) { function islandora_ingest_get_approximate_steps(array $configuration) {
try { try {
// @todo, we need to expand the configuration before we can validate it?
// I think this need some thinking.
islandora_ingest_form_validate_configuration($configuration); islandora_ingest_form_validate_configuration($configuration);
} }
catch(InvalidArgumentException $e) { catch (InvalidArgumentException $e) {
// Don't log or display exception. // Don't log or display exception.
return array(); return array();
} }
@ -270,16 +350,19 @@ function islandora_ingest_get_approximate_steps(array $configuration) {
* @return array * @return array
* The form definition of the current step. * The form definition of the current step.
*/ */
function islandora_ingest_form_execute_step(array $form, array &$form_state) { function islandora_ingest_form_execute_step(array $form, array &$form_state, $step_id = NULL) {
// Load any required files for the current step. // Load any required files for the current step.
islandora_ingest_form_load_include($form_state); islandora_ingest_form_load_include($form_state);
$step = islandora_ingest_form_get_step($form_state); $step = isset($step_id) ? islandora_ingest_form_get_step($form_state) : islandora_ingest_form_get_step($form_state, $step_id);
switch ($step['type']) { switch ($step['type']) {
case 'callback':
// Execute all the consecutive callbacks, and move then attempt to process
// the next step.
islandora_ingest_form_execute_consecutive_callback_steps($form, $form_state, $step);
return islandora_ingest_form_execute_step($form, $form_state);
case 'form': case 'form':
$args = array($form, &$form_state); return islandora_ingest_form_execute_form_step($form, $form_state, $step);
$args = isset($step['args']) ? array_merge($args, $step['args']) : $args;
$form = call_user_func_array($step['form_id'], $args);
return islandora_ingest_form_stepify($form, $form_state, $step);
case 'batch': case 'batch':
// @todo Implement if possible. // @todo Implement if possible.
@ -288,6 +371,94 @@ function islandora_ingest_form_execute_step(array $form, array &$form_state) {
return array(); return array();
} }
/**
* Execute the given 'form' step.
*
* Assumes the given step is a 'form' step.
*
* @param array $form
* The Drupal form.
* @param array $form_state
* The Drupal form state.
*
* @return array
* The form definition of the given step.
*/
function islandora_ingest_form_execute_form_step(array $form, array &$form_state, array $step) {
$args = array($form, &$form_state);
$args = isset($step['args']) ? array_merge($args, $step['args']) : $args;
$form = call_user_func_array($step['form_id'], $args);
return islandora_ingest_form_stepify($form, $form_state, $step);
}
/**
* Execute the given 'callback' step and any consecutive 'callback' steps.
*
* Assumes the given step is a 'callback' step.
*
* @param array $form
* The Drupal form.
* @param array $form_state
* The Drupal form state.
*/
function islandora_ingest_form_execute_consecutive_callback_steps(array $form, array &$form_state, array $step) {
do {
islandora_ingest_form_execute_callback_step($form, $form_state, $step);
islandora_ingest_form_increment_step($form_state);
$step = islandora_ingest_form_get_step($form_state);
} while (isset($step) && $step['type'] == 'callback');
}
/**
* Execute the given 'callback' step.
*
* Assumes the given step is a 'callback' step.
*
* @param array $form
* The Drupal form.
* @param array $form_state
* The Drupal form state.
*/
function islandora_ingest_form_execute_callback_step(array $form, array &$form_state, array $step) {
$args = array(&$form_state);
$args = isset($step['do_function']['args']) ? array_merge($args, $step['do_function']['args']) : $args;
call_user_func_array($step['do_function']['function'], $args);
}
/**
* Undo the given 'callback' step and any consecutive 'callback' steps.
*
* Assumes the given $step is a 'callback' step.
*
* @param array $form
* The Drupal form.
* @param array $form_state
* The Drupal form state.
*/
function islandora_ingest_form_undo_consecutive_callback_steps(array $form, array &$form_state, array $step) {
do {
islandora_ingest_form_undo_callback_step($form, $form_state, $step);
islandora_ingest_form_decrement_step($form_state);
$step = islandora_ingest_form_get_step($form_state);
} while (isset($step) && $step['type'] == 'callback');
}
/**
* Undo the given 'callback' step.
*
* Assumes the given $step is a 'callback' step.
*
* @param array $form
* The Drupal form.
* @param array $form_state
* The Drupal form state.
*/
function islandora_ingest_form_undo_callback_step(array $form, array &$form_state, array $step) {
$args = array(&$form_state);
$args = isset($step['undo_function']['args']) ? array_merge($args, $step['undo_function']['args']) : $args;
call_user_func_array($step['undo_function']['function'], $args);
}
/** /**
* Append Prev/Next buttons submit/validation handlers etc. * Append Prev/Next buttons submit/validation handlers etc.
* *
@ -297,22 +468,20 @@ function islandora_ingest_form_execute_step(array $form, array &$form_state) {
* The Drupal form state. * The Drupal form state.
* *
* @return array * @return array
* The stepified drupal form definition for the given step. * The stepified Drupal form definition for the given step.
*/ */
function islandora_ingest_form_stepify(array $form, array &$form_state, $step) { function islandora_ingest_form_stepify(array $form, array &$form_state, $step) {
$first_step = islandora_ingest_form_on_first_step($form_state); $first_form_step = islandora_ingest_form_on_first_form_step($form_state);
$last_step = islandora_ingest_form_on_last_step($form_state); $last_form_step = islandora_ingest_form_on_last_form_step($form_state);
$form['prev'] = $first_step ? NULL : islandora_ingest_form_previous_button($form_state); $form['prev'] = $first_form_step ? NULL : islandora_ingest_form_previous_button($form_state);
$form['next'] = $last_step ? islandora_ingest_form_ingest_button($form_state) : islandora_ingest_form_next_button($form_state); $form['next'] = $last_form_step ? islandora_ingest_form_ingest_button($form_state) : islandora_ingest_form_next_button($form_state);
// Allow for a hook_form_FORM_ID_alter(). // Allow for a hook_form_FORM_ID_alter().
drupal_alter(array('form_' . $step['form_id'], 'form'), $form, $form_state, $step['form_id']); drupal_alter(array('form_' . $step['form_id'], 'form'), $form, $form_state, $step['form_id']);
return $form; return $form;
} }
/** /**
* Checks if we are on the first step. * Checks if we are on the first form step.
* *
* @param array $form_state * @param array $form_state
* The Drupal form state. * The Drupal form state.
@ -320,14 +489,12 @@ function islandora_ingest_form_stepify(array $form, array &$form_state, $step) {
* @return bool * @return bool
* TRUE if we are currently on the first step, FALSE otherwise. * TRUE if we are currently on the first step, FALSE otherwise.
*/ */
function islandora_ingest_form_on_first_step(array &$form_state) { function islandora_ingest_form_on_first_form_step(array &$form_state) {
$step_id = islandora_ingest_form_get_current_step_id($form_state); return !islandora_ingest_form_get_previous_form_step($form_state);
$step_ids = array_keys(islandora_ingest_form_get_steps($form_state));
return array_search($step_id, $step_ids) == 0;
} }
/** /**
* Checks if we are on the last step. * Checks if we are on the last form step.
* *
* @param array $form_state * @param array $form_state
* The Drupal form state. * The Drupal form state.
@ -335,11 +502,42 @@ function islandora_ingest_form_on_first_step(array &$form_state) {
* @return bool * @return bool
* TRUE if we are currently on the last step, FALSE otherwise. * TRUE if we are currently on the last step, FALSE otherwise.
*/ */
function islandora_ingest_form_on_last_step(array &$form_state) { function islandora_ingest_form_on_last_form_step(array &$form_state) {
$step_id = islandora_ingest_form_get_current_step_id($form_state); return !islandora_ingest_form_get_next_form_step($form_state);
$step_ids = array_keys(islandora_ingest_form_get_steps($form_state)); }
$count = count($step_ids);
return array_search($step_id, $step_ids) == --$count; /**
* Get the previous form step relative to the current step.
*
* @param array $form_state
* The Drupal form state.
*
* @return array
* The previous form step if one exists, NULL otherwise.
*/
function islandora_ingest_form_get_previous_form_step(array &$form_state) {
$step = NULL;
do {
$step = islandora_ingest_form_get_previous_step($form_state, $step);
} while (isset($step) && $step['type'] != 'form');
return $step;
}
/**
* Get the next form step relative to the current step.
*
* @param array $form_state
* The Drupal form state.
*
* @return array
* The next form step if one exists, NULL otherwise.
*/
function islandora_ingest_form_get_next_form_step(array &$form_state) {
$step = NULL;
do {
$step = islandora_ingest_form_get_next_step($form_state, $step);
} while (isset($step) && $step['type'] != 'form');
return $step;
} }
/** /**
@ -354,13 +552,12 @@ function islandora_ingest_form_on_last_step(array &$form_state) {
* The previous button for the ingest form. * The previous button for the ingest form.
*/ */
function islandora_ingest_form_previous_button(array &$form_state) { function islandora_ingest_form_previous_button(array &$form_state) {
// Before we move back to the previous step we should tell the previous step // Before we move back to the previous step we should tell the previous steps
// to undo whatever its submit handler did. // to undo whatever its submit handler did.
$prev_step_id = islandora_ingest_form_get_previous_step_id($form_state); $prev_form_step = islandora_ingest_form_get_previous_form_step($form_state);
$prev_step = islandora_ingest_form_get_step($form_state, $prev_step_id); $form_id = $prev_form_step['form_id'];
$form_id = $prev_step['form_id'];
$submit_callback = $form_id . '_undo_submit'; $submit_callback = $form_id . '_undo_submit';
$submit = function_exists($submit_callback) ? array($submit_callback, 'islandora_ingest_form_previous_submit') : array('islandora_ingest_form_undo_submit'); $submit = function_exists($submit_callback) ? array($submit_callback, 'islandora_ingest_form_previous_submit') : array('islandora_ingest_form_previous_submit');
return array( return array(
'#type' => 'submit', '#type' => 'submit',
'#value' => t('Previous'), '#value' => t('Previous'),
@ -391,6 +588,11 @@ function islandora_ingest_form_previous_button(array &$form_state) {
*/ */
function islandora_ingest_form_previous_submit(array $form, array &$form_state) { function islandora_ingest_form_previous_submit(array $form, array &$form_state) {
islandora_ingest_form_decrement_step($form_state); islandora_ingest_form_decrement_step($form_state);
$step = islandora_ingest_form_get_step($form_state);
// Undo all callbacks that occured after the previous step.
if ($step['type'] == 'callback') {
islandora_ingest_form_undo_consecutive_callback_steps($form, $form_state, $step);
}
$form_state['rebuild'] = TRUE; $form_state['rebuild'] = TRUE;
} }
@ -446,8 +648,10 @@ function islandora_ingest_form_next_submit(array $form, array &$form_state) {
*/ */
function islandora_ingest_form_stash_info(array &$form_state) { function islandora_ingest_form_stash_info(array &$form_state) {
$storage = &islandora_ingest_form_get_step_storage($form_state); $storage = &islandora_ingest_form_get_step_storage($form_state);
if ($storage) {
$storage['values'] = $form_state['values']; $storage['values'] = $form_state['values'];
unset($form_state['values']); unset($form_state['values']);
}
} }
/** /**
@ -493,12 +697,17 @@ function islandora_ingest_form_ingest_button(array &$form_state) {
* *
* Attempts to ingest every object built by the previous steps. * Attempts to ingest every object built by the previous steps.
* *
* @param array $form
* The Drupal form.
* @param array $form_state * @param array $form_state
* The Drupal form state. * The Drupal form state.
*/ */
function islandora_ingest_form_submit(array $form, array &$form_state) { function islandora_ingest_form_submit(array $form, array &$form_state) {
// Execute any remaining callbacks.
islandora_ingest_form_increment_step($form_state);
$step = islandora_ingest_form_get_step($form_state);
if (isset($step) && $step['type'] == 'callback') {
islandora_ingest_form_execute_consecutive_callback_steps($form, $form_state, $step);
}
// Ingest the objects.
foreach ($form_state['islandora']['objects'] as $object) { foreach ($form_state['islandora']['objects'] as $object) {
try { try {
islandora_add_object($object); islandora_add_object($object);
@ -507,7 +716,7 @@ function islandora_ingest_form_submit(array $form, array &$form_state) {
catch (Exception $e) { catch (Exception $e) {
// If post hooks throws it may already exist at this point but may be // If post hooks throws it may already exist at this point but may be
// invalid, so don't say failed. // invalid, so don't say failed.
watchdog('islandora', $e->getMessage(), NULL, WATCHDOG_ERROR); watchdog('islandora', 'Exception Message: @exception.', array('@exception' => $e->getMessage()), 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'); drupal_set_message(t('A problem occured while ingesting "@label" (ID: @pid), please notifiy the administrator.', array('@label' => $object->label, '@pid' => $object->id)), 'error');
} }
} }
@ -567,7 +776,8 @@ function &islandora_ingest_form_get_step_storage(array &$form_state, $step_id =
} }
return $form_state['islandora']['step_storage'][$step_id]; return $form_state['islandora']['step_storage'][$step_id];
} }
return NULL; $undefined_step_storage = array();
return $undefined_step_storage;
} }
/** /**
@ -625,6 +835,8 @@ function islandora_ingest_form_get_steps(array &$form_state) {
$shared_storage = &islandora_ingest_form_get_shared_storage($form_state); $shared_storage = &islandora_ingest_form_get_shared_storage($form_state);
foreach (islandora_build_hook_list(ISLANDORA_INGEST_STEP_HOOK, $shared_storage['models']) as $hook) { foreach (islandora_build_hook_list(ISLANDORA_INGEST_STEP_HOOK, $shared_storage['models']) as $hook) {
// Required for pass by reference. // Required for pass by reference.
// @todo Change this around so that it isn't passed by reference, there
// Is an alter below that can handle that requirement.
foreach (module_implements($hook) as $module) { foreach (module_implements($hook) as $module) {
$function = $module . '_' . $hook; $function = $module . '_' . $hook;
$module_steps = (array) $function($form_state); $module_steps = (array) $function($form_state);
@ -635,6 +847,10 @@ function islandora_ingest_form_get_steps(array &$form_state) {
foreach (islandora_build_hook_list(ISLANDORA_INGEST_STEP_HOOK, $shared_storage['models']) as $hook) { foreach (islandora_build_hook_list(ISLANDORA_INGEST_STEP_HOOK, $shared_storage['models']) as $hook) {
drupal_alter($hook, $steps, $form_state); drupal_alter($hook, $steps, $form_state);
} }
// Add any defaults.
foreach ($steps as $key => &$step) {
$step['id'] = $key;
}
uasort($steps, 'drupal_sort_weight'); uasort($steps, 'drupal_sort_weight');
return $steps; return $steps;
} }

103
includes/solution_packs.inc

@ -187,30 +187,48 @@ function islandora_solution_pack_form_submit(array $form, array &$form_state) {
*/ */
function islandora_solution_pack_batch_operation_reingest_object(NewFedoraObject $object, array &$context) { function islandora_solution_pack_batch_operation_reingest_object(NewFedoraObject $object, array &$context) {
$existing_object = islandora_object_load($object->id); $existing_object = islandora_object_load($object->id);
$deleted = FALSE;
if ($existing_object) { if ($existing_object) {
$deleted = islandora_delete_object($existing_object); $deleted = islandora_delete_object($existing_object);
if (!$deleted) { if (!$deleted) {
$object_link = l($existing_object->label, "islandora/object/{$existing_object->id}"); $object_link = l($existing_object->label, "islandora/object/{$existing_object->id}");
drupal_set_message(t('Failed to purge existing object !object_link.', array( drupal_set_message(filter_xss(t('Failed to purge existing object !object_link.', array(
'!object_link' => $object_link, '!object_link' => $object_link,
)), 'error'); ))), 'error');
// Failed to purge don't attempt to ingest. // Failed to purge don't attempt to ingest.
return; return;
} }
} }
// Object was deleted or did not exist. // Object was deleted or did not exist.
$pid = $object->id; $pid = $object->id;
$label = $object->label; $label = $object->label;
$action = $deleted ? 'reinstalled' : 'installed';
$object_link = l($label, "islandora/object/{$pid}"); $object_link = l($label, "islandora/object/{$pid}");
$object = islandora_add_object($object); $object = islandora_add_object($object);
$msg = $object ? "Successfully $action !object_link." : "Failed to $action @label identified by @pid."; $params = array(
$status = $object ? 'status' : 'error';
drupal_set_message(t($msg, array(
'@pid' => $pid, '@pid' => $pid,
'@label' => $label, '@label' => $label,
'!object_link' => $object_link, '!object_link' => $object_link,
)), $status); );
$msg = '';
if ($object) {
if ($deleted) {
$msg = t('Successfully reinstalled !object_link.', $params);
}
else {
$msg = t('Successfully installed !object_link.', $params);
}
}
elseif ($deleted) {
$msg = t('Failed to reinstall @label, identified by @pid.', $params);
}
else {
$msg = t('Failed to install @label, identified by @pid.', $params);
}
$status = $object ? 'status' : 'error';
drupal_set_message(filter_xss($msg), $status);
} }
/** /**
@ -237,33 +255,37 @@ function islandora_install_solution_pack($module, $op = 'install') {
islandora_uninstall_solution_pack($module); islandora_uninstall_solution_pack($module);
return; return;
} }
$t = get_t();
// Some general replacements.
$admin_link = l($t('Solution Pack admin'), 'admin/islandora/solution_packs');
$config_link = l($t('Islandora configuration'), 'admin/islandora/configure');
$t_params = array(
'@module' => $module,
'!config_link' => $config_link,
'!admin_link' => $admin_link,
);
module_load_include('module', 'islandora', 'islandora'); module_load_include('module', 'islandora', 'islandora');
module_load_include('inc', 'islandora', 'includes/utilities'); module_load_include('inc', 'islandora', 'includes/utilities');
module_load_include('module', $module, $module); module_load_include('module', $module, $module);
$info_file = drupal_get_path('module', $module) . "/{$module}.info"; $info_file = drupal_get_path('module', $module) . "/{$module}.info";
$info_array = drupal_parse_info_file($info_file); $info_array = drupal_parse_info_file($info_file);
$module_name = $info_array['name']; $module_name = $info_array['name'];
$admin_link = l(t('Solution Pack admin'), 'admin/islandora/solution_packs');
$config_link = l(t('Islandora configuration'), 'admin/islandora/configure');
if (!islandora_describe_repository()) { if (!islandora_describe_repository()) {
$msg = '@module: Did not install any objects. Could not connect to the '; $msg = $t('@module: Did not install any objects. Could not connect to the repository. Please check the settings on the !config_link page and install the required objects manually on the !admin_link page.', $t_params);
$msg .= 'repository. Please check the settings on the !config_link page '; drupal_set_message(filter_xss($msg), 'error');
$msg .= 'and install the required objects manually on the !admin_link page.';
drupal_set_message(st($msg, array(
'@module' => $module_name,
'!config_link' => $config_link,
'@admin_link' => $admin_link,
)), 'error');
return; return;
} }
$connection = islandora_get_tuque_connection(); $connection = islandora_get_tuque_connection();
$required_objects = module_invoke($module, 'islandora_required_objects', $connection); $required_objects = module_invoke($module, 'islandora_required_objects', $connection);
$objects = $required_objects[$module]['objects']; $objects = $required_objects[$module]['objects'];
$status_messages = array( $status_messages = array(
'up_to_date' => 'The object already exists and is up-to-date', 'up_to_date' => $t('The object already exists and is up-to-date.', $t_params),
'missing_datastream' => 'The object already exists but is missing a datastream. Please reinstall the object on the !admin_link page', 'missing_datastream' => $t('The object already exists but is missing a datastream. Please reinstall the object on the !admin_link page.', $t_params),
'out_of_date' => 'The object already exists but is out-of-date. Please update the object on the !admin_link page', 'out_of_date' => $t('The object already exists but is out-of-date. Please update the object on the !admin_link page.', $t_params),
'modified_datastream' => 'The object already exists but datastreams are modified. Please reinstall the object on the !admin_link page', 'modified_datastream' => $t('The object already exists but datastreams are modified. Please reinstall the object on the !admin_link page.', $t_params),
); );
foreach ($objects as $object) { foreach ($objects as $object) {
$query = $connection->api->a->findObjects('query', 'pid=' . $object->id); $query = $connection->api->a->findObjects('query', 'pid=' . $object->id);
@ -272,26 +294,25 @@ function islandora_install_solution_pack($module, $op = 'install') {
$object_link = l($label, "islandora/object/{$object->id}"); $object_link = l($label, "islandora/object/{$object->id}");
if ($already_exists) { if ($already_exists) {
$object_status = islandora_check_object_status($object); $object_status = islandora_check_object_status($object);
$status_msg = $status_messages[$object_status['status']]; $here_params = array(
drupal_set_message(st("@module: Did not install !object_link. $status_msg.", array( '!summary' => $t("@module: Did not install !object_link.", array(
'@module' => $module_name,
'!object_link' => $object_link, '!object_link' => $object_link,
'!admin_link' => $admin_link, ) + $t_params),
)), 'warning'); '!description' => $status_messages[$object_status['status']],
);
drupal_set_message(filter_xss(format_string('!summary !description', $here_params)), 'warning');
} }
else { else {
$object = islandora_add_object($object); $object = islandora_add_object($object);
if ($object) { if ($object) {
drupal_set_message(t('@module: Successfully installed. !object_link.', array( drupal_set_message(filter_xss($t('@module: Successfully installed. !object_link.', array(
'@module' => $module_name,
'!object_link' => $object_link, '!object_link' => $object_link,
)), 'status'); ) + $t_params)), 'status');
} }
else { else {
drupal_set_message(t('@module: Failed to install. @label.', array( drupal_set_message($t('@module: Failed to install. @label.', array(
'@module' => $module_name,
'@label' => $label, '@label' => $label,
)), 'warning'); ) + $t_params), 'warning');
} }
} }
} }
@ -307,21 +328,20 @@ function islandora_install_solution_pack($module, $op = 'install') {
* directly for each solution pack. * directly for each solution pack.
*/ */
function islandora_uninstall_solution_pack($module) { function islandora_uninstall_solution_pack($module) {
$t = get_t();
module_load_include('module', 'islandora', 'islandora'); module_load_include('module', 'islandora', 'islandora');
module_load_include('inc', 'islandora', 'includes/utilities'); module_load_include('inc', 'islandora', 'includes/utilities');
module_load_include('module', $module, $module); module_load_include('module', $module, $module);
$config_link = l(t('Islandora configuration'), 'admin/islandora/configure'); $config_link = l($t('Islandora configuration'), 'admin/islandora/configure');
$info_file = drupal_get_path('module', $module) . "/{$module}.info"; $info_file = drupal_get_path('module', $module) . "/{$module}.info";
$info_array = drupal_parse_info_file($info_file); $info_array = drupal_parse_info_file($info_file);
$module_name = $info_array['name']; $module_name = $info_array['name'];
if (!islandora_describe_repository()) { if (!islandora_describe_repository()) {
$msg = '@module: Did not uninstall any objects. Could not connect to the '; $msg = $t('@module: Did not uninstall any objects. Could not connect to the repository. Please check the settings on the !config_link page and uninstall the required objects manually if necessary.', array(
$msg .= 'repository. Please check the settings on the !config_link page ';
$msg .= 'and uninstall the required objects manually if necessary.';
drupal_set_message(st($msg, array(
'@module' => $module_name, '@module' => $module_name,
'!config_link' => $config_link, '!config_link' => $config_link,
)), 'error'); ));
drupal_set_message(filter_xss($msg), 'error');
return; return;
} }
$connection = islandora_get_tuque_connection(); $connection = islandora_get_tuque_connection();
@ -334,12 +354,13 @@ function islandora_uninstall_solution_pack($module) {
}; };
$existing_objects = array_filter($objects, $filter); $existing_objects = array_filter($objects, $filter);
foreach ($existing_objects as $object) { foreach ($existing_objects as $object) {
$msg = '@module: Did not remove !object_link. It may be used by other sites.';
$object_link = l($object->label, "islandora/object/{$object->id}"); $object_link = l($object->label, "islandora/object/{$object->id}");
drupal_set_message(st($msg, array( $msg = $t('@module: Did not remove !object_link. It may be used by other sites.', array(
'!object_link' => $object_link, '!object_link' => $object_link,
'@module' => $module_name, '@module' => $module_name,
)), 'warning'); ));
drupal_set_message(filter_xss($msg), 'warning');
} }
} }

8
includes/tuque_wrapper.inc

@ -205,7 +205,7 @@ class IslandoraFedoraApiM extends FedoraApiM {
} }
return $ret; return $ret;
} }
catch(Exception $e) { catch (Exception $e) {
watchdog('islandora', 'Failed to modify datastream @dsid from @pid</br>code: @code<br/>message: @msg', array( watchdog('islandora', 'Failed to modify datastream @dsid from @pid</br>code: @code<br/>message: @msg', array(
'@pid' => $pid, '@pid' => $pid,
'@dsid' => $dsid, '@dsid' => $dsid,
@ -239,7 +239,7 @@ class IslandoraFedoraApiM extends FedoraApiM {
} }
return $ret; return $ret;
} }
catch(Exception $e) { catch (Exception $e) {
watchdog('islandora', 'Failed to modify object: @pid</br>code: @code<br/>message: @msg', array( watchdog('islandora', 'Failed to modify object: @pid</br>code: @code<br/>message: @msg', array(
'@pid' => $pid, '@pid' => $pid,
'@code' => $e->getCode(), '@code' => $e->getCode(),
@ -281,7 +281,7 @@ class IslandoraFedoraApiM extends FedoraApiM {
return $ret; return $ret;
} }
} }
catch(Exception $e) { catch (Exception $e) {
watchdog('islandora', 'Failed to purge datastream @dsid from @pid</br>code: @code<br/>message: @msg', array( watchdog('islandora', 'Failed to purge datastream @dsid from @pid</br>code: @code<br/>message: @msg', array(
'@pid' => $pid, '@pid' => $pid,
'@dsid' => $dsid, '@dsid' => $dsid,
@ -325,7 +325,7 @@ class IslandoraFedoraApiM extends FedoraApiM {
return $ret; return $ret;
} }
} }
catch(Exception $e) { catch (Exception $e) {
watchdog('islandora', 'Failed to purge object @pid</br>code: @code<br/>message: @msg', array( watchdog('islandora', 'Failed to purge object @pid</br>code: @code<br/>message: @msg', array(
'@pid' => $pid, '@pid' => $pid,
'@code' => $e->getCode(), '@code' => $e->getCode(),

92
includes/utilities.inc

@ -380,18 +380,13 @@ function islandora_get_datastreams_requirements_from_models(array $models) {
* determine what datastreams are required. * determine what datastreams are required.
* *
* @return array * @return array
* The DS-COMPOSITE-MODEL defined datastreams that are required for the given * An associative array mapping datastream IDs to associative arrays
* object. * containing the values parsed from the DS-COMPOSITE-MODEL on the given
* * object--of the form:
* @code * - DSID: A datastream ID being described.
* array( * - "id": A string containing ID of the datastream.
* 'DC' => array( * - "mime": A array containing MIME-types the stream may have.
* 'id' => 'DC', * - "optional": A boolean indicating if the given stream is optional.
* 'mime' => 'text/xml',
* 'optional' => FALSE,
* )
* )
* @endcode
*/ */
function islandora_get_datastreams_requirements_from_content_model(FedoraObject $object) { function islandora_get_datastreams_requirements_from_content_model(FedoraObject $object) {
if (empty($object[DS_COMP_STREAM])) { if (empty($object[DS_COMP_STREAM])) {
@ -465,20 +460,43 @@ function islandora_prepare_new_object($namespace = NULL, $label = NULL, $datastr
if (isset($ds['control_group']) && in_array($ds['control_group'], $groups)) { if (isset($ds['control_group']) && in_array($ds['control_group'], $groups)) {
$control_group = $ds['control_group']; $control_group = $ds['control_group'];
} }
$ds_uri = FALSE;
$as_file = FALSE;
if (file_valid_uri($ds['datastream_file'])) { if (file_valid_uri($ds['datastream_file'])) {
// A local file with as a Drupal file/stream wrapper URI.
$datastream_file = $ds['datastream_file'];
$as_file = TRUE;
}
elseif (is_readable($ds['datastream_file'])) {
// A local file as a filesystem path.
$datastream_file = drupal_realpath($ds['datastream_file']);
$as_file = TRUE;
}
else {
$scheme = parse_url($ds['datastream_file'], PHP_URL_SCHEME);
if (in_array($scheme, stream_get_wrappers())) {
// A URI which gets handled by one of the PHP-native stream wrappers.
$datastream_file = $ds['datastream_file']; $datastream_file = $ds['datastream_file'];
$ds_uri = TRUE; $as_file = TRUE;
} }
else { else {
// Schema does not match available php stream wrapper. Attempt to
// set datastream_file by url for the given scheme. Https (SSL) can
// cause this to fail, and trigger an output log in watchdog.
$datastream_file = url($ds['datastream_file'], array('absolute' => TRUE)); $datastream_file = url($ds['datastream_file'], array('absolute' => TRUE));
watchdog('islandora',
'Attempting to ingest %file in islandora_prepare_new_object(), but it does not appear to be readable. We will pass the path through url(), and pass along as such.',
array('%file' => $datastream_file),
WATCHDOG_WARNING);
} }
}
$datastream = $object->constructDatastream($dsid, $control_group); $datastream = $object->constructDatastream($dsid, $control_group);
$datastream->label = $label; $datastream->label = $label;
$datastream->mimetype = $mimetype; $datastream->mimetype = $mimetype;
switch ($control_group) { switch ($control_group) {
case 'M': case 'M':
if ($ds_uri) { if ($as_file) {
$datastream->setContentFromFile($datastream_file); $datastream->setContentFromFile($datastream_file);
} }
else { else {
@ -490,8 +508,10 @@ function islandora_prepare_new_object($namespace = NULL, $label = NULL, $datastr
$datastream->setContentFromString(file_get_contents($datastream_file)); $datastream->setContentFromString(file_get_contents($datastream_file));
break; break;
} }
$object->ingestDatastream($datastream); $object->ingestDatastream($datastream);
} }
return $object; return $object;
} }
@ -506,7 +526,8 @@ function islandora_display_repository_inaccessible_message() {
$link = l($text, 'admin/islandora/configure', array('attributes' => array('title' => $text))); $link = l($text, 'admin/islandora/configure', array('attributes' => array('title' => $text)));
$message = t('Could not connect to the repository. Please check the settings on the !link page.', $message = t('Could not connect to the repository. Please check the settings on the !link page.',
array('!link' => $link)); array('!link' => $link));
drupal_set_message($message, 'error', FALSE); drupal_set_message(check_plain($message), 'error', FALSE);
} }
/** /**
@ -595,33 +616,24 @@ function islandora_system_settings_form_default_value($name, $default_value, arr
/** /**
* Returns basic information about DS-COMPOSITE-MODEL. * Returns basic information about DS-COMPOSITE-MODEL.
* *
* @deprecated
* The pre-existing--and more flexible--
* islandora_get_datastreams_requirements_from_content_model() should be
* preferred, as it addresses the case where a stream can be allowed to have
* one of a set of mimetypes (this functions appears to only return the last
* declared mimetype for a given datastream).
*
* @param string $pid * @param string $pid
* PID of content model containing DS_COMP stream. * The PID of content model containing DS_COMP stream.
* *
* @return array * @return array
* array of values in the following form * An associative array mapping datastream IDs to an associative array
* * representing the parsed DS-COMPOSITE-MODEL of the form:
* [DC] => Array * - DSID: A string containing the datastream ID.
* ( * - "mimetype": A string containing the last mimetype declared for the
* [mimetype] => text/xml * given datastream ID.
* ) * - "optional": An optional boolean indicating that the given datastream
* * is optional.
* [MODS] => Array
* (
* [optional] => true
* [mimetype] => text/xml
* )
*
* [RELS-EXT] => Array
* (
* [mimetype] => application/rdf+xml
* )
*
* [RELS-INT] => Array
* (
* [optional] => true
* [mimetype] => application/rdf+xml
* )
*/ */
function islandora_get_comp_ds_mappings($pid) { function islandora_get_comp_ds_mappings($pid) {
$cm_object = islandora_object_load($pid); $cm_object = islandora_object_load($pid);

50
islandora.api.php

@ -45,11 +45,24 @@ function hook_CMODEL_PID_islandora_view_object($object) {
* @param FedoraObject $object * @param FedoraObject $object
* A Tuque FedoraObject being operated on. * A Tuque FedoraObject being operated on.
* @param array $rendered * @param array $rendered
* An arr of rendered views. * The array of rendered views.
*/ */
function hook_islandora_view_object_alter(&$object, &$rendered) { function hook_islandora_view_object_alter(&$object, &$rendered) {
} }
/**
* Alter display output if the object has the given model.
*
* @see hook_islandora_view_object_alter()
*
* @param FedoraObject $object
* A Tuque FedoraObject being operated on.
* @param array $rendered
* The array of rendered views.
*/
function hook_CMODEL_PID_islandora_view_object_alter(&$object, &$rendered) {
}
/** /**
* Generate an object's management display. * Generate an object's management display.
* *
@ -291,7 +304,7 @@ function hook_islandora_datastream_modified(FedoraObject $object, FedoraDatastre
} }
/** /**
* Notify modules that the given datastream was ingested. * Notify modules that the given datastream was modified.
* *
* @see hook_islandora_datastream_modified() * @see hook_islandora_datastream_modified()
*/ */
@ -373,15 +386,26 @@ function hook_islandora_undeletable_datastreams(array $models) {
* @return array * @return array
* An associative array of associative arrays which define each step in the * An associative array of associative arrays which define each step in the
* ingest process. Each step should consist of a unique name mapped to an * ingest process. Each step should consist of a unique name mapped to an
* array of properties (keys) including: * array of properties (keys) which take different paramaters based upon type:
* - type: The type of step. Currently, only "form" is implemented. * - type: Type of step. Only "form" and "callback" are implemented so far.
* - weight: The "weight" of this step--heavier(/"larger") values sink to the * Required "form" type specific parameters:
* end of the process while smaller(/"lighter") values are executed first.
* - form_id: The form building function to call to get the form structure * - form_id: The form building function to call to get the form structure
* for this step. * for this step.
* - args: An array of arguments to pass to the form building function. * - args: An array of arguments to pass to the form building function.
* And may optionally include both: * Required "callback" type specific parameters:
* - do_function: An associate array including:
* - 'function': The callback function to be called.
* - 'args': An array of arguments to pass to the callback function.
* - undo_function: An associate array including:
* - 'function': The callback function to be called to reverse the
* executed action in the ingest steps.
* - 'args': An array of arguments to pass to the callback function.
* Shared parameters between both types:
* - weight: The "weight" of this step--heavier(/"larger") values sink to the
* end of the process while smaller(/"lighter") values are executed first.
* Both types may optionally include:
* - module: A module from which we want to load an include. * - module: A module from which we want to load an include.
* "Form" type may optionally include:
* - file: A file to include (relative to the module's path, including the * - file: A file to include (relative to the module's path, including the
* file's extension). * file's extension).
*/ */
@ -393,6 +417,18 @@ function hook_islandora_ingest_steps(array $form_state) {
'form_id' => 'my_cool_form', 'form_id' => 'my_cool_form',
'args' => array('arg_one', 'numero deux'), 'args' => array('arg_one', 'numero deux'),
), ),
'my_cool_step_callback' => array(
'type' => 'callback',
'weight' => 2,
'do_function' => array(
'function' => 'my_cool_execute_function',
'args' => array('arg_one', 'numero deux'),
),
'undo_function' => array(
'function' => 'my_cool_undo_function',
'args' => array('arg_one', 'numero deux'),
),
),
); );
} }
/** /**

7
islandora.module

@ -676,7 +676,8 @@ function islandora_view_object(FedoraObject $object) {
$page_number = (empty($_GET['page'])) ? '1' : $_GET['page']; $page_number = (empty($_GET['page'])) ? '1' : $_GET['page'];
$page_size = (empty($_GET['pagesize'])) ? '10' : $_GET['pagesize']; $page_size = (empty($_GET['pagesize'])) ? '10' : $_GET['pagesize'];
$output = array(); $output = array();
foreach (islandora_build_hook_list(ISLANDORA_VIEW_HOOK, $object->models) as $hook) { $hooks = islandora_build_hook_list(ISLANDORA_VIEW_HOOK, $object->models);
foreach ($hooks as $hook) {
// @todo Remove page number and size from this hook, implementers of the // @todo Remove page number and size from this hook, implementers of the
// hook should use drupal page handling directly. // hook should use drupal page handling directly.
$temp = module_invoke_all($hook, $object, $page_number, $page_size); $temp = module_invoke_all($hook, $object, $page_number, $page_size);
@ -689,7 +690,7 @@ function islandora_view_object(FedoraObject $object) {
$output = islandora_default_islandora_view_object($object); $output = islandora_default_islandora_view_object($object);
} }
arsort($output); arsort($output);
drupal_alter(ISLANDORA_VIEW_HOOK, $object, $output); drupal_alter($hooks, $object, $output);
return implode('', $output); return implode('', $output);
} }
@ -965,7 +966,7 @@ function islandora_delete_object(FedoraObject &$object) {
$object = NULL; $object = NULL;
return TRUE; return TRUE;
} }
catch(Exception $e) { catch (Exception $e) {
// Exception message gets logged in Tuque Wrapper. // Exception message gets logged in Tuque Wrapper.
return FALSE; return FALSE;
} }

10
tests/hooks.test

@ -67,7 +67,7 @@ class IslandoraHooksTestCase extends IslandoraWebTestCase {
$object->label = "Don't Block"; $object->label = "Don't Block";
$this->repository->purgeObject($object->id); $this->repository->purgeObject($object->id);
} }
catch(Exception $e) { catch (Exception $e) {
// Meh... Either it didn't exist or the purge failed. // Meh... Either it didn't exist or the purge failed.
} }
} }
@ -95,7 +95,7 @@ class IslandoraHooksTestCase extends IslandoraWebTestCase {
$this->fail('Blocked ingest should throw an Exception.'); $this->fail('Blocked ingest should throw an Exception.');
$this->repository->purgeObject($object->id); $this->repository->purgeObject($object->id);
} }
catch(Exception $e) { catch (Exception $e) {
$this->pass('Ingest blocked and exception thrown.'); $this->pass('Ingest blocked and exception thrown.');
$this->assert($_SESSION['islandora_hooks']['alter'][ISLANDORA_OBJECT_INGESTED_HOOK], 'Called "hook_islandora_object_alter" when blocking ingesting via FedoraRepository::ingestObject.'); $this->assert($_SESSION['islandora_hooks']['alter'][ISLANDORA_OBJECT_INGESTED_HOOK], 'Called "hook_islandora_object_alter" when blocking ingesting via FedoraRepository::ingestObject.');
$this->assertFalse($_SESSION['islandora_hooks']['hook'][ISLANDORA_OBJECT_INGESTED_HOOK], 'Did not called ISLANDORA_OBJECT_INGESTED_HOOK when blocking ingesting via FedoraRepository::ingestObject.'); $this->assertFalse($_SESSION['islandora_hooks']['hook'][ISLANDORA_OBJECT_INGESTED_HOOK], 'Did not called ISLANDORA_OBJECT_INGESTED_HOOK when blocking ingesting via FedoraRepository::ingestObject.');
@ -115,7 +115,7 @@ class IslandoraHooksTestCase extends IslandoraWebTestCase {
$object->label = 'block'; $object->label = 'block';
$this->fail('Blocked modify should throw an Exception.'); $this->fail('Blocked modify should throw an Exception.');
} }
catch(Exception $e) { catch (Exception $e) {
$this->pass('Modify blocked and exception thrown.'); $this->pass('Modify blocked and exception thrown.');
$this->assertNotEqual($object->label, 'block', 'Modification did not stick.'); $this->assertNotEqual($object->label, 'block', 'Modification did not stick.');
$this->assert($_SESSION['islandora_hooks']['alter'][ISLANDORA_OBJECT_MODIFIED_HOOK], 'Called "hook_islandora_object_alter" when blocking modifying via set magic functions.'); $this->assert($_SESSION['islandora_hooks']['alter'][ISLANDORA_OBJECT_MODIFIED_HOOK], 'Called "hook_islandora_object_alter" when blocking modifying via set magic functions.');
@ -149,7 +149,7 @@ class IslandoraHooksTestCase extends IslandoraWebTestCase {
$this->repository->purgeObject($object->id); $this->repository->purgeObject($object->id);
$this->fail('Blocked modify should throw an Exception.'); $this->fail('Blocked modify should throw an Exception.');
} }
catch(Exception $e) { catch (Exception $e) {
$this->pass('Modify blocked and exception thrown.'); $this->pass('Modify blocked and exception thrown.');
$this->assert($_SESSION['islandora_hooks']['alter'][ISLANDORA_OBJECT_PURGED_HOOK], 'Called "hook_islandora_object_alter" when blocking purge via FedoraRepository::purgeObject.'); $this->assert($_SESSION['islandora_hooks']['alter'][ISLANDORA_OBJECT_PURGED_HOOK], 'Called "hook_islandora_object_alter" when blocking purge via FedoraRepository::purgeObject.');
$this->assertFalse($_SESSION['islandora_hooks']['hook'][ISLANDORA_OBJECT_PURGED_HOOK], 'Called ISLANDORA_OBJECT_PURGED_HOOK when blocking purge via FedoraRepository::purgeObject.'); $this->assertFalse($_SESSION['islandora_hooks']['hook'][ISLANDORA_OBJECT_PURGED_HOOK], 'Called ISLANDORA_OBJECT_PURGED_HOOK when blocking purge via FedoraRepository::purgeObject.');
@ -191,7 +191,7 @@ class IslandoraHooksTestCase extends IslandoraWebTestCase {
$ds->label = 'block'; $ds->label = 'block';
$this->fail('Blocked modify should throw an Exception.'); $this->fail('Blocked modify should throw an Exception.');
} }
catch(Exception $e) { catch (Exception $e) {
$this->pass('Modify blocked and exception thrown.'); $this->pass('Modify blocked and exception thrown.');
$this->assert($_SESSION['islandora_hooks']['alter'][ISLANDORA_DATASTREAM_MODIFIED_HOOK], 'Called "hook_islandora_datastream_alter" when blocking modifying via set magic functions.'); $this->assert($_SESSION['islandora_hooks']['alter'][ISLANDORA_DATASTREAM_MODIFIED_HOOK], 'Called "hook_islandora_datastream_alter" when blocking modifying via set magic functions.');
$this->assertFALSE($_SESSION['islandora_hooks']['hook'][ISLANDORA_DATASTREAM_MODIFIED_HOOK], 'Called ISLANDORA_DATASTREAM_MODIFIED_HOOK when blocking modifying via set magic functions.'); $this->assertFALSE($_SESSION['islandora_hooks']['hook'][ISLANDORA_DATASTREAM_MODIFIED_HOOK], 'Called ISLANDORA_DATASTREAM_MODIFIED_HOOK when blocking modifying via set magic functions.');

2
tests/islandora_manage_permissions.test

@ -90,7 +90,7 @@ class IslandoraPermissionsTestCase extends IslandoraWebTestCase {
*/ */
public function testAccessFunctions() { public function testAccessFunctions() {
$object = islandora_object_load(variable_get('islandora_repository_pid', 'islandora:root')); $object = islandora_object_load(variable_get('islandora_repository_pid', 'islandora:root'));
// Test islandora_user_access(); // Test islandora_user_access().
// Test no object/permissions. // Test no object/permissions.
$ret = islandora_user_access(NULL, array()); $ret = islandora_user_access(NULL, array());
$this->assertFalse($ret, 'User access denied when no object/permissions are provided.'); $this->assertFalse($ret, 'User access denied when no object/permissions are provided.');

14
tests/scripts/line_endings.sh

@ -0,0 +1,14 @@
#!/bin/bash
RETURN=0
FILES=`find -L $1 -name "*.info" -o -name "*.txt" -o -name "*.md"`
echo "Testing for files with DOS line endings..."
for FILE in $FILES
do
file $FILE | grep CRLF
if [ $? == 0 ]
then
RETURN=1
fi
done
exit $RETURN

2
tests/travis_setup.sh → tests/scripts/travis_setup.sh

@ -27,8 +27,10 @@ mv sites/all/modules/islandora/tests/travis.test_config.ini sites/all/modules/is
mkdir sites/all/libraries mkdir sites/all/libraries
ln -s $HOME/tuque sites/all/libraries/tuque ln -s $HOME/tuque sites/all/libraries/tuque
drush dl --yes coder drush dl --yes coder
drush dl --yes potx
drush en --yes coder_review drush en --yes coder_review
drush en --yes simpletest drush en --yes simpletest
drush en --yes potx
drush en --user=1 --yes islandora drush en --user=1 --yes islandora
drush cc all drush cc all
sleep 4 sleep 4
Loading…
Cancel
Save