From c0fd0f11f2dc9bef1c412e1561eb2a9d971eaa88 Mon Sep 17 00:00:00 2001 From: Alexander O'Neill Date: Thu, 3 Mar 2011 13:29:27 -0400 Subject: [PATCH] ISLANDORA-214 Add function to check a datastream's version. --- content_models/COLLECTIONCM.xml | 90 ++++++++++++++- fedora_repository.install | 23 ---- fedora_repository.module | 106 ++++++++++++++++++ .../islandora_newspaper.module | 56 ++++----- 4 files changed, 224 insertions(+), 51 deletions(-) diff --git a/content_models/COLLECTIONCM.xml b/content_models/COLLECTIONCM.xml index 85ed18d1..9dae85ef 100644 --- a/content_models/COLLECTIONCM.xml +++ b/content_models/COLLECTIONCM.xml @@ -1 +1,89 @@ - text/xml text/plain application/xml The name given to the resource An entity primarily responsible for making the content of the resource such as a person, organization or service. An entity primarily responsible for making the content of the resource such as a person, organization or service. none Multi Media image meeting presentation sound text Examples include an abstract, table of contents, or free-text account of the content of the resource. An entity, (including persons, organizations, or services), responsible for making the resource available. An entity responsible for contributing to the content of the resource such as a person, organization or service. Temporal scope of the content if known. Date format is YYYY-MM-DD (e.g. 1890,1910-10,or 2007-10-23) Genre of the content of the resource. Examples include: home page, novel, poem, working paper, technical report, essay, dictionary. none collection dataset event image interactive resource model party physical object place service software sound text A reference to a resource from which the present resource is derived. A unique reference to the resource; In this instance, the accession number or collection number. The language of the intellectual content of the resource. English French Reference to a related resource. Information about intellectual property rights, copyright, and various property rights. \ No newline at end of file + + + + text/xml + text/plain + application/xml + + + + + + + + + + + + + + The name given to the resource + + + An entity primarily responsible for making the content of the resource such as a person, organization or service. + + + An entity primarily responsible for making the content of the resource such as a person, organization or service. + + none + Multi Media + image + meeting + presentation + sound + text + + + + Examples include an abstract, table of contents, or free-text account of the content of the resource. + + + An entity, (including persons, organizations, or services), responsible for making the resource available. + + + An entity responsible for contributing to the content of the resource such as a person, organization or service. + + + Temporal scope of the content if known. Date format is YYYY-MM-DD (e.g. 1890,1910-10,or 2007-10-23) + + + Genre of the content of the resource. Examples include: home page, novel, poem, working paper, technical report, essay, dictionary. + + none + collection + dataset + event + image + interactive resource + model + party + physical object + place + service + software + sound + text + + + + A reference to a resource from which the present resource is derived. + + + A unique reference to the resource; In this instance, the accession number or collection number. + + + The language of the intellectual content of the resource. + + English + French + + + + Reference to a related resource. + + + Information about intellectual property rights, copyright, and various property rights. + + + + diff --git a/fedora_repository.install b/fedora_repository.install index a90e33fc..de8f31e8 100644 --- a/fedora_repository.install +++ b/fedora_repository.install @@ -93,27 +93,4 @@ function fedora_repository_requirements($phase) { } return $requirements; -} - -/** - * Invokes a hook to any dependent modules asking them if their installations require - * any fedora objects to be present. Modules implementing this hook should return an array - * of arrays of the form: - * - * array( 'pid', 'path-to-foxml-file', 'dsid', 'path-to-datastream-file', int dsversion) - * - * where the last three options are optional. A module can either point to a simple - * foxml file to install, or can specify a datastreamstream to check for, with a - * path to load the datastream from if it isn't there. Optionally a version number - * can be included, to enable updating of content model or collection policy streams - * that may have been updated. THis is a simple whole number that should be incremented - * when changed. This value appears in as an attribute of the topmost element of the stream, - * e.g.,: - * - * NULL ), ), + 'fedora_repository_solution_packs_list' => array( + 'arguments' => array( + 'solution_packs' => NULL, + ), + ), ); } @@ -1724,3 +1729,104 @@ function fedora_repository_display_schema($file) { return; } + +/** + * Invokes a hook to any dependent modules asking them if their installations require + * any fedora objects to be present. Modules implementing this hook should return an array + * of arrays of the form: + * + * array( 'pid', 'path-to-foxml-file', 'dsid', 'path-to-datastream-file', int dsversion) + * + * where the last three options are optional. A module can either point to a simple + * foxml file to install, or can specify a datastreamstream to check for, with a + * path to load the datastream from if it isn't there. Optionally a version number + * can be included, to enable updating of content model or collection policy streams + * that may have been updated. THis is a simple whole number that should be incremented + * when changed. This value appears in as an attribute of the topmost element of the stream, + * e.g.,: + * + * $objects) { + + } + return theme('fedora_repository_solution_packs_list', $required_objects); +} + +/** + * Check for installed objects and add a 'Update' or 'Install' button if some objects are missing. + * @param array $solution_pack + */ +function fedora_repository_solution_pack_form($form, &$form_state, $solution_pack_name, $objects = array()) { + // Check each object to see if it is in the repository. + + $form['name'] = array( + '#value' => $solution_pack_name, + ); + $needs_update = FALSE; + $needs_install = FALSE; + + foreach($objects as $object) { + if (isset($object['pid'])) { + $pid = $object['pid']; + + $item = new Fedora_Item($pid); + if (!$item->exists()) { + $needs_install = TRUE; + $object['install'] = TRUE; + } + elseif (isset($object['dsid']) && isset($object['datastream_file']) && isset($object['dsversion'])) { + // Check if the datastream is versioned and needs updating. + $installed_version = fedora_repository_get_islandora_datastream_version($item, $object['dsid']); + $available_version = fedora_repository_get_islandora_datastream_version(NULL, NULL, $object['datastream_file']); + if ($available_version > $installed_version) { + $needs_update = TRUE; + $object['update'] = TRUE; + } + } + $row .= "$icon"; + $row .= "Object: $pid" . t('Installed') . ""; + $row .= ""; + $output .= $row; + } + } +} + +function fedora_repository_get_islandora_datastream_version($item = NULL, $dsid = NULL, $datastream_file = NULL) { + $return = NULL; + if (isset($item)) { + $doc = simplexml_load_string($item->get_datastream_dissemination($dsid)); + } elseif (isset($datastream_file)) { + $doc = simplexml_load_file($datastream_file); + } + + if (!empty($doc)) { + $attrs = $doc->attributes(); + foreach($attrs as $name => $value) { + if ($name == 'version') { + $return = (int) $value; + break; + } + } + } + return $return; +} + +function theme_fedora_repository_solution_packs_list($solution_packs) { + module_load_include('inc', 'fedora_repository', 'api/fedora_item'); + module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); + $output = ''; + $header = array(); + $rows = array(); + + + + + drupal_add_css(drupal_get_path('module', 'update') .'/update.css'); + return $output; +} \ No newline at end of file diff --git a/plugins/islandora_newspaper/islandora_newspaper.module b/plugins/islandora_newspaper/islandora_newspaper.module index 8a7fe1e9..9a3a567a 100644 --- a/plugins/islandora_newspaper/islandora_newspaper.module +++ b/plugins/islandora_newspaper/islandora_newspaper.module @@ -7,33 +7,35 @@ function islandora_newspaper_required_fedora_objects() { // array( 'path-to-foxml-file', 'pid', 'dsid', 'path-to-datastream-file', int dsversion, boolean required) $module_path = drupal_get_path('module', 'islandora_newspaper'); return array( - array( - 'foxml_file' => "$module_path/newspapers_issueCModel.xml", - 'pid' => NULL, - 'dsid' => NULL, - 'datastream_file' => NULL, - 'dsversion' => NULL, - ), - array( - 'foxml_file' => "$module_path/newspapers_pageCModel.xml", - 'pid' => NULL, - 'dsid' => NULL, - 'datastream_file' => NULL, - 'dsversion' => NULL, - ), - array( - 'foxml_file' => "$module_path/newspapers_viewerSdep-issueCModel.xml", - 'pid' => NULL, - 'dsid' => NULL, - 'datastream_file' => NULL, - 'dsversion' => NULL, - ), - array( - 'foxml_file' => "$module_path/newspapers_viewerSdep-pageCModel.xml", - 'pid' => NULL, - 'dsid' => NULL, - 'datastream_file' => NULL, - 'dsversion' => NULL, + 'Islandora Newspapers' => array( + array( + 'foxml_file' => "$module_path/newspapers_issueCModel.xml", + 'pid' => 'newspapers:issueCModel', + 'dsid' => NULL, + 'datastream_file' => NULL, + 'dsversion' => NULL, + ), + array( + 'foxml_file' => "$module_path/newspapers_pageCModel.xml", + 'pid' => 'newspapers:pageCModel', + 'dsid' => NULL, + 'datastream_file' => NULL, + 'dsversion' => NULL, + ), + array( + 'foxml_file' => "$module_path/newspapers_viewerSdep-issueCModel.xml", + 'pid' => 'newspapers:viewerSdep-issueCModel', + 'dsid' => NULL, + 'datastream_file' => NULL, + 'dsversion' => NULL, + ), + array( + 'foxml_file' => "$module_path/newspapers_viewerSdep-pageCModel.xml", + 'pid' => 'newspapers:viewerSdep-pageCModel', + 'dsid' => NULL, + 'datastream_file' => NULL, + 'dsversion' => NULL, + ), ), ); } \ No newline at end of file