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. 120
      fedora_repository.solutionpacks.inc

120
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,78 +204,98 @@ 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));
// If it doesn't exist
if (!XMLFormDatabase::Exists($mods_form_name) ) {
// Load the form // Check to see if there is anything to do
$definition = new DOMDocument(); if ( $results && $force==false) {
$definition->load($mods_form_file);
// Create the form // Nothing to do so early out
XMLFormDatabase::Create($mods_form_name, $definition); return 0;
}
// Force Update of an existing form // Get the contents of the file
} elseif ( $force == true ) { $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);
// Update the form // Return an error
XMLFormDatabase::Update($mods_form_name, $definition); return 1;
} }
// Check to see if the form has already been registered // Create the data model
$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)); $object = new stdClass();
$object->name = $mods_form_name;
$object->form = $mods_form_data;
// Are we adding the form
if ( ! $results ) {
// Check for results // Add the model to the database
if (!$result) { $result = drupal_write_record('xml_forms', $object);
// Create a model for the database } else {
$object = new stdClass();
$object->content_model = $content_model;
$object->form_name = $mods_form_name;
$object->dsid = 'MODS';
$object->title_field = "['titleInfo']['title']";
$object->transform = 'mods_to_dc.xsl';
// Write the association // Update the model in the database
$result = drupal_write_record('islandora_content_model_forms', $object); $result = drupal_write_record('xml_forms', $object, array("name" => $mods_form_name));
} }
// Log the action
drupal_set_message(t("Added @name", array("@name" => $mods_form_name)));
} }
/** /**
* Solution pack unregister 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 $content_model The Content Model (islandora:docs_sp_cm) * @param type $content_model The Content Model (islandora:docs_sp_cm)
*/ */
function solution_pack_unregister_form($mods_form_name, $content_model) function solution_pack_register_form_association($mods_form_name, $content_model, $force=false) {
{
// Load the form builders xmlformdatabase // Query the database for previous associations
module_load_include('inc', 'xml_form_builder', 'XMLFormDatabase'); $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 the form exists // Check to see if there is anything to do
if (XMLFormDatabase::Exists($mods_form_name)) { if ( $results && $force==false) {
// Delete the form // Nothing to do so early out
XMLFormDatabase::Delete($mods_form_name); return;
} }
// Check to see if the form has already been registered // Create a model for the database
$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)); $object = new stdClass();
$object->content_model = $content_model;
$object->form_name = $mods_form_name;
$object->dsid = 'MODS';
$object->title_field = "['titleInfo']['title']";
$object->transform = 'mods_to_dc.xsl';
// Are we adding the form association
if ( ! $results ) {
// Is there anything to delete // Add the association
if ($result) { $result = drupal_write_record('islandora_content_model_forms', $object);
} else {
// Delete the association // Update the association
db_query('DELETE FROM {islandora_content_model_forms} WHERE content_model = "%s" and form_name = "%s"', $content_model, $mods_form_name); $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)));
}
/**
* Solution pack unregister 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_unregister_form($mods_form_name, $content_model)
{
} }

Loading…
Cancel
Save