Browse Source

Merge pull request #537 from willtp87/7.x.dd

defer derivatives api
pull/546/head
Adam 10 years ago
parent
commit
f4f32a72a7
  1. 7
      includes/admin.form.inc
  2. 39
      includes/derivatives.inc
  3. 2
      includes/regenerate_derivatives.form.inc
  4. 1
      islandora.install
  5. 19
      islandora.module

7
includes/admin.form.inc

@ -61,6 +61,13 @@ function islandora_repository_admin(array $form, array &$form_state) {
'#description' => t('HTTP caching can reduce network traffic, by allowing clients to used cached copies.'),
'#default_value' => variable_get('islandora_use_datastream_cache_headers', TRUE),
),
'islandora_defer_derivatives_on_ingest' => array(
'#type' => 'checkbox',
'#title' => t('Defer derivative generation during ingest'),
'#description' => t('Prevent derivatives from running during ingest,
useful if derivatives are to be created by an external service.'),
'#default_value' => variable_get('islandora_defer_derivatives_on_ingest', FALSE),
),
),
'islandora_namespace' => array(
'#type' => 'fieldset',

39
includes/derivatives.inc

@ -4,6 +4,9 @@
* Defines functions used when constructing derivatives.
*/
// Relations.
define('ISLANDORA_DEFER_DERIVATIVES_FLAG', 'deferDerivatives');
/**
* Decides which derivative function to call and runs it.
*
@ -245,3 +248,39 @@ function islandora_filter_derivatives($hooks, $options, AbstractObject $object)
$hooks = array_filter($hooks, $filter_function);
return $hooks;
}
/**
* Set the defer derivatives flag on an object.
*/
function islandora_set_defer_derivatives_flag(AbstractObject $object) {
$object->relationships->add(
ISLANDORA_RELS_EXT_URI,
ISLANDORA_DEFER_DERIVATIVES_FLAG,
'true',
RELS_TYPE_PLAIN_LITERAL
);
}
/**
* Get the defer derivatives flag on an object.
*/
function islandora_get_defer_derivatives_flag(AbstractObject $object) {
return $object->relationships->get(
ISLANDORA_RELS_EXT_URI,
ISLANDORA_DEFER_DERIVATIVES_FLAG,
'true',
RELS_TYPE_PLAIN_LITERAL
);
}
/**
* Remove the defer derivatives flag on an object.
*/
function islandora_remove_defer_derivatives_flag(AbstractObject $object) {
$object->relationships->remove(
ISLANDORA_RELS_EXT_URI,
ISLANDORA_DEFER_DERIVATIVES_FLAG,
'true',
RELS_TYPE_PLAIN_LITERAL
);
}

2
includes/regenerate_derivatives.form.inc

@ -95,6 +95,7 @@ function islandora_regenerate_object_derivatives_form_submit(array $form, array
*/
function islandora_regenerate_object_derivatives_batch(AbstractObject $object) {
module_load_include('inc', 'islandora', 'includes/derivatives');
islandora_remove_defer_derivatives_flag($object);
return array(
'title' => t('Regenerating all derivatives for @label', array('@label' => $object->label)),
'operations' => islandora_do_batch_derivatives($object, array('force' => TRUE)),
@ -117,6 +118,7 @@ function islandora_regenerate_object_derivatives_batch(AbstractObject $object) {
*/
function islandora_regenerate_datastream_derivative_batch(AbstractDatastream $datastream) {
module_load_include('inc', 'islandora', 'includes/derivatives');
islandora_remove_defer_derivatives_flag($datastream->parent);
return array(
'title' => t('Regenerating derivatives for the @dsid datastream', array('@dsid' => $datastream->id)),
'operations' => islandora_do_batch_derivatives($datastream->parent, array(

1
islandora.install

@ -46,6 +46,7 @@ function islandora_uninstall() {
// Add new variables to clean up.
$variables = array(
'islandora_ds_replace_exclude_enforced',
'islandora_defer_derivatives_on_ingest',
);
array_walk($variables, 'variable_del');
}

19
islandora.module

@ -1720,6 +1720,10 @@ function islandora_islandora_basic_collection_get_query_filters() {
*/
function islandora_islandora_object_ingested(AbstractObject $object) {
module_load_include('inc', 'islandora', 'includes/derivatives');
// Defer derivatives if necessary.
if (islandora_get_defer_derivatives_flag($object)) {
return;
}
islandora_run_derivatives($object, NULL);
}
@ -1731,6 +1735,10 @@ function islandora_islandora_object_ingested(AbstractObject $object) {
*/
function islandora_islandora_datastream_ingested(AbstractObject $object, AbstractDatastream $datastream) {
module_load_include('inc', 'islandora', 'includes/derivatives');
// Defer derivatives if necessary.
if (islandora_get_defer_derivatives_flag($object)) {
return;
}
islandora_run_derivatives($object, $datastream->id);
}
@ -1952,3 +1960,14 @@ function islandora_menu_local_tasks_alter(&$data, $router_item, $root_path) {
}
}
}
/**
* Implements hook_islandora_object_alter().
*/
function islandora_islandora_object_alter(AbstractObject $object, array &$context) {
// Prevent derivative creation during ingest if var is set.
if ($context['action'] == 'ingest' && variable_get('islandora_defer_derivatives_on_ingest', FALSE)) {
module_load_include('inc', 'islandora', 'includes/derivatives');
islandora_set_defer_derivatives_flag($object);
}
}

Loading…
Cancel
Save