Browse Source

Added initial code for swapping content models in a collection

pull/120/merge
rwincewicz 13 years ago
parent
commit
c3c5b28adb
  1. 12
      islandora_basic_collection/admin/islandora_basic_collection.admin.inc
  2. 52
      islandora_basic_collection/includes/ChangeContentModels.inc
  3. 23
      islandora_basic_collection/includes/ChildCollection.inc
  4. 7
      islandora_basic_collection/includes/CollectionManagement.inc
  5. 22
      islandora_basic_collection/includes/CollectionManagerTable.inc
  6. 115
      islandora_basic_collection/includes/CollectionPolicy.inc
  7. 26
      islandora_basic_collection/includes/DeleteCollection.inc
  8. 37
      islandora_basic_collection/includes/ManagePolicies.inc
  9. 18
      islandora_basic_collection/includes/MoveCollection.inc
  10. 61
      islandora_basic_collection/islandora_basic_collection.install
  11. 32
      islandora_basic_collection/islandora_basic_collection.module

12
islandora_basic_collection/admin/islandora_basic_collection.admin.inc

@ -1,5 +1,14 @@
<?php
/**
* @file
* islandora_basic_collection.admin.inc
*/
/**
*
* @return type
*/
function islandora_basic_collection_admin() {
$form = array();
$form['islandora_basic_collection_use_for_default_tab'] = array(
@ -12,5 +21,4 @@ function islandora_basic_collection_admin() {
);
return system_settings_form($form);
}
}

52
islandora_basic_collection/includes/ChangeContentModels.inc

@ -0,0 +1,52 @@
<?php
/**
* @file
* ChangeContentModels.inc
*/
function islandora_change_content_models_form($form, &$form_state, $collection_pid) {
$represented_content_models = get_represented_content_models($collection_pid);
var_dump($represented_content_models);
$form['change_cmodel']['titlebox'] = array(
'#type' => 'item',
'#title' => t("Change Content Models within @collection_pid", array('@collection_pid' => $collection_pid)),
);
$form['change_cmodel']['current_content_model'] = array(
'#title' => "Choose content model to be changed",
'#type' => 'select',
'#options' => $represented_content_models,
'#description' => t("All objects in this collection with the selected content model will be changed."),
);
$form['change_cmodel']['new_content_model'] = array(
'#title' => "Choose new content model",
'#type' => 'select',
'#options' => $new_content_models,
'#description' => t("The new content model to be assigned to selected objects."),
);
$form['change_cmodel']['collection_pid'] = array(
'#type' => 'hidden',
'#value' => $this_collection_pid,
);
$form['change_cmodel']['submit'] = array(
'#type' => 'submit',
'#value' => t('Change Content Model Associations'),
'#id' => 'change_model',
);
return $form;
}
function islandora_change_content_models_form_validate($form, &$form_state) {
}
function islandora_change_content_models_form_submit($form, &$form_state) {
}

23
islandora_basic_collection/includes/ChildCollection.inc

