diff --git a/includes/admin.form.inc b/includes/admin.form.inc index 69f09fd2..42612ea0 100644 --- a/includes/admin.form.inc +++ b/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', diff --git a/includes/derivatives.inc b/includes/derivatives.inc index 72d61235..7248f03f 100644 --- a/includes/derivatives.inc +++ b/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 + ); +} diff --git a/includes/regenerate_derivatives.form.inc b/includes/regenerate_derivatives.form.inc index 9a7a097e..1312bec3 100644 --- a/includes/regenerate_derivatives.form.inc +++ b/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( diff --git a/islandora.install b/islandora.install index f37894e9..12c92009 100644 --- a/islandora.install +++ b/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'); } diff --git a/islandora.module b/islandora.module index c930ba5f..697d43e0 100644 --- a/islandora.module +++ b/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); + } +}