From 92fb559933332a4c3b91b743e69abf0ac7a1cccb Mon Sep 17 00:00:00 2001 From: DannyJoris Date: Tue, 11 Sep 2012 01:43:41 -0300 Subject: [PATCH 01/10] added some doxygen comments --- admin/islandora.admin.inc | 1 + includes/breadcrumb.inc | 3 +++ includes/datastream.inc | 6 +++++- includes/ingest-menu.inc | 1 + includes/utilities.inc | 3 +++ islandora.module | 18 ++++++++++++++---- theme/islandora.theme.inc | 6 ++++-- 7 files changed, 31 insertions(+), 7 deletions(-) diff --git a/admin/islandora.admin.inc b/admin/islandora.admin.inc index 49de312c..e3aeb60c 100644 --- a/admin/islandora.admin.inc +++ b/admin/islandora.admin.inc @@ -7,6 +7,7 @@ /** * Create admin form + * * @return array */ function islandora_repository_admin($form, &$form_state) { diff --git a/includes/breadcrumb.inc b/includes/breadcrumb.inc index d1cacdbe..5e553277 100644 --- a/includes/breadcrumb.inc +++ b/includes/breadcrumb.inc @@ -5,6 +5,9 @@ * This file contains functions to create breadcrumbs on Islandora object pages. */ +/** + * Callback function to get the breadcrumbs for an object page + */ function islandora_get_breadcrumbs($object) { $breadcrumbs = array(); diff --git a/includes/datastream.inc b/includes/datastream.inc index fea8747c..42edbd2d 100644 --- a/includes/datastream.inc +++ b/includes/datastream.inc @@ -6,6 +6,7 @@ */ define('DS_COMP_STREAM', 'DS-COMPOSITE-MODEL'); + /** * Callback function to view or download a datastream. * @@ -33,6 +34,9 @@ function islandora_view_datastream($object, $dsid, $method = 'view') { exit(); } +/** + * For a given object, return all parent collections. + */ function islandora_datastream_get_parents($islandora_object) { $parent_collections = array(); @@ -462,7 +466,7 @@ function islandora_edit_datastream($object, $ds_id) { } } -//@TODO: theme / preprocess +// @TODO: theme / preprocess function islandora_edit_datastream_registry_render($edit_registry) { $output = array( '#type' => 'markup', diff --git a/includes/ingest-menu.inc b/includes/ingest-menu.inc index 56ae500e..5e7d9436 100644 --- a/includes/ingest-menu.inc +++ b/includes/ingest-menu.inc @@ -7,6 +7,7 @@ /** * Callback function for islandora/ingest/%collection_pid + * * @TODO: validate?: pid, registry return * @param string $pid */ diff --git a/includes/utilities.inc b/includes/utilities.inc index d4cb0b40..49eb98e6 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -37,6 +37,9 @@ function islandora_convert_bytes_to_human_readable($bytes, $precision = 2) { } } +/** + * Creates a label for control group symbols. + */ function islandora_control_group_to_human_readable($control_group) { switch ($control_group) { case 'M': diff --git a/islandora.module b/islandora.module index 17171ff8..4a0fbd6a 100644 --- a/islandora.module +++ b/islandora.module @@ -201,6 +201,9 @@ function islandora_menu() { return $items; } +/** + * Implements hook_admin_paths(). + */ function islandora_admin_paths() { $paths = array(); $paths['islandora/object/*/manage*'] = TRUE; @@ -348,8 +351,9 @@ function islandora_view_object($fedora_object = NULL) { } /** - * the default view hook. If there are no modules registered to handle this objects cmodels or there are + * The default view hook. If there are no modules registered to handle this objects cmodels or there are * not any cmodels specified this will create a default display. + * * @param string $object_id * @return string */ @@ -366,7 +370,8 @@ function islandora_islandora_view_object($object) { } /** - * Theme registry function + * Implements hook_theme(). + * * @return array */ function islandora_theme() { @@ -385,7 +390,8 @@ function islandora_theme() { } /** - * drupal hook_permissions function + * Implements hook_permission(). + * * @return array */ function islandora_permission() { @@ -422,7 +428,8 @@ function islandora_permission() { } /** - * a helper function to get a connection and return an object + * A helper function to get a connection and return an object + * * @global object $user * @param string $object_id * @return FedoraObject @@ -449,6 +456,9 @@ function islandora_object_load($object_id) { } } +/** + * Ingest access callback + */ function islandora_ingest_access_callback($object, $perm) { if (islandora_access_callback($object, $perm) === FALSE) { return FALSE; diff --git a/theme/islandora.theme.inc b/theme/islandora.theme.inc index b0e79739..7999e0d0 100644 --- a/theme/islandora.theme.inc +++ b/theme/islandora.theme.inc @@ -6,7 +6,8 @@ */ /** - * preprocess the edit template + * Preprocess the edit template + * * @global string $base_url * @param array $variables * theme variables for the edit template @@ -49,7 +50,8 @@ function islandora_preprocess_islandora_default_edit(&$variables) { /** - * preprocess for the default view template + * Preprocess for the default view template + * * @global string $base_url * @param array $variables */ From f26788ddea4abbb109d10ee880a8fe4afad2a274 Mon Sep 17 00:00:00 2001 From: DannyJoris Date: Tue, 11 Sep 2012 01:46:41 -0300 Subject: [PATCH 02/10] small comment adjustment --- includes/datastream.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/datastream.inc b/includes/datastream.inc index 42edbd2d..3fde916f 100644 --- a/includes/datastream.inc +++ b/includes/datastream.inc @@ -299,7 +299,7 @@ function islandora_add_datastream_form_validate($form, &$form_state) { } } else { - // todo: this is unsafe, should probably be fixed see: + // @TODO: this is unsafe, should probably be fixed see: // http://api.drupal.org/api/drupal/includes!file.inc/function/file_save_upload/7 $arr = array(); } From b2bd51d82f03217feaf90c293af12218c4dc0ed3 Mon Sep 17 00:00:00 2001 From: DannyJoris Date: Tue, 18 Sep 2012 10:03:00 -0300 Subject: [PATCH 03/10] phase 1 of solution pack administration + creating wrapper functionality to create and ingest new objects --- css/islandora.admin.css | 16 ++- includes/islandora.ingest.inc | 123 +++++++++++++++- includes/purge.form.inc | 31 +--- includes/solution_packs.inc | 257 ++++++++++++++++++++++++++++++++++ islandora.info | 2 +- islandora.module | 93 ++++++++++++ 6 files changed, 484 insertions(+), 38 deletions(-) create mode 100644 includes/solution_packs.inc diff --git a/css/islandora.admin.css b/css/islandora.admin.css index ab1e4e86..2e3a0f41 100644 --- a/css/islandora.admin.css +++ b/css/islandora.admin.css @@ -1,9 +1,11 @@ -/* - Document : islandora_basic_collection.admin.css - Created on : May 23, 2012, 11:23:06 AM - Description: - Purpose of the stylesheet follows. -*/ - +/** + * @file + * Css file for Islandora admin pages + */ +/* Solution pack admin page */ +.islandora-solution-pack-fieldset +{ + padding-top: 0.5em; +} \ No newline at end of file diff --git a/includes/islandora.ingest.inc b/includes/islandora.ingest.inc index bf33466a..5308006d 100644 --- a/includes/islandora.ingest.inc +++ b/includes/islandora.ingest.inc @@ -5,6 +5,9 @@ * This file contains ingest callback functions */ +/** + * @TODO: needs documentation + */ function islandora_ingest_get_information(AbstractFedoraObject $collection_object) { $models = $collection_object->models; $collection_info = module_invoke_all('islandora_ingest_get_information', $models, $collection_object); @@ -12,6 +15,9 @@ function islandora_ingest_get_information(AbstractFedoraObject $collection_objec return $collection_info; } +/** + * @TODO: needs documentation + */ function islandora_ingest_get_object($content_models, $collection_pid, $relationship, $namespace) { module_load_include('inc', 'islandora', 'includes/tuque'); global $user; @@ -25,8 +31,123 @@ function islandora_ingest_get_object($content_models, $collection_pid, $relation return $object; } +/** + * @TODO: needs documentation + */ +function islandora_ingest_new_object_prepare($namespace = NULL, $label = NULL, $datastreams = array(), $content_models = array(), $relationships = array(), $collection_pid = NULL) { + // include Tuque library + module_load_include('inc', 'islandora', 'includes/tuque'); + global $user; + // new connection + try { + $connection = new IslandoraTuque($user); + } catch (Exception $e) { + drupal_set_message(t('Unable to connect to the repository %e', array('%e' => $e)), 'error'); + return; + } + // construct new object + $object = $connection->repository->constructObject($namespace); + + // add label + if (!empty($label)) { + $object->label = $label; + } + // add content model relationship(s) + foreach ($content_models as $content_model) { + $object->relationships->add(FEDORA_MODEL_URI, 'hasModel', $content_model); + } + // add collection relationship(s) + if (!empty($relationships)) { + foreach ($relationships as $relationship) { + $object->relationships->add(FEDORA_RELS_EXT_URI, $relationship['relationship'], $relationship['pid']); + } + } + // add datastreams + foreach ((array) $datastreams as $ds) { + // variables + $ds_id = $ds['dsid']; + $ds_label = isset($ds['label']) ? $ds['label'] : ''; + $ds_mimetype = isset($ds['mimetype']) ? $ds['mimetype'] : 'text/xml'; + $ds_control_group = (isset($ds['control_group']) AND in_array($ds['control_group'], array('X', 'M', 'R', 'E'))) ? $ds['control_group'] : 'M'; + $ds_datastream_file = url($ds['datastream_file'], array('absolute' => TRUE)); + + // datastream object + $datastream = $object->constructDatastream($ds_id, $ds_control_group); + $datastream->label = $ds_label; + $datastream->mimetype = $ds_mimetype; + switch ($ds_control_group) { + case 'M': + $datastream->setContentFromUrl($ds_datastream_file); + break; + case 'X': + $datastream->setContentFromString(file_get_contents($ds_datastream_file)); + break; + } + $object->ingestDatastream($datastream); + } + + module_invoke_all('islandora_ingest_pre_ingest', $object, $content_models, $collection_pid); + return $object; +} + +/** + * @TODO: needs documentation + */ function islandora_ingest_add_object(&$object) { $object->repository->ingestObject($object); module_invoke_all('islandora_ingest_post_ingest', $object); return $object; -} \ No newline at end of file +} + + +function islandora_ingest_new_object($object_model) { + // prepare variables + // namespace + $namespace = $object_model['pid']; + // label + $label = !empty($object_model['label']) ? $object_model['label'] : NULL; + // datastreams + $datastreams = array(); + if (!empty($object_model['datastreams']) AND is_array($object_model['datastreams'])) { + $datastreams = $object_model['datastreams']; + } + // content models + $content_models = array(); + if (!empty($object_model['cmodel'])) { + if (is_array($object_model['cmodel'])) { + $content_models = $object_model['cmodel']; + } + else { + $content_models[] = $object_model['cmodel']; + } + } + // relationships + $relationships = array(); + // single parent + if (!empty($object_model['parent']) AND !is_array($object_model['parent'])) { + $relationships[] = array('relationship' => 'isMemberOfCollection', 'pid' => $object_model['parent']); + } + // parents array + if (!empty($object_model['parents']) AND is_array($object_model['parents'])) { + foreach ($object_model['parents'] as $parent) { + $relationships[] = array('relationship' => 'isMemberOfCollection', 'pid' => $parent); + } + } + // other relationships + if (!empty($object_model['relationships']) AND is_array($object_model['relationships'])) { + foreach ($object_model['relationships'] as $relationship) { + $relationships[] = array('relationship' => $relationship['relationship'], 'pid' => $relationship['pid']); + } + } + + // build new object + $object = islandora_ingest_new_object_prepare($namespace, $label, $datastreams, $content_models, $relationships); + + // ingest new object + islandora_ingest_add_object($object); +} + + + + + diff --git a/includes/purge.form.inc b/includes/purge.form.inc index 62c18ba9..32517933 100644 --- a/includes/purge.form.inc +++ b/includes/purge.form.inc @@ -26,36 +26,9 @@ function islandora_purge_object_submit($form, &$form_state) { $object_id = $form_state['values']['pid']; $collection = $form_state['values']['col']; - if (!$object_id) { - drupal_set_message(t('Cannot remove object, object id not set')); - return; - } + // purge object + islandora_object_purge($object_id); - $object = islandora_object_load($object_id); - - if (!$object) { - drupal_set_message(t('Could not remove object, object not found')); - return; - } - $content_models = $object->models; - $arr = module_invoke_all('islandora_pre_purge_object', $object); //notify modules of pending deletion - if (isset($arr['delete']) && $arr['delete']) { - try { - $object->delete(); - } catch (Exception $e) { - drupal_set_message(t('Error deleting Islandora object %s %e', array('%s' => $object_id, '%e' => $e)), 'error'); - return ""; - } - } - else { - try { - $object->repository->purgeObject($object_id); - } catch (Exception $e) { - drupal_set_message(t('Error purging Islandora object %s %e', array('%s' => $object_id, '%e' => $e)), 'error'); - return ""; - } - } - module_invoke_all('islandora_post_purge_object', $object_id, $content_models); //notify modules post deletion drupal_goto($collection); } diff --git a/includes/solution_packs.inc b/includes/solution_packs.inc new file mode 100644 index 00000000..f24c269d --- /dev/null +++ b/includes/solution_packs.inc @@ -0,0 +1,257 @@ + $solution_pack_info) { + $objects = array(); + foreach ($solution_pack_info as $field => $value) { + switch ($field) { + case 'title': + $solution_pack_name = $value; + break; + case 'objects': + $objects = $value; + break; + } + } + // get form + $form_array = drupal_get_form('islandora_solution_pack_form_' . $solution_pack_module, $solution_pack_module, $solution_pack_name, $objects); + // render form + $output .= drupal_render($form_array); + } + + return $output; +} + + +function islandora_solution_pack_form($form, &$form_state, $solution_pack_module, $solution_pack_name, $objects = array()) { + + // set variables + global $base_path; + $needs_update = FALSE; + $needs_install = FALSE; + $form = array(); + + $form['solution_pack'] = array( + '#type' => 'fieldset', + '#collapsible' => FALSE, + '#collapsed' => FALSE, + '#attributes' => array('class' => array('islandora-solution-pack-fieldset')), + ); + + // adding values + $form['solution_pack']['solution_pack_module'] = array( + '#type' => 'value', + '#value' => $solution_pack_module, + ); + $form['solution_pack']['solution_pack_name'] = array( + '#type' => 'value', + '#value' => $solution_pack_name, + ); + $form['solution_pack']['objects'] = array( + '#type' => 'value', + '#value' => $objects, + ); + + // table + // header + $table_header = array('PID', 'Status'); + $table_rows = array(); + + // loop over defined objects + foreach ($objects as $object) { + $datastreams = NULL; + if (isset($object['pid'])) { + $pid = $object['pid']; + + // load object + $item = islandora_object_load($pid); + + $table_row = array($object['pid']); + $object_status = t('Up-to-date'); + if (!$item) { + $object_status = t('Missing'); + $needs_install = TRUE; + } + else { + if (isset($object['dsid']) && isset($object['datastream_file']) && isset($object['dsversion'])) { + $datastreams = array( + array( + 'dsid' => $object['dsid'], + 'datastream_file' => $object['datastream_file'], + 'dsversion' => $object['dsversion'], + ), + ); + } + elseif (!empty($object['datastreams'])) { + $datastreams = $object['datastreams']; + } + if (!empty($datastreams) && is_array($datastreams)) { + foreach ($datastreams as $ds) { + + $ds_id = $ds['dsid']; + // check if defined datastream exists in the object + if (!$item[$ds_id]) { + $needs_update = TRUE; + $object_status = t('Missing datastream'); + break; + } + elseif (isset($ds['dsversion'])) { + // Check if the datastream is versioned and needs updating. + $installed_version = islandora_get_islandora_datastream_version($item, $ds['dsid']); + $available_version = islandora_get_islandora_datastream_version(NULL, NULL, $ds['datastream_file']); + + if ($available_version > $installed_version) { + $needs_update = TRUE; + $object_status = t('Out of date'); + break; + } + } + } + } + } + array_push($table_row, $object_status); + $table_rows[] = $table_row; + } + } + + // title + if (!$form_state['submitted']) { + $form['solution_pack']['solution_pack_label'] = array( + '#markup' => filter_xss($solution_pack_name), + '#prefix' => '

', + '#suffix' => '

', + ); + + $form['solution_pack']['install_status'] = array( + '#markup' => '' . t('Object status:') . ' ', + '#prefix' => '
', + '#suffix' => '
', + ); + if (!$needs_install && !$needs_update) { + $form['solution_pack']['install_status']['#markup'] .= ' ' . theme('image', array('path' => 'misc/watchdog-ok.png')) . ' ' . t('All required objects are installed and up-to-date.'); + $submit_button_text = t("Force reinstallation of objects"); + } + else { + $form['solution_pack']['install_status']['#markup'] .= ' ' . theme('image', array('path' => 'misc/watchdog-warning.png')) . ' ' . t('Some objects must be re-ingested. See objects list for details.'); + $submit_button_text = t("Install objects"); + + } + + $form['solution_pack']['table'] = array( + '#type' => 'item', + '#markup' => theme('table', array('header' => $table_header, 'rows' => $table_rows)), + ); + } + + $form['solution_pack']['submit'] = array( + '#value' => $submit_button_text, + '#type' => 'submit', + '#name' => $solution_pack_module, + '#attributes' => array('class' => array('islandora-solution-pack-submit')), + '#weight' => 40, + ); + + $form['solution_pack']['#submit'] = array( + 'islandora_solution_pack_form_submit', + ); + + return $form; +} + +/** + * Submit handler for solution pack form. + * + * @param array $form + * The form submitted. + * @param array_reference $form_state + * The state of the form submited. + */ +function islandora_solution_pack_form_submit($form, &$form_state) { + + // get variables + $solution_pack_module = $form_state['values']['solution_pack_module']; + $solution_pack_name = $form_state['values']['solution_pack_name']; + $objects = $form_state['values']['objects']; + + $batch = array( + 'title' => t('Installing / updating solution pack objects'), + 'file' => drupal_get_path('module', 'islandora') . '/includes/solution_packs.inc', + 'operations' => array(), + ); + + foreach ($objects as $object) { + // Add this object to the batch job queue. + $batch['operations'][] = array('islandora_batch_reingest_object', array($object)); + } + + batch_set($batch); + + // Hook to let solution pack objects be modified. + // Not using module_invoke so solution packs can be expanded by other modules. + module_invoke_all('islandora_postprocess_solution_pack', $solution_pack_module); + +} + + + + +/** + * Batch reingest object + * + * @param type $object + * @param type $context + * @return type + */ +function islandora_batch_reingest_object($object, &$context) { + + module_load_include('inc', 'islandora', 'includes/utilities'); + module_load_include('inc', 'islandora', 'includes/islandora.ingest'); + // include Tuque library + module_load_include('inc', 'islandora', 'includes/tuque'); + global $user; + // new connection + try { + $connection = new IslandoraTuque($user); + } catch (Exception $e) { + drupal_set_message(t('Unable to connect to the repository %e', array('%e' => $e)), 'error'); + return; + } + + if (!empty($object) && is_array($object)) { + // set and validate PID + $pid = $object['pid']; + if (!islandora_validate_pid($pid)) { + return NULL; + } + + // purge object + // check if object already exits + $object_query = $connection->api->a->findObjects('query', 'pid=' . $pid); + if (!empty($object_query['results'])) { + islandora_object_purge($pid); + } + else { + drupal_set_message(t('Content models for the basic image module already exist!'), 'warning'); + } + + // build and ingest new object + islandora_ingest_new_object($object); + } +} + + + + + + + diff --git a/islandora.info b/islandora.info index 1179f00b..188380f9 100644 --- a/islandora.info +++ b/islandora.info @@ -1,4 +1,4 @@ -name = Islandora Repository +name = Islandora description = "View and manage Fedora objects" package = Islandora version = 7.x-dev diff --git a/islandora.module b/islandora.module index 4a0fbd6a..a506ae23 100644 --- a/islandora.module +++ b/islandora.module @@ -59,6 +59,15 @@ function islandora_menu() { 'weight' => -1, ); + $items['admin/islandora/solution_packs'] = array( + 'title' => 'Solution packs', + 'description' => 'Install content models and collections required by installed solution packs.', + 'page callback' => 'islandora_solution_packs_admin', + 'access arguments' => array(FEDORA_ADD_DS), + 'file' => 'includes/solution_packs.inc', + 'type' => MENU_NORMAL_ITEM, + ); + $items['islandora/object/%islandora_object/manage/ingest'] = array( 'title' => 'Add an object', 'page callback' => 'islandora_ingest_callback', @@ -208,6 +217,7 @@ function islandora_admin_paths() { $paths = array(); $paths['islandora/object/*/manage*'] = TRUE; $paths['islandora/object/*/delete'] = TRUE; + $paths['islandora/object/*/datastream/*/edit'] = TRUE; return $paths; } @@ -253,6 +263,19 @@ function islandora_init() { } } +/** + * Implements hook_forms(). + */ +function islandora_forms($form_id) { + $forms = array(); + if (strpos($form_id, 'islandora_solution_pack_form_') !== FALSE) { + $forms[$form_id] = array( + 'callback' => 'islandora_solution_pack_form', + ); + } + return $forms; +} + /** * a function to call other modules edit page. If there are not any modules * that handle this function this module will build a default page. @@ -456,6 +479,48 @@ function islandora_object_load($object_id) { } } +/** + * A helper function to get a connection and purge an object + * + * @global object $user + * @param string $object_id + * @return FedoraObject + */ +function islandora_object_purge($object_id) { + if (!$object_id) { + drupal_set_message(t('Cannot remove object, object id not set')); + return; + } + + // load object + $object = islandora_object_load($object_id); + + if (!$object) { + drupal_set_message(t('Could not remove object, object not found')); + return; + } + $content_models = $object->models; + $arr = module_invoke_all('islandora_pre_purge_object', $object); // notify modules of pending deletion + if (isset($arr['delete']) && $arr['delete']) { + try { + $object->delete(); + } catch (Exception $e) { + drupal_set_message(t('Error deleting Islandora object %s %e', array('%s' => $object_id, '%e' => $e)), 'error'); + return ""; + } + } + else { + try { + $object->repository->purgeObject($object_id); + } catch (Exception $e) { + drupal_set_message(t('Error purging Islandora object %s %e', array('%s' => $object_id, '%e' => $e)), 'error'); + return ""; + } + } + module_invoke_all('islandora_post_purge_object', $object_id, $content_models); // notify modules post deletion +} + + /** * Ingest access callback */ @@ -472,4 +537,32 @@ function islandora_ingest_access_callback($object, $perm) { else { return FALSE; } +} + +/** + * Content model, collection view and collection policy datastreams may now optionally define a version + * number in their top-level XML element as an attribute, as in: + * content); + } + elseif (!empty($datastream_file)) { + $doc = simplexml_load_file($datastream_file); + } + + if (!empty($doc) && $version = (int)$doc->attributes()->version) { + $return = $version; + } + + return $return; } \ No newline at end of file From f2722e2c650940a4de272b1a6e4f98101dc5c1d2 Mon Sep 17 00:00:00 2001 From: DannyJoris Date: Tue, 18 Sep 2012 17:36:46 -0300 Subject: [PATCH 04/10] phase 2 of solution pack port - moved root collection into islandora - created a callback function for install and uninstall hooks --- css/islandora.admin.css | 6 ++ images/folder.png | Bin 0 -> 5137 bytes includes/islandora.ingest.inc | 4 +- includes/solution_packs.inc | 125 ++++++++++++++++++++++++---- islandora.install | 24 +++++- islandora.module | 41 ++++++++- xml/islandora_collection_policy.xml | 21 +++++ 7 files changed, 201 insertions(+), 20 deletions(-) create mode 100644 images/folder.png create mode 100644 xml/islandora_collection_policy.xml diff --git a/css/islandora.admin.css b/css/islandora.admin.css index 2e3a0f41..1cd1976d 100644 --- a/css/islandora.admin.css +++ b/css/islandora.admin.css @@ -8,4 +8,10 @@ .islandora-solution-pack-fieldset { padding-top: 0.5em; +} + +.islandora-solution-pack-fieldset table th, +.islandora-solution-pack-fieldset table td +{ + width: 33%; } \ No newline at end of file diff --git a/images/folder.png b/images/folder.png new file mode 100644 index 0000000000000000000000000000000000000000..f4c80d830c5360c15a503e50e0bf3d8f7df3cddf GIT binary patch literal 5137 zcmV+s6z=PZP))wk&$WN`P+PIpgrcYXi!egE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dpJF?X6a4PZE5tNPf?y3U6rL(ymyRK|Up+p=v zss&N9)4jL*-dEY@hygjw9sh&sLhHZhJ8#)!yUvbeJ9WIt%FJ2hO4af0B49Bsk)jeL84N zmVNVI=#~S!e&PNN(HrY)8=_V>R@b4o-oH@R?9Pl*5zdYhF`OSI0&AmGO5bnXHG!h4 zhWx}%eJNZ@EQ}*Zld*Z`?qwSznZ`=XC2&BoFmJ#C8pt^2jJeW2$Qg3T3O&2&x3-tEDUH1R(YyP**Q$$6xP7xLmo7qg=e=B5$$Gi4lK1oCl_KCOBpW2Jt#6tuf5w23T_VB!lSFEUqY_e5 z`t<12rAJCq?W0k1UV^fhH`3n!G?o&C%L>k1d=NVQjR%FKfA*pw?XNsgwm|jrZVtjo z?RN&(uYPI!74C3{Z4T`6$T{c8)J(?}SDWe3AtfcP$USM$eDNr8{t`L^75p?;U6fl0 zow@Hp=&r0?1Tb>*zjxoX%VUe>k%N;=5vm!FRCbgTD`0){&Hobz5aq$68n89N31QLB zGU37mciCo>9S)uGpQ|LM<~TOIEQpRS9Pmfhh00-yhUU~}lte%&rT~sPWS3obIj~FQ zPB1~NPJFyy9djSKmkV*Pr_v5js4c}5bW$B_$Qf|V0f*Hhxs%L}&$UInn#p7o;gy)0 zS77pqQ8yr}f56y!*fGPZ1a_i1QuV*^-bv8-0O`g8G$FHhb8_()d1W)TpwEb3fJ!-$ zw5c|g;p8*q%f0yHvfy2a=pWrax_xx}=m!4-VW*uR;6Aq=00000NkvXXu0mjfNJ+K$ literal 0 HcmV?d00001 diff --git a/includes/islandora.ingest.inc b/includes/islandora.ingest.inc index 5308006d..a9869ed1 100644 --- a/includes/islandora.ingest.inc +++ b/includes/islandora.ingest.inc @@ -143,8 +143,8 @@ function islandora_ingest_new_object($object_model) { // build new object $object = islandora_ingest_new_object_prepare($namespace, $label, $datastreams, $content_models, $relationships); - // ingest new object - islandora_ingest_add_object($object); + // ingest (and return) new object + return islandora_ingest_add_object($object); } diff --git a/includes/solution_packs.inc b/includes/solution_packs.inc index f24c269d..5b7e24ef 100644 --- a/includes/solution_packs.inc +++ b/includes/solution_packs.inc @@ -36,6 +36,7 @@ function islandora_solution_packs_admin() { function islandora_solution_pack_form($form, &$form_state, $solution_pack_module, $solution_pack_name, $objects = array()) { // set variables + global $base_url; global $base_path; $needs_update = FALSE; $needs_install = FALSE; @@ -64,19 +65,23 @@ function islandora_solution_pack_form($form, &$form_state, $solution_pack_modul // table // header - $table_header = array('PID', 'Status'); + $table_header = array(t('Label'), t('PID'), t('Status')); $table_rows = array(); // loop over defined objects foreach ($objects as $object) { $datastreams = NULL; if (isset($object['pid'])) { + // set variables $pid = $object['pid']; // load object $item = islandora_object_load($pid); - $table_row = array($object['pid']); + // table row + $table_row = array(); + + // check out object status $object_status = t('Up-to-date'); if (!$item) { $object_status = t('Missing'); @@ -119,7 +124,19 @@ function islandora_solution_pack_form($form, &$form_state, $solution_pack_modul } } } - array_push($table_row, $object_status); + // label (prepend) + if ($needs_install) { + $label = $object['label'] ? $object['label'] : ''; + } + else { + $label = $object['label'] ? l($object['label'], $base_url . '/islandora/object/' . $pid) : ''; + } + $table_row[] = $label; + // pid + $table_row[] = $pid; + // object status + $table_row[] = $object_status; + // add row $table_rows[] = $table_row; } } @@ -212,24 +229,26 @@ function islandora_solution_pack_form_submit($form, &$form_state) { * @param type $context * @return type */ -function islandora_batch_reingest_object($object, &$context) { +function islandora_batch_reingest_object($object_model, &$context) { module_load_include('inc', 'islandora', 'includes/utilities'); module_load_include('inc', 'islandora', 'includes/islandora.ingest'); // include Tuque library module_load_include('inc', 'islandora', 'includes/tuque'); global $user; + global $base_url; // new connection try { $connection = new IslandoraTuque($user); - } catch (Exception $e) { + } + catch (Exception $e) { drupal_set_message(t('Unable to connect to the repository %e', array('%e' => $e)), 'error'); return; } - if (!empty($object) && is_array($object)) { + if (!empty($object_model) && is_array($object_model)) { // set and validate PID - $pid = $object['pid']; + $pid = $object_model['pid']; if (!islandora_validate_pid($pid)) { return NULL; } @@ -237,21 +256,95 @@ function islandora_batch_reingest_object($object, &$context) { // purge object // check if object already exits $object_query = $connection->api->a->findObjects('query', 'pid=' . $pid); + $reinstall = FALSE; if (!empty($object_query['results'])) { islandora_object_purge($pid); - } - else { - drupal_set_message(t('Content models for the basic image module already exist!'), 'warning'); + $reinstall = TRUE; } // build and ingest new object - islandora_ingest_new_object($object); + try { + $object = islandora_ingest_new_object($object_model); + $object_name = $object->label; + if ($reinstall) { + drupal_set_message(t('Successfully re-installed @object_name.', array('@object_name' => $object_name, '@pid' => $pid))); + } + else { + drupal_set_message(t('Successfully installed @object_name.', array('@object_name' => $object_name, '@pid' => $pid))); + } + } + catch (Exception $e) { + drupal_set_message(t('Installation of object @pid failed', array('@pid' => $pid)), 'error'); + } } } - - - - - +/** + * Callback function that can be called from the solution pack's hook_install() and hook_uninstall() functions. + * + * @TODO: add documentation + */ +function islandora_install_solution_pack($module_name = NULL, $op = 'install') { + if (!empty($module_name)) { + module_load_include('inc', 'islandora', 'includes/tuque'); + module_load_include('module', 'islandora', 'islandora'); + module_load_include('inc', 'islandora', 'includes/islandora.ingest'); + module_load_include('module', $module_name, $module_name); + global $base_url; + global $user; + + // get module info + $info_file = drupal_get_path('module', $module_name) . '/' . $module_name . '.info'; + $info_array = drupal_parse_info_file($info_file); + $module_label = $info_array['name']; + + // create new connection + try { + $connection = new IslandoraTuque($user); + } catch (Exception $e) { + drupal_set_message(st('Unable to connect to the repository %e', array('%e' => $e)), 'error'); + return; + } + + // get object models + $enabled_solution_packs = module_invoke_all('islandora_required_objects'); + $islandora_required_objects = $module_name . '_islandora_required_objects'; + $required_objects = $islandora_required_objects(); + $objects = $required_objects[$module_name]['objects']; + + // loop over object models + foreach ($objects as $object) { + // set variables + $pid = $object['pid']; + $label = isset($object['label']) ? $object['label'] : st('Object'); + // check if object already exists + $query = $connection->api->a->findObjects('query', 'pid=' . $pid); + + // operation: install or uninstall + switch ($op) { + case 'install': + // if object exists, don't re-ingest + if (!empty($query['results'])) { + $object_url = url($base_url . '/islandora/object/' . $pid); + drupal_set_message(st('@module_label: did not install @label because the object already exists.', array('@module_label' => $module_label, '@label' => $label, '@pid' => $pid, '!url' => $object_url)), 'warning'); + } + else { + // build and ingest new object + islandora_ingest_new_object($object); + // set message + drupal_set_message(st('@module_label: installed @label object.', array('@module_label' => $module_label, '@label' => $label, '@pid' => $pid))); + } + break; + + case 'uninstall': + // if object exists, set message + if (!empty($query['results'])) { + $object_url = url($base_url . '/islandora/object/' . $pid); + drupal_set_message(st('@module_label: Did not remove @label. It may be used by other sites.', array('@pid' => $pid, '!object_url' => $object_url, '@label' => $label, '@module_label' => $module_label)), 'warning'); + } + break; + } + } + } +} diff --git a/islandora.install b/islandora.install index 3fdd0fd7..1a4022b6 100644 --- a/islandora.install +++ b/islandora.install @@ -3,4 +3,26 @@ /** * @file * This file contains all install functions. - */ \ No newline at end of file + */ + +/** + * Implements hook_install(). + * + * @see islandora_islandora_required_objects(). + */ +function islandora_install() { + module_load_include('inc', 'islandora', 'includes/solution_packs'); + // install object(s) + islandora_install_solution_pack('islandora'); +} + +/** + * Implements hook_uninstall(). + * + * @see islandora_islandora_required_objects(). + */ +function islandora_uninstall() { + module_load_include('inc', 'islandora', 'includes/solution_packs'); + // uninstall callback + islandora_install_solution_pack('islandora', 'uninstall'); +} \ No newline at end of file diff --git a/islandora.module b/islandora.module index a506ae23..c745716a 100644 --- a/islandora.module +++ b/islandora.module @@ -565,4 +565,43 @@ function islandora_get_islandora_datastream_version($item = NULL, $dsid = NULL, } return $return; -} \ No newline at end of file +} + +/** + * Implements hook_islandora_required_objects(). + */ +function islandora_islandora_required_objects() { + + // module path + $module_path = drupal_get_path('module', 'islandora'); + + return array( + 'islandora' => array( + 'module' => 'islandora', + 'title' => 'Islandora', + 'objects' => array( + array( + 'pid' => 'islandora:root', + 'label' => 'Islandora top-level collection', + 'cmodel' => 'islandora:collectionCModel', + 'datastreams' => array( + array( + 'dsid' => 'COLLECTION_POLICY', + 'label' => 'Collection policy', + 'mimetype' => 'text/xml', + 'control_group' => 'X', + 'datastream_file' => "$module_path/xml/islandora_collection_policy.xml", + ), + array( + 'dsid' => 'TN', + 'label' => 'Thumbnail', + 'mimetype' => 'image/png', + 'control_group' => 'M', + 'datastream_file' => "$module_path/images/folder.png", + ), + ), + ), + ), + ), + ); +} diff --git a/xml/islandora_collection_policy.xml b/xml/islandora_collection_policy.xml new file mode 100644 index 00000000..9d74fb26 --- /dev/null +++ b/xml/islandora_collection_policy.xml @@ -0,0 +1,21 @@ + + + + + + dc.title + dc.creator + dc.description + dc.date + dc.identifier + dc.language + dc.publisher + dc.rights + dc.subject + dc.relation + dcterms.temporal + dcterms.spatial + Full text + + isMemberOfCollection + \ No newline at end of file From 2d9e82b79e10318ea752a11dcde55fef93fdddc9 Mon Sep 17 00:00:00 2001 From: DannyJoris Date: Wed, 19 Sep 2012 03:33:13 -0300 Subject: [PATCH 05/10] cleaned up the template file a bit --- theme/islandora-object.tpl.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/theme/islandora-object.tpl.php b/theme/islandora-object.tpl.php index d6efaac3..e876f679 100644 --- a/theme/islandora-object.tpl.php +++ b/theme/islandora-object.tpl.php @@ -53,22 +53,22 @@ * */ ?> - +
-

Details

+

- - '); ?>
+ +