diff --git a/includes/ingest.batch.inc b/includes/ingest.batch.inc index 7faff3d..125b187 100644 --- a/includes/ingest.batch.inc +++ b/includes/ingest.batch.inc @@ -19,7 +19,7 @@ define('ISLANDORA_BATCH_EMPTY_SET', 2); * Function to get the average. * * @param array $context - * The context + * The context. */ function islandora_batch_get_average($context) { if ($context['results']['count'] > 0) { @@ -39,7 +39,7 @@ function islandora_batch_ingest_preprocess($preprocessor, &$context) { /** * Get the name of the lock to acquire/release. * - * @param string|int|NULL $ingest_set + * @param string|int|null $ingest_set * A string or integer identifying an ingest set to process. NULL indicates * that it is a general/set-independent batch, processing everything in the * queue. @@ -91,7 +91,7 @@ function islandora_batch_get_lock_timeout($timeout) { * The general/set-independent batch should not be able to run at the same time * as any other batch. * - * @param string|int|NULL $ingest_set + * @param string|int|null $ingest_set * A string or integer identifying an ingest set to process. NULL indicates * that it is a general/set-independent batch, processing everything in the * queue. @@ -373,7 +373,6 @@ function test_islandora_batch_process_results($results, $timeout, $lock_timeout, return TRUE; } - /** * Process set of result from the islandora_batch_queue table. * @@ -397,11 +396,11 @@ function islandora_batch_process_results($results, $timeout, $lock_timeout, &$co ) { $start = timer_read(ISLANDORA_BATCH_TIMER_NAME); // Process a single object. - $ingest_object = unserialize($object['data']); + $islandora_batch_object = unserialize($object['data']); if ($object['state'] !== ISLANDORA_BATCH_STATE__DONE) { // Both a simple state and state with message return are accepted. - $process_results = $ingest_object->batchProcess(); + $process_results = $islandora_batch_object->batchProcess(); $object['state'] = is_array($process_results) ? $process_results['state'] : $process_results; } @@ -410,31 +409,49 @@ function islandora_batch_process_results($results, $timeout, $lock_timeout, &$co // XXX: Due to how the things currently work, the user name and // password hash gets serialized, so later changes to the password // can break things... Let's set the password again. - $username = $ingest_object->repository->api->connection->username; + $username = $islandora_batch_object->repository->api->connection->username; $user = user_load_by_name($username); - if ($ingest_object->repository->api->connection->password != $user->pass) { - $ingest_object->repository->api->connection->password = $user->pass; + if ($islandora_batch_object->repository->api->connection->password != $user->pass) { + $islandora_batch_object->repository->api->connection->password = $user->pass; } // Push to backend. - $ingested_object = islandora_add_object($ingest_object); - if ($ingested_object) { - $context['message'] = t('Ingested %pid.', array('%pid' => $ingested_object->id)); + $actionresult_object = $islandora_batch_object->batchRepositoryAction(); + + if ($actionresult_object) { + $context['message'] = t('Successfully %action %pid.', + array( + '%pid' => $actionresult_object->id, + '%action' => $islandora_batch_object->getRepositoryActionDescription(), + )); } else { - // Failed to ingest... Flag an error. + // Failed to process on backend... Flag an error. $object['state'] = ISLANDORA_BATCH_STATE__ERROR; - $context['message'] = t('Unknown error: Failed to ingest %pid.', array('%pid' => $ingest_object->id)); + $context['message'] = t('Unknown error: %pid cannot be %action.', + array( + '%pid' => $islandora_batch_object->id, + '%action' => $islandora_batch_object->getRepositoryActionDescription(), + )); } } catch (Exception $e) { - // Failed to ingest... Flag an error. + // Backend exception happened... Flag an error. $object['state'] = ISLANDORA_BATCH_STATE__ERROR; - $context['message'] = t('Exception occured: Failed to ingest %pid.', array('%pid' => $ingest_object->id)); + $context['message'] = t('Exception occured: %pid cannot be %action because of %message.', + array( + '%pid' => $islandora_batch_object->id, + '%action' => $islandora_batch_object->getRepositoryActionDescription(), + '%message' => $e->getMessage(), + )); } } else { - $context['message'] = t('%pid not ready for ingest.', array('%pid' => $ingest_object->id)); + $context['message'] = t('%pid cannot be %action: object not ready.', + array( + '%pid' => $islandora_batch_object->id, + '%action' => $islandora_batch_object->getRepositoryActionDescription(), + )); } // Update the info in the database. @@ -450,7 +467,7 @@ function islandora_batch_process_results($results, $timeout, $lock_timeout, &$co ); // Pass hook object and a pass/fail state for the object. - module_invoke_all(ISLANDORA_BATCH_OBJECT_PROCESSED_HOOK, $ingest_object, ($object['state'] === ISLANDORA_BATCH_STATE__DONE ? 1 : 0)); + module_invoke_all(ISLANDORA_BATCH_OBJECT_PROCESSED_HOOK, $islandora_batch_object, ($object['state'] === ISLANDORA_BATCH_STATE__DONE ? 1 : 0)); $end = timer_read(ISLANDORA_BATCH_TIMER_NAME); if (!isset($context['results']['count'])) { diff --git a/includes/islandora_batch_object_base.inc b/includes/islandora_batch_object_base.inc index 7f7c7e9..3693559 100644 --- a/includes/islandora_batch_object_base.inc +++ b/includes/islandora_batch_object_base.inc @@ -8,9 +8,10 @@ /** * Batch interface. * - * Implementing classes should subclass some version of FedoraObject, so + * Implementing classes should subclass some version of FedoraObject, so. */ abstract class IslandoraBatchObject extends IslandoraNewFedoraObject { + /** * The initial batch state. * @@ -71,6 +72,34 @@ abstract class IslandoraBatchObject extends IslandoraNewFedoraObject { */ abstract public function addRelationships(); + /** + * The actual back-end action that is run after the batchProcess. + * + * Classes not overriding this will get objects pushed to the back-end. + * (ingested) + * + * @return AbstractObject|false + * Either a newly ingested Abstract Object or false if failed. + */ + public function batchRepositoryAction() { + if (!islandora_object_load($this->id)) { + return islandora_add_object($this); + } + else { + return FALSE; + } + } + + /** + * A human readable short description of the repository action. + * + * @return string + * Recomended value is a verb in past tense. + */ + public function getRepositoryActionDescription() { + return "ingested"; + } + /** * Get the ID of this object in the queue. * @@ -92,6 +121,10 @@ abstract class IslandoraBatchObject extends IslandoraNewFedoraObject { ))); } } + } +/** + * An Islandora Batch Exception Class. + */ class IslandoraBatchNoIdException extends Exception {} diff --git a/islandora_batch.install b/islandora_batch.install index 5a52665..d462b0e 100644 --- a/islandora_batch.install +++ b/islandora_batch.install @@ -45,7 +45,7 @@ function islandora_batch_schema() { 'not null' => FALSE, ), ), - 'primary key' => array('id'), + 'primary key' => array('id', 'sid'), 'indexes' => array( 'parent_index' => array('parent'), 'sid' => array('sid'), @@ -367,3 +367,11 @@ function islandora_batch_update_7105() { No action is required for most sites, but any custom modules referring to this file should be pointed to its new location in the Islandora module. This copy of mods_to_dc.xsl will be removed in the next release.'); } + +/** + * Make PID and Set ID combined primary Keys. + */ +function islandora_batch_update_7106() { + db_drop_primary_key('islandora_batch_queue'); + db_add_primary_key('islandora_batch_queue', array('id', 'sid')); +} \ No newline at end of file