Browse Source

We now use the database to store instead of xmlformdatabase and a force has been added

pull/81/head
Ben Woodhead 13 years ago
parent
commit
0a13bf248f
  1. 108
      fedora_repository.solutionpacks.inc

108
fedora_repository.solutionpacks.inc

@ -181,7 +181,7 @@ function solution_pack_add_form($form_name, $form_xml) {
$object->name = $form_name; $object->name = $form_name;
$object->form = $form_xml; $object->form = $form_xml;
$result = drupal_write_record('xml_forms', $object); $result = drupal_write_record('xml_forms', $object);
drupal_set_message(t("Added @name", array("@name" => $name))); drupal_set_message(t("Added @name", array("@name" => $form_name)));
} }
} }
@ -196,7 +196,7 @@ function solution_pack_add_form_association($content_model, $form_name) {
$object->title_field = "['titleInfo']['title']"; $object->title_field = "['titleInfo']['title']";
$object->transform = 'mods_to_dc.xsl'; $object->transform = 'mods_to_dc.xsl';
$result = drupal_write_record('islandora_content_model_forms', $object); $result = drupal_write_record('islandora_content_model_forms', $object);
drupal_set_message(t("Added association between @cm@name", array("@cm" => $content_model, "@name"=>$name))); drupal_set_message(t("Added association between @cm@name", array("@cm" => $content_model, "@name"=>$form_name)));
} }
} }
@ -204,40 +204,68 @@ function solution_pack_add_form_association($content_model, $form_name) {
* Solution pack register form * Solution pack register form
* @param type $mods_form_name The MODS form name "Islandora Docs MODS Form" * @param type $mods_form_name The MODS form name "Islandora Docs MODS Form"
* @param type $mods_form_file The MODS form file name relative to the module (solutionpack/xml/mods_article.xml) * @param type $mods_form_file The MODS form file name relative to the module (solutionpack/xml/mods_article.xml)
* @param type $content_model The Content Model (islandora:docs_sp_cm) * @return int 0 = Ok and 1 = Unable to load file
* @param boolean $force Force a reinstall
*/ */
function solution_pack_register_form($mods_form_name, $mods_form_file, $content_model, $force=false) function solution_pack_register_form($mods_form_name, $mods_form_file, $force=false)
{ {
// Load the form builder database // Lookup the form
module_load_include('inc', 'xml_form_builder', 'XMLFormDatabase'); $results = db_result(db_query('Select name from {xml_forms} where name = "%s"', $mods_form_name));
// Check to see if there is anything to do
if ( $results && $force==false) {
// Nothing to do so early out
return 0;
}
// If it doesn't exist // Get the contents of the file
if (!XMLFormDatabase::Exists($mods_form_name) ) { $mods_form_data = file_get_contents($mods_form_file);
// Load the form // Didn't load the file
$definition = new DOMDocument(); if ( ! $mods_form_data ) {
$definition->load($mods_form_file);
// Create the form // Return an error
XMLFormDatabase::Create($mods_form_name, $definition); return 1;
}
// Create the data model
$object = new stdClass();
$object->name = $mods_form_name;
$object->form = $mods_form_data;
// Force Update of an existing form // Are we adding the form
} elseif ( $force == true ) { if ( ! $results ) {
// Load the form // Add the model to the database
$definition = new DOMDocument(); $result = drupal_write_record('xml_forms', $object);
$definition->load($mods_form_file);
// Update the form } else {
XMLFormDatabase::Update($mods_form_name, $definition);
// Update the model in the database
$result = drupal_write_record('xml_forms', $object, array("name" => $mods_form_name));
} }
// Check to see if the form has already been registered // Log the action
$result = db_result(db_query('Select content_model from {islandora_content_model_forms} where content_model = "%s" and form_name = "%s"', $content_model, $mods_form_name)); drupal_set_message(t("Added @name", array("@name" => $mods_form_name)));
}
// Check for results /**
if (!$result) { * Solution pack register form
* @param type $mods_form_name The MODS form name "Islandora Docs MODS Form"
* @param type $content_model The Content Model (islandora:docs_sp_cm)
*/
function solution_pack_register_form_association($mods_form_name, $content_model, $force=false) {
// Query the database for previous associations
$results = db_result(db_query('Select content_model from {islandora_content_model_forms} where content_model = "%s" and form_name = "%s"',
$content_model, $mods_form_name));
// Check to see if there is anything to do
if ( $results && $force==false) {
// Nothing to do so early out
return;
}
// Create a model for the database // Create a model for the database
$object = new stdClass(); $object = new stdClass();
@ -247,9 +275,19 @@ function solution_pack_register_form($mods_form_name, $mods_form_file, $content_
$object->title_field = "['titleInfo']['title']"; $object->title_field = "['titleInfo']['title']";
$object->transform = 'mods_to_dc.xsl'; $object->transform = 'mods_to_dc.xsl';
// Write the association // Are we adding the form association
if ( ! $results ) {
// Add the association
$result = drupal_write_record('islandora_content_model_forms', $object); $result = drupal_write_record('islandora_content_model_forms', $object);
} else {
// Update the association
$result = drupal_write_record('islandora_content_model_forms', $object, array("content_model" => $content_model));
} }
// Log the action
drupal_set_message(t("Added association between @cm@name", array("@cm" => $content_model, "@name"=>$mods_form_name)));
} }
/** /**
@ -259,23 +297,5 @@ function solution_pack_register_form($mods_form_name, $mods_form_file, $content_
*/ */
function solution_pack_unregister_form($mods_form_name, $content_model) function solution_pack_unregister_form($mods_form_name, $content_model)
{ {
// Load the form builders xmlformdatabase
module_load_include('inc', 'xml_form_builder', 'XMLFormDatabase');
// Check to see if the form exists
if (XMLFormDatabase::Exists($mods_form_name)) {
// Delete the form
XMLFormDatabase::Delete($mods_form_name);
}
// Check to see if the form has already been registered
$result = db_result(db_query('Select content_model from {islandora_content_model_forms} where content_model = "%s" and form_name = "%s"', $content_model, $mods_form_name));
// Is there anything to delete
if ($result) {
// Delete the association
db_query('DELETE FROM {islandora_content_model_forms} WHERE content_model = "%s" and form_name = "%s"', $content_model, $mods_form_name);
}
} }

Loading…
Cancel
Save