From ec441096e47afedf70912cd31a607c9930fb8c26 Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Tue, 28 Jun 2011 22:51:29 -0300 Subject: [PATCH] Fixes for ingesting objects. --- fedora_repository.module | 41 +++++++++++++++++++++++++++++++++++++--- formClass.inc | 23 +++++++++++++++++++--- 2 files changed, 58 insertions(+), 6 deletions(-) diff --git a/fedora_repository.module b/fedora_repository.module index 1a95be07..81e9197b 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -124,8 +124,43 @@ function fedora_repository_ingest_form_submit($form, &$form_state) { $xml_form = new XMLForm($form_state); $doc = $xml_form->submit($form, $form_state); $document = $doc->document; - dom_document_pretty_print($document); - exit(); + // Get Hidden Values. + $dsid = $form_state['values']['dsid']; + $collection_pid = $form_state['values']['collection_pid']; + $content_model_pid = $form_state['values']['content_model_pid']; + $content_model_dsid = $form_state['values']['content_model_dsid']; + // + module_load_include('inc', 'fedora_repository', 'CollectionPolicy'); + $error = TRUE; + $should_redirect = TRUE; + $collection_policy = CollectionPolicy::loadFromCollection($collection_pid); + if ($collection_policy !== FALSE) { + module_load_include('inc', 'fedora_repository', 'ContentModel'); + $relationship = $collection_policy->getRelationship(); + $content_model = ContentModel::loadFromModel($content_model_pid, $content_model_dsid); + if ($content_model !== FALSE) { + module_load_include('inc', 'islandora_content_model_forms', 'FOXML'); + $label = 'test'; //$form['#post']['form_builder'][0]; // use mods title as label + if (empty($form['#post']['active-toggle'])) { + $state = 'A'; + } + else { + $state = $form['#post']['active-toggle'] ? 'A' : 'I'; + } + $pid = $collection_policy->getNextPid($content_model_dsid); + $ingest_file_location = isset($form_state['values']['ingest-file-location']) ? $form_state['values']['ingest-file-location'] : NULL; + // hack + $transform = drupal_get_path('module', 'islandora_content_model_forms') . '/transforms/mods_to_dc.xsl'; + $foxml = new FOXML($label, $pid, $dsid, $content_model_pid, $collection_pid, $relationship, $ingest_file_location, $document, $transform, $state); + $error = $foxml->ingest(); + $_SESSION['fedora_ingest_files'] = ''; //empty this variable + $form_state['storage'] = NULL; + } + } + if ($should_redirect) { + global $base_url; + $form_state['redirect'] = ($error) ? '' : $base_url . "/fedora/repository/{$collection_pid}"; + } } else if ($form_state['clicked_button']['#id'] == 'edit-submit') { global $base_url; @@ -193,7 +228,7 @@ function fedora_repository_ingest_form_validate($form, &$form_state) { $form_state['values']['ingest-file-location'] = $fileObject->filepath; } - if (file_exists($form_state['values']['ingest-file-location'])) { + if (isset($form_state['values']['ingest-file-location']) && file_exists($form_state['values']['ingest-file-location'])) { module_load_include('inc', 'fedora_repository', 'ContentModel'); module_load_include('inc', 'fedora_repository', 'MimeClass'); diff --git a/formClass.inc b/formClass.inc index 10921bf2..ef1fc0a7 100644 --- a/formClass.inc +++ b/formClass.inc @@ -461,11 +461,14 @@ class formClass { global $user; module_load_include('inc', 'fedora_repository', 'CollectionPolicy'); // drupal_add_js("function _imce_ingest_ImceFinish(path, w, h, s, imceWin) {imceWin.close(); document.getElementById('edit-ingest-file-location').value = path;}",'inline','header'); + $content_model_pid = isset($form_state['values']['content_model_pid']) ? $form_state['values']['content_model_pid'] : NULL; + $content_model_dsid = isset($form_state['values']['content_model_dsid']) ? $form_state['values']['content_model_dsid'] : NULL; if (!user_access('ingest new fedora objects')) { drupal_set_message(t('You do not have permission to ingest.'), 'error'); return ''; } + if (empty($form_state['storage']['step'])) { // we are coming in without a step, so default to step 1 $form_state['storage']['step'] = 1; @@ -530,8 +533,8 @@ class formClass { case 2: module_load_include('inc', 'fedora_repository', 'MimeClass'); // Why this include? --Zac, 2010-09-17 - $contentModelPid = ContentModel::getPidFromIdentifier($form_state['values']['models']); - $contentModelDsid = ContentModel::getDSIDFromIdentifier($form_state['values']['models']); + $content_model_pid = ContentModel::getPidFromIdentifier($form_state['values']['models']); + $content_model_dsid = ContentModel::getDSIDFromIdentifier($form_state['values']['models']); // XML Forms if (module_exists('xml_form_api')) { module_load_include('inc', 'xml_form_api', 'XMLForm'); @@ -549,11 +552,17 @@ class formClass { $xml_form->initialize($form, $document); } $form = $xml_form->toArray(); + $form['dsid'] = array( + '#type' => 'hidden', + '#value' => isset($form_state['values']['dsid']) ? + $form_state['values']['dsid'] : + islandora_content_model_get_dsid($content_model_pid, $form_name) + ); break; } } // End XML forms - if (($cm = ContentModel::loadFromModel($contentModelPid, $contentModelDsid)) !== FALSE) { + if (($cm = ContentModel::loadFromModel($content_model_pid, $content_model_dsid)) !== FALSE) { $form = $cm->buildIngestForm($form, $form_state); if ($form === FALSE) { @@ -571,6 +580,14 @@ class formClass { '#type' => 'hidden', '#value' => $collection_pid ); + $form['content_model_pid'] = array( + '#type' => 'hidden', + '#value' => $content_model_pid + ); + $form['content_model_dsid'] = array( + '#type' => 'hidden', + '#value' => $content_model_dsid + ); if ($form_state['storage']['step'] < 2) { $button_name = t('Next');