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..437288c9 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($object); 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.module b/islandora.module index f0bf796b..9c811611 100644 --- a/islandora.module +++ b/islandora.module @@ -1719,6 +1719,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); } @@ -1730,6 +1734,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); }