Browse Source

Add derivative regeneration to the UI.

pull/439/head
Jordan Dukart 11 years ago
parent
commit
28b3deedcc
  1. 2
      includes/datastream.inc
  2. 24
      includes/object_properties.form.inc
  3. 163
      includes/regenerate_derivatives.form.inc
  4. 30
      islandora.module
  5. 31
      theme/theme.inc

2
includes/datastream.inc

@ -312,7 +312,7 @@ function islandora_edit_datastream(AbstractDatastream $datastream) {
case 0: case 0:
// No edit implementations. // No edit implementations.
drupal_set_message(t('There are no edit methods specified for this datastream.')); drupal_set_message(t('There are no edit methods specified for this datastream.'));
drupal_goto("islandora/object/{$object->id}/manage/datastreams"); drupal_goto("islandora/object/{$datastream->parent->id}/manage/datastreams");
break; break;
case 1: case 1:

24
includes/object_properties.form.inc

@ -26,6 +26,12 @@ function islandora_object_properties_form(array $form, array &$form_state, Abstr
if (!empty($temp)) { if (!empty($temp)) {
$related_objects_pids = array_merge_recursive($related_objects_pids, $temp); $related_objects_pids = array_merge_recursive($related_objects_pids, $temp);
} }
$regenerate_derivatives_access = FALSE;
if (islandora_object_access(ISLANDORA_REGENERATE_DERIVATIVES, $object)) {
if (count(islandora_invoke_hook_list(ISLANDORA_DERVIATIVE_CREATION_HOOK, $object->models, array($object))) > 0) {
$regenerate_derivatives_access = TRUE;
}
}
return array( return array(
'pid' => array( 'pid' => array(
'#type' => 'hidden', '#type' => 'hidden',
@ -84,6 +90,12 @@ function islandora_object_properties_form(array $form, array &$form_state, Abstr
'#submit' => array('islandora_object_properties_form_delete'), '#submit' => array('islandora_object_properties_form_delete'),
'#limit_validation_errors' => array(array('pid')), '#limit_validation_errors' => array(array('pid')),
), ),
'regenerate' => array(
'#type' => 'submit',
'#access' => $regenerate_derivatives_access,
'#value' => t("Regenerate all derivatives"),
'#submit' => array('islandora_object_properties_regenerate_derivatives'),
),
); );
} }
@ -188,3 +200,15 @@ function islandora_update_object_properties($pid, $update_states, $state, $updat
} }
} }
} }
/**
* Callback function for object properties regenerate all derivatives.
*
* @param array $form
* The Drupal form.
* @param array $form_state
* The Drupal form state.
*/
function islandora_object_properties_regenerate_derivatives(array $form, array &$form_state) {
drupal_goto("islandora/object/{$form_state['object']}/regenerate");
}

163
includes/regenerate_derivatives.form.inc