@ -1,8 +1,20 @@
<?php
/**
* @file
* ChildCollection.inc
*/
/**
*
* @param type $form
* @param type $form_state
* @param type $this_collection_pid
* @return string
*/
function islandora_create_child_collection_form($form, &$form_state, $this_collection_pid) {
module_load_include('inc', 'islandora', 'RestConnection');
$restConnection = new RestConnection();
$rest_connection = new RestConnection();
$restricted = FALSE;
if (variable_get('fedora_namespace_restriction_enforced', TRUE)) {
@ -18,7 +30,8 @@ function islandora_create_child_collection_form($form, &$form_state, $this_colle
$collection_namespace = substr($this_collection_pid, 0, strpos($this_collection_pid, ":"));
$form['child_creation']['titlebox'] = array(
'#markup' => t("Create New Child Collection within @collection", array('@collection' => $this_collection_pid)),
'#type' => 'item',
'#title' => t("Create New Child Collection within @collection", array('@collection' => $this_collection_pid)),
);
$form['child_creation']['collection_name'] = array(
@ -32,7 +45,7 @@ function islandora_create_child_collection_form($form, &$form_state, $this_colle
'#title' => "Collection PID",
'#type' => 'textfield',
'#size' => 15,
'#default_value' => $restConnection->repository->api->m->getNextPid($collection_namespace),
'#default_value' => $rest_connection->repository->api->m->getNextPid($collection_namespace),
'#description' => t("Unique PID for this collection. <br />Pids take the general form of namespace:collection (eg. islandora:pamphlets)"),
);
@ -69,7 +82,7 @@ function islandora_create_child_collection_form($form, &$form_state, $this_colle
}
function islandora_create_child_collection_form_validate($form, &$form_state) {
}
function islandora_create_child_collection_form_submit($form, &$form_state) {
@ -94,7 +107,7 @@ function islandora_create_child_collection_form_submit($form, &$form_state) {
$thumbnail_datastream->mimetype = 'image/png';
$fedora_object->ingestDatastream($thumbnail_datastream);
$new_fedora_object = islandora_ingest_add_object($fedora_object);
// $content_models = $form_state['values']['content_models'];
// $collection_policy_xml = simplexml_load_string($collection_policy);
// foreach ($content_models as $content_model) {

7
islandora_basic_collection/includes/CollectionManagement.inc

@ -1,5 +1,10 @@
<?php
/**
* @file
* CollectionManagement.inc
*/
/**
* collection creation form
* @param array $form_state
@ -219,7 +224,7 @@ function collection_management_form($this_collection_pid, $content_models) {
'#id' => 'change_model',
);
return($form);
return $form;
}
/**

22
islandora_basic_collection/includes/CollectionManagerTable.inc

@ -1,5 +1,10 @@
<?php
/**
* @file
* CollectionManagerTable.inc
*/
/**
* Returns a formatted table listing all members of the collection
* defined by the $collection_pid parameter
@ -9,12 +14,12 @@
function islandora_collection_table($collection_pid) {
module_load_include('inc', 'islandora', 'RestConnection');
require_once 'sites/all/libraries/tuque/RepositoryQuery.php';
$restConnection = new RestConnection();
$rest_connection = new RestConnection();
$query = 'select $object $title from <#ri>
where ($object <info:fedora/fedora-system:def/relations-external#isMemberOf> <info:fedora/' . $collection_pid . '>
or $object <info:fedora/fedora-system:def/relations-external#isMemberOfCollection> <info:fedora/' . $collection_pid . '>)
and $object <dc:title> $title';
$results = $restConnection->repository->ri->itqlQuery($query, 'unlimited', '0');
$results = $rest_connection->repository->ri->itqlQuery($query, 'unlimited', '0');
$keys = array();
$objects = array();
foreach ($results as $result) {
@ -35,15 +40,15 @@ function islandora_collection_table($collection_pid) {
),
);
}
$header = array(
'title' => array('data' => t('Title')),
);
if (!$rows) {
return;
}
$table = array(
'#type' => 'tableselect',
'#header' => $header,
@ -51,7 +56,7 @@ function islandora_collection_table($collection_pid) {
);
return $table;
}
/**
@ -89,19 +94,18 @@ function get_collections_as_option_array() {
$allowed_string = variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora:');
$namespaces = explode(':', $allowed_string);
$restConnection = new RestConnection();
$rest_connection = new RestConnection();
$query = 'select $object $title from <#ri>
where ($object <fedora-model:label> $title
and $object <info:fedora/fedora-system:def/model#hasModel> <info:fedora/islandora:collectionCModel>
and $object <fedora-model:state> <info:fedora/fedora-system:def/model#Active>)
order by $title';
$results = $restConnection->repository->ri->itqlQuery($query, 'unlimited', '0');
$results = $rest_connection->repository->ri->itqlQuery($query, 'unlimited', '0');
foreach ($namespaces as $namespace) {
$trimmed_names[] = trim($namespace);
}
$options = array();
foreach ($results as $item) { //removes blanks
// var_dump($item['object']['value']);
$namespace = explode(':', $item['object']['value']);
$namespace = trim($namespace[0]);
if (!$restricted || in_array($namespace, $trimmed_names)) {

115
islandora_basic_collection/includes/CollectionPolicy.inc

@ -16,7 +16,7 @@ class CollectionPolicy {
*
* @param string $xmlStr
* The COLLECTION_POLICY in string form
*
*
* @return CollectionPolicy
* The parsed collection policy.
*/
@ -27,8 +27,8 @@ class CollectionPolicy {
}
/**
* Gets the name of the relationship to use
* for members of this collection.
* Gets the name of the relationship to use
* for members of this collection.
* Returns FALSE on failure.
*
* @return string $relationship
@ -39,8 +39,8 @@ class CollectionPolicy {
}
/**
* Sets the name of the relationship to use
* for members of this collection.
* Sets the name of the relationship to use
* for members of this collection.
* Returns FALSE on failure.
*
* @param string $relationship
@ -77,8 +77,8 @@ class CollectionPolicy {
}
/**
* Removes the specified content model from the collection policy. This will only
* prevent future ingests of the removed model to the collection. $cm should be
* Removes the specified content model from the collection policy. This will only
* prevent future ingests of the removed model to the collection. $cm should be
* a valid ContentModel object. Returns FALSE on failure or when the CM was not found in
* the collection policy.
*
@ -109,7 +109,7 @@ class CollectionPolicy {
* addModel ??
* @param ContentModel $cm
* @param type $namespace
* @return type
* @return type
*/
function addModel($cm, $namespace) {
$ret = FALSE;
@ -141,7 +141,7 @@ class CollectionPolicy {
/**
* getName ??
* @return type
* @return type
*/
function getName() {
$ret = FALSE;
@ -151,101 +151,4 @@ class CollectionPolicy {
return $ret;
}
/**
* valid_pid
* Validates a fedora PID based on the regexp provided in the fedora
* 3.3 documentation.
* http://www.fedora-commons.org/confluence/display/FCR30/Fedora+Identifiers
*
* @param String $pid
* @return boolean $valid
*/
public static function valid_pid($pid) {
$valid = FALSE;
if (strlen(trim($pid)) <= 64 && preg_match('/^([A-Za-z0-9]|-|\.)+:(([A-Za-z0-9])|-|\.|~|_|(%[0-9A-F]{2}))+$/', trim($pid))) {
$valid = TRUE;
}
return $valid;
}
/**
* Validates the XMLDatastream against the schema location
* defined by the xmlns:schemaLocation attribute of the root
* element. If the xmlns:schemaLocation attribute does not exist,
* then it is assumed to be the old schema and it attempts to convert
* using the convertFromOldSchema method.
*
* TODO: Maybe change it so that it always validates against a known
* schema. This makes more sense because this class assumes the structure
* to be known after it has been validated.
*
* @return boolean $valid
*/
public function validate() {
global $user;
if ($this->valid === NULL) {
$ret = TRUE;
if ($this->xml == NULL) {
$this->fetchXml();
}
// figure out if we're dealing with a new or old schema
$rootEl = $this->xml->firstChild;
if (!$rootEl->hasAttributes() || $rootEl->attributes->getNamedItem('schemaLocation') === NULL) {
//$tmpname = substr($this->pid, strpos($this->pid, ':') + 1);
$tmpname = user_password(10);
$this->convertFromOldSchema();
drupal_add_js("fedora_repository_print_new_schema_$tmpname = function(tagID) {
var target = document.getElementById(tagID);
var content = target.innerHTML;
var text = '<html><head><title>Title' +
'</title><body>' + content +'</body></html>';
printerWindow = window.open('', '', 'toolbar=no,location=no,' + 'status=no,menu=no,scrollbars=yes,width=650,height=400');
printerWindow.document.open();
printerWindow.document.write(text);
}", 'inline');
if (user_access('administer site configuration')) {
drupal_set_message('<span id="new_schema_' . $tmpname . '" style="display: none;">' . htmlentities($this->xml->saveXML()) . '</span>Warning: XMLDatastream performed conversion of \'' . $this->getIdentifier() . '\' from old schema. Please update the datastream. The new datastream contents are <a href="javascript:fedora_repository_print_new_schema_' . $tmpname . '(\'new_schema_' . $tmpname . '\')">here.</a> ');
}
$rootEl = $this->xml->firstChild;
}
$schemaLocation = NULL;
if ($this->forceSchema) {
// hack because you cant easily get the static property value from
// a subclass.
$vars = get_class_vars(get_class($this));
$schemaLocation = $vars['SCHEMA_URI'];
}
elseif ($rootEl->attributes->getNamedItem('schemaLocation') !== NULL) {
//figure out where the schema is located and validate.
list(, $schemaLocation) = preg_split('/\s+/', $rootEl->attributes->getNamedItem('schemaLocation')->nodeValue);
}
$schemaLocation = NULL;
return TRUE;
if ($schemaLocation !== NULL) {
if (!$this->xml->schemaValidate($schemaLocation)) {
$ret = FALSE;
$errors = libxml_get_errors();
foreach ($errors as $err) {
self::$errors[] = 'XML Error: Line ' . $err->line . ': ' . $err->message;
}
}
else {
$this->name = $rootEl->attributes->getNamedItem('name')->nodeValue;
}
}
else {
$ret = FALSE;
self::$errors[] = 'Unable to load schema.';
}
$this->valid = $ret;
}
return $this->valid;
}
}

26
islandora_basic_collection/includes/DeleteCollection.inc

@ -1,5 +1,10 @@
<?php
/**
* @file
* DeleteCollection.inc
*/
/**
*
* @param array $form_state
@ -15,6 +20,11 @@ function islandora_collection_deletion_form($form, &$form_state, $pid) {
$submit_text_message = ($table) ? "Delete Selected Objects" : "Delete Collection";
$form = array();
$form['collection_delete']['titlebox'] = array(
'#type' => 'item',
'#title' => t("Delete objects from @collection_pid", array('@collection_pid' => $pid)),
);
if ($table) {
$form['collection_delete']['table'] = array(
@ -49,10 +59,10 @@ function islandora_collection_deletion_form($form, &$form_state, $pid) {
function islandora_collection_deletion_form_submit($form, &$form_state) {
global $user;
module_load_include('inc', 'islandora', 'RestConnection');
$restConnection = new RestConnection();
$rest_connection = new RestConnection();
$collection_pid = $form_state['values']['current'];
$fedora_object = new FedoraObject($collection_pid, $restConnection->repository);
$fedora_object = new FedoraObject($collection_pid, $rest_connection->repository);
$parents = $fedora_object->relationships->get(NULL, 'isMemberOfCollection');
$parents = Islandora_collections_get_collection_from_pid($collection_pid);
$collection_pid = $form_state['values']['current'];
@ -75,18 +85,18 @@ function islandora_collection_deletion_form_submit($form, &$form_state) {
}
}
if (!empty($populated_child_collections)) {
$conflict = false;
$conflict = FALSE;
foreach ($populated_child_collections as $collection) {
if (in_array($collection, $pids)) {
$conflict = true;
drupal_set_message("Populated child collections were not deleted.");
$conflict = TRUE;
drupal_set_message(t("Populated child collections were not deleted."));
}
}
}
$pids_to_delete = array_diff($pids, $populated_child_collections);
foreach ($pids_to_delete as $pid_to_delete) {
$restConnection->repository->purgeObject($pid_to_delete);
$rest_connection->repository->purgeObject($pid_to_delete);
}
drupal_goto("islandora/object/" . $collection_pid);
}
@ -94,8 +104,8 @@ function islandora_collection_deletion_form_submit($form, &$form_state) {
function delete_root_collection($pid) {
module_load_include('inc', 'islandora', 'RestConnection');
try {
$restConnection = new RestConnection();
$restConnection->repository->purgeObject($pid);
$rest_connection = new RestConnection();
$rest_connection->repository->purgeObject($pid);
} catch (Exception $e) {
drupal_set_message(t("Collection '@pid' could not be deleted!", array('@pid' => $pid)), 'error');
return;

37
islandora_basic_collection/includes/ManagePolicies.inc

@ -1,16 +1,28 @@
<?php
/**
* @file
* ManagePolicies.inc
*/
/**
*
* @param type $form
* @param type $form_state
* @param type $collection_pid
* @return type
*/
function islandora_manage_policies_form($form, &$form_state, $collection_pid) {
module_load_include('inc', 'islandora_basic_collection', 'includes/CollectionPolicy');
module_load_include('inc', 'islandora', 'RestConnection');
$restConnection = new RestConnection();
$rest_connection = new RestConnection();
$content_models = get_content_models_list($collection_pid);
$cm_options = array();
$name_mappings = array();
foreach ($content_models as $content_model) {
if ($content_model != "islandora:collectionCModel") {
$item = new FedoraObject($content_model, $restConnection->repository);
$item = new FedoraObject($content_model, $rest_connection->repository);
$cm_name = $item->Label;
$cm_options[$content_model] = $cm_name;
}
@ -24,7 +36,7 @@ function islandora_manage_policies_form($form, &$form_state, $collection_pid) {
$namespace = substr($collection_pid, 0, strpos($collection_pid, ":"));
$collection_policy_dsid = variable_get('Islandora_Collection_Policy_DSID', 'COLLECTION_POLICY');
$collection_object = new FedoraObject($collection_pid, $restConnection->repository);
$collection_object = new FedoraObject($collection_pid, $rest_connection->repository);
$collection_policy_string = $collection_object->getDatastream($collection_policy_dsid);
$supported_collection_models = array();
@ -50,6 +62,11 @@ function islandora_manage_policies_form($form, &$form_state, $collection_pid) {
$new_options = array_diff_key($new_content_models, $current_models_in_policy);
}
$form['manage_collection_policy']['titlebox'] = array(
'#type' => 'item',
'#title' => t("Manage collection policy for @collection_pid", array('@collection_pid' => $collection_pid)),
);
$form ['manage_collection_policy']['add']['content_model_to_add'] = array(
'#title' => "Choose Content Model",
'#type' => 'select',
@ -96,7 +113,6 @@ function islandora_manage_policies_form($form, &$form_state, $collection_pid) {
'#description' => t("Choose content models to remove from this collection policy."),
);
$form['manage_collection_policy']['remove']['submit'] = array(
'#type' => 'submit',
'#value' => t('Remove Content Model From Collection Policy'),
@ -107,16 +123,16 @@ function islandora_manage_policies_form($form, &$form_state, $collection_pid) {
}
function islandora_manage_policies_form_validate($form, &$form_state) {
}
function islandora_manage_policies_form_submit($form, &$form_state) {
module_load_include('inc', 'islandora_basic_collection', 'CollectionPolicy');
module_load_include('inc', 'islandora', 'RestConnection');
$restConnection = new RestConnection();
$rest_connection = new RestConnection();
$collection_pid = $form_state['values']['parent_collection'];
$collection_object = new FedoraObject($collection_pid, $restConnection->repository);
$collection_object = new FedoraObject($collection_pid, $rest_connection->repository);
$policy = $collection_object->getDatastream(variable_get('Islandora_Collection_Policy_DSID', 'COLLECTION_POLICY'));
$collection_policy = '<?xml version="1.0" encoding="UTF-8"?>
<collection_policy xmlns="http://www.islandora.ca" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="" xsi:schemaLocation="http://www.islandora.ca http://syn.lib.umanitoba.ca/collection_policy.xsd">
@ -143,7 +159,7 @@ function islandora_manage_policies_form_submit($form, &$form_state) {
$cp_namespace = $form_state['values']['new_cp_namespace'];
$cp_content_model = $form_state['values']['content_model_to_add'];
$content_model_object = new FedoraObject($cp_content_model, $restConnection->repository);
$content_model_object = new FedoraObject($cp_content_model, $rest_connection->repository);
$content_model_datastream = $content_model_object->getDatastream(variable_get('Islandora_Content_Model_DSID', 'ISLANDORACM'));
$content_models_element = $collection_policy_xml->getElementsByTagName('content_models');
@ -160,7 +176,7 @@ function islandora_manage_policies_form_submit($form, &$form_state) {
$new_collection_policy_datastream->setContentFromString($collection_policy_xml->saveXML());
$new_collection_policy_datastream->label = 'COLLECTION_POLICY';
$collection_object->ingestDatastream($new_collection_policy_datastream);
drupal_set_message("Collection model successfully added");
drupal_set_message(t("Collection model @model successfully added", array('@model' => $content_model_object->label)));
}
//remove content model from collection policy
@ -170,7 +186,6 @@ function islandora_manage_policies_form_submit($form, &$form_state) {
$s = '';
foreach ($candidates as $candidate) {
if (is_string($candidate)) {
$content_models_element = $collection_policy_xml->getElementsByTagName('content_models');
$models = $content_models_element->item(0)->getElementsByTagName('content_model');
$found = FALSE;
@ -195,7 +210,7 @@ function islandora_manage_policies_form_submit($form, &$form_state) {
if ($count > 1) {
$s = 's';
}
drupal_set_message("$count collection model$s removed");
drupal_set_message(t("$count collection model@s removed", array('@s' => $s)));
}
}
}

18
islandora_basic_collection/includes/MoveCollection.inc

@ -1,5 +1,10 @@
<?php
/**
* @file
* MoveCollection.inc
*/
/**
*
* @param array $form_state
@ -16,9 +21,14 @@ function islandora_collection_migrate_form($form, &$form_state, $pid) {
}
$form = array();
$form['migrate']['titlebox'] = array(
'#type' => 'item',
'#title' => t("Move objects from @collection_pid", array('@collection_pid' => $pid)),
);
$form['migrate']['new_collection'] = array(
'#title' => t('New Collection'),
'#description' => t("All content will be migrated from $pid to the selected collection"),
'#description' => t("All content will be migrated from @pid to the selected collection", array('@pid' => $pid)),
'#type' => 'select',
'#options' => $potential_collections,
);
@ -34,7 +44,7 @@ function islandora_collection_migrate_form($form, &$form_state, $pid) {
'#type' => 'item',
'#value' => t(""),
);
$form['migrate']['submit'] = array(
'#type' => 'submit',
'#value' => t('Migrate selected objects'),
@ -44,13 +54,13 @@ function islandora_collection_migrate_form($form, &$form_state, $pid) {
function islandora_collection_migrate_form_submit($form, &$form_state) {
module_load_include('inc', 'islandora', 'RestConnection');
$restConnection = new RestConnection();
$rest_connection = new RestConnection();
$pids = array_filter($form_state['values']['table']);
$new_collection = $form_state['values']['new_collection'];
$current = $form_state['values']['current'];
foreach ($pids as $pid) {
$fedora_object = new FedoraObject($pid, $restConnection->repository);
$fedora_object = new FedoraObject($pid, $rest_connection->repository);
$fedora_object->relationships->remove(FEDORA_RELS_EXT_URI, 'isMemberOfCollection', $current);
$fedora_object->relationships->add(FEDORA_RELS_EXT_URI, 'isMemberOfCollection', $new_collection);
}

61
islandora_basic_collection/islandora_basic_collection.install

@ -1,95 +1,94 @@
<?php
/**
* @file islandora_basic_collection.install
* @file
* islandora_basic_collection.install
*/
function islandora_basic_collection_install() {
module_load_include('inc', 'islandora', 'RestConnection');
global $user;
global $base_root;
try {
$restConnection = new RestConnection($user);
$rest_connection = new RestConnection($user);
} catch (Exception $e) {
drupal_set_message(t('Unable to connect to the repository %e', array('%e' => $e)), 'error');
drupal_set_message(st('Unable to connect to the repository %e', array('%e' => $e)), 'error');
return;
}
$content_model_query = $restConnection->api->a->findObjects('query', 'pid=islandora:collectionCModel');
$content_model_query = $rest_connection->api->a->findObjects('query', 'pid=islandora:collectionCModel');
if (empty($content_model_query['results'])) {
try {
$xml = file_get_contents(drupal_get_path('module', 'islandora_basic_collection') . '/xml/islandora_collection_CModel.xml');
$restConnection->api->m->ingest(array('string' => $xml));
$rest_connection->api->m->ingest(array('string' => $xml));
} catch (Exception $e) {
drupal_set_message(t('Unable to install content models %e', array('%e' => $e)), 'error');
drupal_set_message(st('Unable to install content models %e', array('%e' => $e)), 'error');
return;
}
drupal_set_message(t('Content models installed!'));
drupal_set_message(st('Content models installed!'));
}
else {
drupal_set_message(t('Content models already exist!'), 'warning');
drupal_set_message(st('Content models already exist!'), 'warning');
}
$collection_query = $restConnection->api->a->findObjects('query', 'pid=islandora:root');
$collection_query = $rest_connection->api->a->findObjects('query', 'pid=islandora:root');
if (empty($collection_query['results'])) {
try {
$xml = file_get_contents(drupal_get_path('module', 'islandora_basic_collection') . '/xml/islandora_root_collection.xml');
$restConnection->api->m->ingest(array('string' => $xml));
$fedora_object = new FedoraObject('islandora:root', $restConnection->repository);
$datastream = new NewFedoraDatastream('TN', 'M', $fedora_object, $restConnection->repository);
$rest_connection->api->m->ingest(array('string' => $xml));
$fedora_object = new FedoraObject('islandora:root', $rest_connection->repository);
$datastream = new NewFedoraDatastream('TN', 'M', $fedora_object, $rest_connection->repository);
$file_path = $base_root . '/' . drupal_get_path('module', 'islandora_basic_collection') . '/Crystal_Clear_filesystem_folder_grey.png';
$datastream->label = 'Thumbnail';
$datastream->mimetype = 'image/png';
$datastream->setContentFromUrl($file_path);
$fedora_object->ingestDatastream($datastream);
} catch (Exception $e) {
drupal_set_message(t('Unable to install collections %e', array('%e' => $e)), 'error');
drupal_set_message(st('Unable to install collections %e', array('%e' => $e)), 'error');
return;
}
drupal_set_message(t('Collections installed!'));
drupal_set_message(st('Collections installed!'));
}
else {
drupal_set_message(t('Collections already exist!'), 'warning');
drupal_set_message(st('Collections already exist!'), 'warning');
}
}
function islandora_basic_collection_uninstall() {
module_load_include('inc', 'islandora', 'RestConnection');
module_load_include('inc', 'islandora', 'RestConnection');
global $user;
try {
$restConnection = new RestConnection($user);
$rest_connection = new RestConnection($user);
} catch (Exception $e) {
drupal_set_message(t('Unable to connect to the repository %e', array('%e' => $e)), 'error');
drupal_set_message(st('Unable to connect to the repository %e', array('%e' => $e)), 'error');
return;
}
$content_model_query = $restConnection->api->a->findObjects('query', 'pid=islandora:collectionCModel');
$content_model_query = $rest_connection->api->a->findObjects('query', 'pid=islandora:collectionCModel');
if (!empty($content_model_query['results'])) {
try {
$restConnection->repository->purgeObject('islandora:collectionCModel');
$rest_connection->repository->purgeObject('islandora:collectionCModel');
} catch (Exception $e) {
drupal_set_message(t('Unable to purge content models %e', array('%e' => $e)), 'error');
drupal_set_message(st('Unable to purge content models %e', array('%e' => $e)), 'error');
return;
}
drupal_set_message(t('Content models purged!'));
drupal_set_message(st('Content models purged!'));
}
else {
drupal_set_message(t('Content models don\'t exist!'), 'warning');
drupal_set_message(st('Content models don\'t exist!'), 'warning');
}
$collection_query = $restConnection->api->a->findObjects('query', 'pid=islandora:root');
$collection_query = $rest_connection->api->a->findObjects('query', 'pid=islandora:root');
if (!empty($collection_query['results'])) {
try {
$restConnection->repository->purgeObject('islandora:root');
$rest_connection->repository->purgeObject('islandora:root');
} catch (Exception $e) {
drupal_set_message(t('Unable to purge collections %e', array('%e' => $e)), 'error');
drupal_set_message(st('Unable to purge collections %e', array('%e' => $e)), 'error');
return;
}
drupal_set_message(t('Collections purged!'));
drupal_set_message(st('Collections purged!'));
}
else {
drupal_set_message(t('Collections don\'t exist!'), 'warning');
drupal_set_message(st('Collections don\'t exist!'), 'warning');
}
}

32
islandora_basic_collection/islandora_basic_collection.module

@ -1,29 +1,30 @@
<?php
/*
* @file islandora_basic_image.module
*
* an Islandora module to handle basic image cmodels
*
*
* @file
* islandora_basic_collection.module
*
* an Islandora module to handle basic image cmodels
*
*
* This file is part of Islandora.
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with the program. If not, see <http ://www.gnu.org/licenses/>.
*/
/**
* Implementation of hook_menu.
* Implements hook_menu().
* we need some standard entry points so we can have consistent urls for different Object actions
*/
function islandora_basic_collection_menu() {
@ -63,7 +64,7 @@ function islandora_basic_collection_menu() {
/**
* This function is where we create the view for the related menu item
* @param type $object_id
* @return type
* @return type
*/
function islandora_basic_collection_manage_object($object_id) {
@ -73,6 +74,7 @@ function islandora_basic_collection_manage_object($object_id) {
module_load_include('inc', 'islandora_basic_collection', 'includes/MoveCollection');
module_load_include('inc', 'islandora_basic_collection', 'includes/ChildCollection');
module_load_include('inc', 'islandora_basic_collection', 'includes/ManagePolicies');
module_load_include('inc', 'islandora_basic_collection', 'includes/ChangeContentModels');
$form = array();
@ -105,9 +107,7 @@ function islandora_basic_collection_manage_object($object_id) {
'#collapsed' => TRUE,
);
$form['collection_manager']['change_content_models']['form'] = array(
// '#content' => drupal_get_form($form_id),
);
$form['collection_manager']['change_content_models']['form'] = drupal_get_form('islandora_change_content_models_form', $object_id);
$form['collection_manager']['migrate_members'] = array(
'#type' => 'fieldset',
@ -136,7 +136,7 @@ function islandora_basic_collection_manage_object($object_id) {
* determines whether or not to show this modules manage tab
* @global object $user
* @param string $object_id
* @return boolean
* @return boolean
*/
function islandora_basic_collection_access($object_id) {
module_load_include('inc', 'islandora', 'RestConnection');
@ -188,7 +188,7 @@ function islandora_basic_collection_theme($existing, $type, $theme, $path) {
* this module should attempt to respond.
* If ISLANDORA_VIEW_HOOK = TRUE this function will populate the default tab. This should be configurable
* in the modules admin section, otherwise two modules can populate one tab.
* @return array
* @return array
* array of content model pids that this module supports
*/
function islandora_basic_collection_islandora_get_types() {
@ -226,7 +226,7 @@ function islandora_basic_collection_islandora_view_object($object, $user, $page_
/**
*
* @global type $base_url
* @param array $variables
* @param array $variables
* an array of variables that will be passed to the theme function
*/
function islandora_basic_collection_preprocess_islandora_basic_collection(&$variables) {

Loading…
Cancel
Save