From b6ee966a7ab97032769af00dfaf1029af2375443 Mon Sep 17 00:00:00 2001 From: Alexander O'Neill Date: Thu, 24 Mar 2011 15:26:33 -0700 Subject: [PATCH] ISLANDORA-214 Move solution pack functions to separate source file. --- fedora_repository.solutionpacks.inc | 131 ++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 fedora_repository.solutionpacks.inc diff --git a/fedora_repository.solutionpacks.inc b/fedora_repository.solutionpacks.inc new file mode 100644 index 00000000..962e69d3 --- /dev/null +++ b/fedora_repository.solutionpacks.inc @@ -0,0 +1,131 @@ + $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); +}