@ -0,0 +1,163 @@
<?php
/**
* @file
* The confirmation forms used to regenerate derivatives.
*/
/**
* Regenerate a single datastream derivative confirm form.
*
* @param array $form
* The Drupal form.
* @param array $form_state
* The Drupal form state.
* @param AbstractDatastream $datastream
* The datastream to have derivatives regenerated for.
*
* @return array
* The Drupal form definition.
*/
function islandora_regenerate_datastream_derivative_form(array $form, array &$form_state, AbstractDatastream $datastream) {
$form_state['datastream'] = $datastream;
return confirm_form($form,
t('Are you sure you want to regenerate the derivative for the %dsid datastream?', array('%dsid' => $datastream->id)),
"islandora/object/{$datastream->parent->id}/manage/datastreams",
t('This will create a new version of the datastream. Please wait while this happens.'),
t('Regenerate'),
t('Cancel')
);
}
/**
* Submit handler for the regenerate datastream derivative form.
*
* @param array $form
* The Drupal form.
* @param array $form_state
* The Drupal form state.
*/
function islandora_regenerate_datastream_derivative_form_submit(array $form, array &$form_state) {
module_load_include('inc', 'islandora', 'includes/derivatives');
$datastream = $form_state['datastream'];
$batch = islandora_regenerate_datastream_derivative_batch($datastream);
batch_set($batch);
$form_state['redirect'] = "islandora/object/{$datastream->parent->id}/manage/datastreams";
}
/**
* Regenerate all derivatives on an object.
*
* @param array $form
* The Drupal form.
* @param array $form_state
* The Drupal form state.
* @param AbstractObject $object
* The object that is having its derivatives regenerated.
*
* @return array
* The Drupal form definition.
*/
function islandora_regenerate_object_derivatives_form(array $form, array &$form_state, AbstractObject $object) {
$form_state['object'] = $object;
return confirm_form($form,
t('Are you sure you want to regenerate all the derivatives for %title?', array('%title' => $object->label)),
"islandora/object/{$object}/manage/properties",
t('This will create a new version for every datastream on the object. Please wait while this happens.'),
t('Regenerate'),
t('Cancel')
);
}
/**
* Submit handler for the regenerate object derivativse form.
*
* @param array $form
* The Drupal form.
* @param array $form_state
* The Drupal form state.
*/
function islandora_regenerate_object_derivatives_form_submit(array $form, array &$form_state) {
module_load_include('inc', 'islandora', 'includes/derivatives');
$object = $form_state['object'];
$batch = islandora_regenerate_object_derivatives_batch($object);
batch_set($batch);
$form_state['redirect'] = "islandora/object/{$object}/manage/properties";
}
/**
* Creates a batch to go out and re-create all of the derivatives for an object.
*
* @param AbstractObject $object
* A AbstractObject representing an object within Fedora.
*
* @return array
* An array specifying the Drupal batch.
*/
function islandora_regenerate_object_derivatives_batch(AbstractObject $object) {
return array(
'title' => t('Regenerating all derivatives for @label', array('@label' => $object->label)),
'operations' => array(
array('islandora_regenerate_object_derivatives_batch_operation', array($object)),
),
'init_message' => t('Preparing to regenerate derivatives...'),
'progress_message' => t('Time elapsed: @elapsed <br/>Estimated time remaning @estimate.'),
'error_message' => t('An error has occurred.'),
'file' => drupal_get_path('module', 'islandora') . '/includes/regenerate_derivatives.form.inc',
);
}
/**
* Defines the regenerate object derivatives batch operation.
*
* @param AbstractObject $object
* A AbstractObject representing an object within Fedora.
* @param array $context
* An array containing the context of the current batch.
*/
function islandora_regenerate_object_derivatives_batch_operation(AbstractObject $object, &$context) {
module_load_include('inc', 'islandora', 'includes/derivatives');
$logging_results = islandora_do_derivatives($object, array(
'force' => TRUE,
));
islandora_derivative_logging($logging_results);
}
/**
* Creates a batch to go out and re-create the derivative for a datastream.
*
* @param AbstractDatastream $datastream
* A AbstractDatastream representing a datastream on an object within Fedora.
*
* @return array
* An array specifying the Drupal batch.
*/
function islandora_regenerate_datastream_derivative_batch(AbstractDatastream $datastream) {
return array(
'title' => t('Regenerating derivatives for the @dsid datastream', array('@dsid' => $datastream->id)),
'operations' => array(
array('islandora_regenerate_datastream_derivative_batch_operation', array($datastream)),
),
'init_message' => t('Preparing to regenerate derivatives...'),
'progress_message' => t('Time elapsed: @elapsed <br/>Estimated time remaning @estimate.'),
'error_message' => t('An error has occurred.'),
'file' => drupal_get_path('module', 'islandora') . '/includes/regenerate_derivatives.form.inc',
);
}
/**
* Defines the regenerate datastream derivative batch operation.
*
* @param AbstractDatastream $datastream
* A AbstractDatastream representing a datastream on an object within Fedora.
* @param array $context
* An array containing the context of the current batch.
*/
function islandora_regenerate_datastream_derivative_batch_operation(AbstractDatastream $datastream, &$context) {
module_load_include('inc', 'islandora', 'includes/derivatives');
$logging_results = islandora_do_derivatives($datastream->parent, array(
'force' => TRUE,
'destination_dsid' => $datastream->id,
));
islandora_derivative_logging($logging_results);
}

30
islandora.module

