Browse Source

ISLANDORA-214 Add menu item for solution packs.

pull/105/head
Alexander O'Neill 14 years ago
parent
commit
2f111cf90d
  1. 172
      fedora_repository.module
  2. 22
      fedora_repository.solutionpacks.inc
  3. 1
      formClass.inc

172
fedora_repository.module

@ -1399,6 +1399,49 @@ function fedora_repository_demo_objects_form_submit($form, &$form_state) {
}
}
function fedora_repository_required_fedora_objects() {
// array( 'path-to-foxml-file', 'pid', 'dsid', 'path-to-datastream-file', int dsversion, boolean required)
$module_path = drupal_get_path('module', 'fedora_repository');
return array (
'fedora_repository' => array(
'module' => 'fedora_repository',
'title' => 'Islandora Core',
'objects' => array (
array (
'foxml_file' => "$module_path",
'pid' => 'islandora:collectionCModel',
'dsid' => 'ISLANDORACM',
'datastream_file' => "$module_path/content_models/COLLECTIONCM.xml",
'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,
),
),
),
);
}
/*
* Functions to create a time selector form element type.
*/
@ -1737,135 +1780,6 @@ function fedora_repository_display_schema($file) {
}
/**
* 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.,:
*
* <?xml version="1.0" encoding="utf-8"?> <content_model name="Collection" version="2" ...
*
* Datastreams which don't have this element are assumed to be at version 0.
*/
function fedora_repository_solution_packs_page() {
$enabled_solution_packs = module_invoke_all('required_fedora_objects');
$output = '';
foreach ($enabled_solution_packs as $solution_pack_module => $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;
}
}
$output .= drupal_get_form('fedora_repository_solution_pack_form', $solution_pack_module, $solution_pack_name, $objects);
}
return $output;
}
/**
* 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_state, $solution_pack_module, $solution_pack_name, $objects = array()) {
// Check each object to see if it is in the repository.
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$needs_update = FALSE;
$needs_install = FALSE;
$form = array();
$form['solution_pack_module'] = array(
'#type' => 'hidden',
'#value' => $solution_pack_module,
);
if (!$form_state['submitted']) {
$form['objects'] = array(
'#type' => 'fieldset',
'#title' => "Objects",
'#weight' => 10,
'#attributes' => array('class' => 'collapsed'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$table_header = array('PID', 'Status');
$table_rows = array();
foreach($objects as $object) {
if (isset($object['pid'])) {
$pid = $object['pid'];
$item = new Fedora_Item($pid);
$table_row = array($object['pid']);
$object_status = t('Up-to-date');
if (!$item->exists()) {
$object_status = 'Missing';
$needs_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_status = 'Out of date';
}
}
array_push($table_row, $object_status);
$table_rows[] = $table_row;
}
}
$form['objects']['table'] = array(
'#type' => 'markup',
'#value' => theme_table($table_header, $table_rows),
);
}
$form['submit'] = array(
'#value' => t('Install'),
'#disabled' => !$needs_install,
'#type' => 'submit',
'#name' => 'ingest',
);
return $form;
}
function fedora_repository_solution_pack_form_submit($form, &$form_state) {
$what = $form_state;
$module_name = $form_state['values']['solution_pack_module'];
$solution_pack_info = call_user_func($module_name . '_required_fedora_objects');
$batch = array(
'title' => t('Installing / updating solution pack objects'),
'file' => drupal_get_path('module', 'fedora_repository') . '/fedora_repository.module',
'operations' => array(),
);
foreach ($solution_pack_info[$module_name]['objects'] as $object) {
// Add this object to the batch job queue.
$batch['operations'][] = array('fedora_repository_batch_reingest_object', array($object));
}
batch_set($batch);
}
function fedora_repository_batch_reingest_object($object, &$context) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
module_load_include('inc', 'fedora_repository', 'api/fedora_utils');

22
fedora_repository.solutionpacks.inc

@ -48,7 +48,7 @@ function fedora_repository_solution_packs_page() {
function fedora_repository_solution_pack_form(&$form_state, $solution_pack_module, $solution_pack_name, $objects = array()) {
// Check each object to see if it is in the repository.
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
global $base_path;
$needs_update = FALSE;
$needs_install = FALSE;
$form = array();
@ -58,7 +58,12 @@ function fedora_repository_solution_pack_form(&$form_state, $solution_pack_modul
);
if (!$form_state['submitted']) {
$form['soluction_pack_name'] = array(
'#type' => 'markup',
'#value' => t($solution_pack_name),
'#prefix' => '<h3>',
'#suffix' => '</h3>',
);
$form['objects'] = array(
'#type' => 'fieldset',
'#title' => "Objects",
@ -102,13 +107,24 @@ function fedora_repository_solution_pack_form(&$form_state, $solution_pack_modul
'#value' => theme_table($table_header, $table_rows),
);
}
$form['install_status'] = array(
'#type' => 'markup',
'#prefix' => '<strong>' . t('Object status:') . '&nbsp;</strong>',
'#suffix' => '&nbsp;',
);
if (!$needs_install) {
$form['install_status']['#value'] = theme_image('misc/watchdog-ok.png') . t('All required objects are installed and up-to-date.');
}
else {
$form['install_status']['#value'] = theme_image('misc/watchdog-warning.png') . t('Some objects must be re-ingested. See Objects list for details.');
}
$form['submit'] = array(
'#value' => t('Install'),
'#disabled' => !$needs_install,
'#type' => 'submit',
'#name' => 'ingest',
);
return $form;
}

1
formClass.inc

@ -46,6 +46,7 @@ class formClass {
'description' => t('Install content models and collections required by installed solution packs.'),
'page callback' => 'fedora_repository_solution_packs_page',
'access arguments' => array('add fedora datastreams'),
'file' => 'fedora_repository.solutionpacks.inc',
'type' => MENU_LOCAL_TASK,
);

Loading…
Cancel
Save