@ -36,6 +36,7 @@ define('ISLANDORA_MANAGE_PROPERTIES', 'manage object properties');
define('ISLANDORA_VIEW_DATASTREAM_HISTORY', 'view old datastream versions'); define('ISLANDORA_VIEW_DATASTREAM_HISTORY', 'view old datastream versions');
define('ISLANDORA_MANAGE_DELETED_OBJECTS', 'manage deleted objects'); define('ISLANDORA_MANAGE_DELETED_OBJECTS', 'manage deleted objects');
define('ISLANDORA_REVERT_DATASTREAM', 'revert to old datastream'); define('ISLANDORA_REVERT_DATASTREAM', 'revert to old datastream');
define('ISLANDORA_REGENERATE_DERIVATIVES', 'regenerate derivatives for an object');
// Hooks. // Hooks.
@ -209,6 +210,15 @@ function islandora_menu() {
'access callback' => 'islandora_object_access_callback', 'access callback' => 'islandora_object_access_callback',
'access arguments' => array(ISLANDORA_PURGE, 2), 'access arguments' => array(ISLANDORA_PURGE, 2),
); );
$items['islandora/object/%islandora_object/regenerate'] = array(
'title' => 'Regenerate all derivatives on an object',
'file' => 'includes/regenerate_derivatives.form.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_regenerate_object_derivatives_form', 2),
'type' => MENU_CALLBACK,
'access callback' => 'islandora_object_access_callback',
'access arguments' => array(ISLANDORA_REGENERATE_DERIVATIVES, 2),
);
$items['islandora/object/%islandora_object/manage/datastreams/add'] = array( $items['islandora/object/%islandora_object/manage/datastreams/add'] = array(
'title' => 'Add a datastream', 'title' => 'Add a datastream',
'file' => 'includes/add_datastream.form.inc', 'file' => 'includes/add_datastream.form.inc',
@ -314,6 +324,16 @@ function islandora_menu() {
'access arguments' => array(ISLANDORA_VIEW_DATASTREAM_HISTORY, 4), 'access arguments' => array(ISLANDORA_VIEW_DATASTREAM_HISTORY, 4),
'load arguments' => array(2), 'load arguments' => array(2),
); );
$items['islandora/object/%islandora_object/datastream/%islandora_datastream/regenerate'] = array(
'title' => 'Regenrate datastream derivative',
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_regenerate_datastream_derivative_form', 4),
'file' => 'includes/regenerate_derivatives.form.inc',
'type' => MENU_CALLBACK,
'access callback' => 'islandora_datastream_access',
'access arguments' => array(ISLANDORA_REGENERATE_DERIVATIVES, 4),
'load arguments' => array(2),
);
$items['islandora/object/%islandora_object/download_clip'] = array( $items['islandora/object/%islandora_object/download_clip'] = array(
'page callback' => 'islandora_download_clip', 'page callback' => 'islandora_download_clip',
'page arguments' => array(2), 'page arguments' => array(2),
@ -460,6 +480,10 @@ function islandora_theme() {
'file' => 'theme/theme.inc', 'file' => 'theme/theme.inc',
'variables' => array('datastream' => NULL), 'variables' => array('datastream' => NULL),
), ),
'islandora_datastream_regenerate_link' => array(
'file' => 'theme/theme.inc',
'variables' => array('datastream' => NULL),
),
'islandora_dublin_core_display' => array( 'islandora_dublin_core_display' => array(
'file' => 'theme/theme.inc', 'file' => 'theme/theme.inc',
'template' => 'theme/islandora-dublin-core-display', 'template' => 'theme/islandora-dublin-core-display',
@ -534,6 +558,10 @@ function islandora_permission() {
'title' => t('Manage deleted objects'), 'title' => t('Manage deleted objects'),
'description' => t('Purge or revert deleted objects.'), 'description' => t('Purge or revert deleted objects.'),
), ),
ISLANDORA_REGENERATE_DERIVATIVES => array(
'title' => t('Regenerate derivatives'),
'description' => t('Regenerate derivatives for an object or per datastream.'),
),
); );
} }
@ -1069,7 +1097,7 @@ function islandora_default_islandora_view_object($object) {
* *
* @param AbstractObject $object * @param AbstractObject $object
* The fedora object to print. * The fedora object to print.
* @param unknown $alter * @param string $alter
* The string representation of the themed viewable object. * The string representation of the themed viewable object.
* *
* @return array * @return array

31
theme/theme.inc

@ -25,7 +25,7 @@ function islandora_preprocess_islandora_default_edit(array &$variables) {
$header[] = array('data' => t('Versions')); $header[] = array('data' => t('Versions'));
} }
$header[] = array('data' => t('Operations'), 'colspan' => '3'); $header[] = array('data' => t('Operations'), 'colspan' => '4');
$table_attributes = array('class' => array('manage-datastreams')); $table_attributes = array('class' => array('manage-datastreams'));
$rows = array(); $rows = array();
@ -79,6 +79,14 @@ function islandora_preprocess_islandora_default_edit(array &$variables) {
'datastream' => $ds, 'datastream' => $ds,
)), )),
); );
if (user_access(ISLANDORA_REGENERATE_DERIVATIVES)) {
$row[] = array(
'class' => 'datastream-regenerate',
'data' => theme('islandora_datastream_regenerate_link', array(
'datastream' => $ds,
)),
);
}
$rows[] = $row; $rows[] = $row;
} }
$caption = filter_xss($islandora_object->label) . ' - ' . $islandora_object->id; $caption = filter_xss($islandora_object->label) . ' - ' . $islandora_object->id;
@ -424,6 +432,27 @@ function theme_islandora_datastream_version_link(array $vars) {
} }
} }
/**
* Renders a link that will re-create derivatives for a datastream.
*
* @param array $vars
* An array containing:
* - datastream: An AbstractDatastream to generate the version link from.
*
* @return string
* Markup.
*/
function theme_islandora_datastream_regenerate_link(array $vars) {
$datastream = $vars['datastream'];
$object = $datastream->parent;
$hooks = islandora_invoke_hook_list(ISLANDORA_DERVIATIVE_CREATION_HOOK, $object->models, array($object));
foreach ($hooks as $hook) {
if ($hook['destination_dsid'] == $datastream->id) {
return l(t('regenerate'), "islandora/object/{$datastream->parent->id}/datastream/{$datastream->id}/regenerate");
}
}
}
/** /**
* Implements hook_preprocess(). * Implements hook_preprocess().
*/ */

Loading…
Cancel
Save