From c3c5b28adbb129f84c3d3df47009f708f1691caa Mon Sep 17 00:00:00 2001 From: rwincewicz Date: Tue, 29 May 2012 08:09:35 -0300 Subject: [PATCH 1/3] Added initial code for swapping content models in a collection --- .../islandora_basic_collection.admin.inc | 12 +- .../includes/ChangeContentModels.inc | 52 ++++++++ .../includes/ChildCollection.inc | 23 +++- .../includes/CollectionManagement.inc | 7 +- .../includes/CollectionManagerTable.inc | 22 ++-- .../includes/CollectionPolicy.inc | 115 ++---------------- .../includes/DeleteCollection.inc | 26 ++-- .../includes/ManagePolicies.inc | 37 ++++-- .../includes/MoveCollection.inc | 18 ++- .../islandora_basic_collection.install | 61 +++++----- .../islandora_basic_collection.module | 32 ++--- 11 files changed, 212 insertions(+), 193 deletions(-) create mode 100644 islandora_basic_collection/includes/ChangeContentModels.inc diff --git a/islandora_basic_collection/admin/islandora_basic_collection.admin.inc b/islandora_basic_collection/admin/islandora_basic_collection.admin.inc index 8311f3e8..6bef9d51 100644 --- a/islandora_basic_collection/admin/islandora_basic_collection.admin.inc +++ b/islandora_basic_collection/admin/islandora_basic_collection.admin.inc @@ -1,5 +1,14 @@ '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) { + +} \ No newline at end of file diff --git a/islandora_basic_collection/includes/ChildCollection.inc b/islandora_basic_collection/includes/ChildCollection.inc index a443bfc5..767c008b 100644 --- a/islandora_basic_collection/includes/ChildCollection.inc +++ b/islandora_basic_collection/includes/ChildCollection.inc @@ -1,8 +1,20 @@ 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.
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) { diff --git a/islandora_basic_collection/includes/CollectionManagement.inc b/islandora_basic_collection/includes/CollectionManagement.inc index a1856a0b..ead0f199 100644 --- a/islandora_basic_collection/includes/CollectionManagement.inc +++ b/islandora_basic_collection/includes/CollectionManagement.inc @@ -1,5 +1,10 @@ 'change_model', ); - return($form); + return $form; } /** diff --git a/islandora_basic_collection/includes/CollectionManagerTable.inc b/islandora_basic_collection/includes/CollectionManagerTable.inc index c1f91f99..7172652c 100644 --- a/islandora_basic_collection/includes/CollectionManagerTable.inc +++ b/islandora_basic_collection/includes/CollectionManagerTable.inc @@ -1,5 +1,10 @@ where ($object or $object ) and $object $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 $title and $object and $object ) 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)) { diff --git a/islandora_basic_collection/includes/CollectionPolicy.inc b/islandora_basic_collection/includes/CollectionPolicy.inc index 2302f58d..cbe261d1 100644 --- a/islandora_basic_collection/includes/CollectionPolicy.inc +++ b/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 = 'Title' + - '' + content +''; - 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('Warning: XMLDatastream performed conversion of \'' . $this->getIdentifier() . '\' from old schema. Please update the datastream. The new datastream contents are here. '); - } - - $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; - } - } diff --git a/islandora_basic_collection/includes/DeleteCollection.inc b/islandora_basic_collection/includes/DeleteCollection.inc index fdb51e9b..a8598095 100644 --- a/islandora_basic_collection/includes/DeleteCollection.inc +++ b/islandora_basic_collection/includes/DeleteCollection.inc @@ -1,5 +1,10 @@ '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; diff --git a/islandora_basic_collection/includes/ManagePolicies.inc b/islandora_basic_collection/includes/ManagePolicies.inc index a1dbe861..14a94a8b 100644 --- a/islandora_basic_collection/includes/ManagePolicies.inc +++ b/islandora_basic_collection/includes/ManagePolicies.inc @@ -1,16 +1,28 @@ 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 = ' @@ -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))); } } } \ No newline at end of file diff --git a/islandora_basic_collection/includes/MoveCollection.inc b/islandora_basic_collection/includes/MoveCollection.inc index 44caa7d9..26ff05d1 100644 --- a/islandora_basic_collection/includes/MoveCollection.inc +++ b/islandora_basic_collection/includes/MoveCollection.inc @@ -1,5 +1,10 @@ '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); } diff --git a/islandora_basic_collection/islandora_basic_collection.install b/islandora_basic_collection/islandora_basic_collection.install index 6b90190d..fbe6b7f5 100644 --- a/islandora_basic_collection/islandora_basic_collection.install +++ b/islandora_basic_collection/islandora_basic_collection.install @@ -1,95 +1,94 @@ $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'); } } \ No newline at end of file diff --git a/islandora_basic_collection/islandora_basic_collection.module b/islandora_basic_collection/islandora_basic_collection.module index a288e00d..ecebc374 100644 --- a/islandora_basic_collection/islandora_basic_collection.module +++ b/islandora_basic_collection/islandora_basic_collection.module @@ -1,29 +1,30 @@ . */ /** - * 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) { From 09d79a269725875510358abcad156688e48d7c92 Mon Sep 17 00:00:00 2001 From: rwincewicz Date: Wed, 30 May 2012 10:52:43 -0300 Subject: [PATCH 2/3] Change content models in collection is now working --- .../includes/ChangeContentModels.inc | 110 +++++++++++++++++- .../includes/ChildCollection.inc | 2 +- .../includes/CollectionManagement.inc | 44 +++---- .../includes/DeleteCollection.inc | 2 +- .../includes/ManagePolicies.inc | 10 +- 5 files changed, 131 insertions(+), 37 deletions(-) diff --git a/islandora_basic_collection/includes/ChangeContentModels.inc b/islandora_basic_collection/includes/ChangeContentModels.inc index 07362b69..b1f956da 100644 --- a/islandora_basic_collection/includes/ChangeContentModels.inc +++ b/islandora_basic_collection/includes/ChangeContentModels.inc @@ -6,9 +6,43 @@ */ function islandora_change_content_models_form($form, &$form_state, $collection_pid) { + module_load_include('inc', 'islandora_basic_collection', 'includes/CollectionPolicy'); + module_load_include('inc', 'islandora', 'RestConnection'); + $rest_connection = new RestConnection(); - $represented_content_models = get_represented_content_models($collection_pid); - var_dump($represented_content_models); + $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, $rest_connection->repository); + $cm_name = $item->Label; + $cm_options[$content_model] = $cm_name; + } + } + + $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, $rest_connection->repository); + $collection_policy_datastream = $collection_object->getDatastream($collection_policy_dsid); + + $supported_collection_models = array(); + if ($collection_policy_datastream->content) { + $collection_policy = new CollectionPolicy($collection_policy_datastream->content); + $supported_collection_models = $collection_policy->getContentModels(); + } + $collection_namespace = substr($collection_pid, 0, strpos($collection_pid, ":")); + + $collection_name = $collection_object->label; + $new_content_models = get_content_models_as_option_array(); + $current_models_in_policy = array(); + + if ($supported_collection_models) { + foreach ($supported_collection_models as $supported_model) { + $current_models_in_policy[$supported_model['pid']] = $supported_model['pid']; + } + } $form['change_cmodel']['titlebox'] = array( '#type' => 'item', @@ -18,7 +52,7 @@ function islandora_change_content_models_form($form, &$form_state, $collection_p $form['change_cmodel']['current_content_model'] = array( '#title' => "Choose content model to be changed", '#type' => 'select', - '#options' => $represented_content_models, + '#options' => $current_models_in_policy, '#description' => t("All objects in this collection with the selected content model will be changed."), ); @@ -31,12 +65,12 @@ function islandora_change_content_models_form($form, &$form_state, $collection_p $form['change_cmodel']['collection_pid'] = array( '#type' => 'hidden', - '#value' => $this_collection_pid, + '#value' => $collection_pid, ); $form['change_cmodel']['submit'] = array( '#type' => 'submit', - '#value' => t('Change Content Model Associations'), + '#value' => t('Change content model associations'), '#id' => 'change_model', ); @@ -44,9 +78,73 @@ function islandora_change_content_models_form($form, &$form_state, $collection_p } function islandora_change_content_models_form_validate($form, &$form_state) { - + } function islandora_change_content_models_form_submit($form, &$form_state) { + module_load_include('inc', 'islandora_basic_collection', 'includes/CollectionPolicy'); + module_load_include('inc', 'islandora', 'RestConnection'); + $rest_connection = new RestConnection(); + + $current_content_model = $form_state['values']['current_content_model']; + $new_content_model = $form_state['values']['new_content_model']; + $collection_pid = $form_state['values']['collection_pid']; + + $current_content_model_object = new FedoraObject($current_content_model, $rest_connection->repository); + + $collection_object = new FedoraObject($form_state['values']['collection_pid'], $rest_connection->repository); + $collection_policy_datastream = $collection_object->getDatastream(variable_get('Islandora_Collection_Policy_DSID', 'COLLECTION_POLICY')); + $policy = new CollectionPolicy($collection_policy_datastream->content); + + $collection_policy_xml = new DOMDocument(); + $collection_policy_xml->loadXML($collection_policy_datastream->content); + + $add_to_policy = TRUE; + $policy_content_models = $policy->getContentModels(); + foreach ($policy_content_models as $policy_content_model) { + if ($policy_content_model['pid'] == $current_content_model) { + $namespace = $policy_content_model['namespace']; + } + if ($policy_content_model['pid'] == $new_content_model) { + $add_to_policy = FALSE; + } + } + if ($add_to_policy) { + $new_content_model_object = new FedoraObject($new_content_model, $rest_connection->repository); + $new_content_model_datastream = $new_content_model_object->getDatastream(variable_get('Islandora_Content_Model_DSID', 'ISLANDORACM')); + $content_models_element = $collection_policy_xml->getElementsByTagName('content_models'); + $content_model_element = $content_models_element->item(0)->getElementsByTagName('content_model'); + + $content_model_element = $collection_policy_xml->createElement('content_model'); + $content_model_element->setAttribute('name', $new_content_model_object->label); + $content_model_element->setAttribute('dsid', variable_get('Islandora_Content_Model_DSID', 'ISLANDORACM')); + $content_model_element->setAttribute('namespace', $namespace); + $content_model_element->setAttribute('pid', $new_content_model_object->id); + $content_models_element->item(0)->appendChild($content_model_element); + $new_collection_policy_datastream = $collection_object->getDatastream('COLLECTION_POLICY'); + $new_collection_policy_datastream->setContentFromString($collection_policy_xml->saveXML()); + $new_collection_policy_datastream->label = 'COLLECTION_POLICY'; + $collection_object->ingestDatastream($new_collection_policy_datastream); + } + + $query = "select \$object from <#ri> + where (\$object + and (\$object + or \$object ) + and \$object )"; + + $objects = $rest_connection->repository->ri->itqlQuery($query, 'unlimited', '0'); + + $count = 0; + foreach ($objects as $object) { + if (!$object['object']['value']) { + continue; + } + $fedora_item = new FedoraObject($object['object']['value'], $rest_connection->repository); + $fedora_item->relationships->remove(FEDORA_MODEL_URI, 'hasModel', $current_content_model); + $fedora_item->relationships->add(FEDORA_MODEL_URI, 'hasModel', $new_content_model); + $count++; + } + drupal_set_message(t('@current_content_model changed to @new_content_model on @count objects', array('@current_content_model' => $current_content_model, '@new_content_model' => $new_content_model, '@count' => $count))); } \ No newline at end of file diff --git a/islandora_basic_collection/includes/ChildCollection.inc b/islandora_basic_collection/includes/ChildCollection.inc index 767c008b..682004dc 100644 --- a/islandora_basic_collection/includes/ChildCollection.inc +++ b/islandora_basic_collection/includes/ChildCollection.inc @@ -75,7 +75,7 @@ function islandora_create_child_collection_form($form, &$form_state, $this_colle $form['child_creation']['submit'] = array( '#type' => 'submit', - '#value' => t('Create Collection'), + '#value' => t('Create collection'), '#id' => 'create_child' ); return $form; diff --git a/islandora_basic_collection/includes/CollectionManagement.inc b/islandora_basic_collection/includes/CollectionManagement.inc index ead0f199..d72bf080 100644 --- a/islandora_basic_collection/includes/CollectionManagement.inc +++ b/islandora_basic_collection/includes/CollectionManagement.inc @@ -414,9 +414,9 @@ function collection_management_form_submit($form, &$form_state) { */ function delete_objects_as_batch($pid) { module_load_include('inc', 'islandora', 'RestConnection'); - $restConnection = new RestConnection(); + $rest_connection = new RestConnection(); $name = $user->name; - $restConnection->repository->purgeObject($pid); + $rest_connection->repository->purgeObject($pid); } /** @@ -425,8 +425,8 @@ function delete_objects_as_batch($pid) { */ function remove_collection_association($pid, $collection_pid) { module_load_include('inc', 'islandora', 'RestConnection'); - $restConnection = new RestConnection(); - $fedora_object = new FedoraObject($pid, $restConnection->repository); + $rest_connection = new RestConnection(); + $fedora_object = new FedoraObject($pid, $rest_connection->repository); $fedora_object->relationships->remove(NULL, 'isMemberOfCollection', $collection_pid); } @@ -437,7 +437,7 @@ function remove_collection_association($pid, $collection_pid) { */ function get_represented_content_models($pid) { module_load_include('inc', 'islandora', 'RestConnection'); - $restConnection = new RestConnection(); + $rest_connection = new RestConnection(); require_once 'sites/all/libraries/tuque/RepositoryQuery.php'; $query = "select \$model \$title from <#ri> @@ -446,12 +446,14 @@ where (\$object \$model and \$object \$title"; - $model_pids = $restConnection->repository->ri->itqlQuery($query, 'unlimited', '0'); + $model_pids = $rest_connection->repository->ri->itqlQuery($query, 'unlimited', '0'); $represented_models = array(); foreach ($model_pids as $model_pid) { - if ($model_pid && $model_pid['model']['value'] != 'fedora-system:FedoraObject-3.0') { - - $represented_models[$model_pid['model']['value']] = $model_pid['model']['value'] . ' ~ ' . $model_pid['title']['value']; + + if ($model_pid['model']['value'] && $model_pid['model']['value'] != 'fedora-system:FedoraObject-3.0') { + $fedora_object = new FedoraObject($model_pid['model']['value'], $rest_connection->repository); + $content_model_title = $fedora_object->label; + $represented_models[$model_pid['model']['value']] = $model_pid['model']['value'] . ' ~ ' . $content_model_title; } } return $represented_models; @@ -459,7 +461,7 @@ where (\$object EOD; - $lines = $restConnection->repository->ri->itqlQuery($query, 'unlimited', '0'); + $lines = $rest_connection->repository->ri->itqlQuery($query, 'unlimited', '0'); $collection_pids = array_values(array_filter($lines)); return $collection_pids; } function Islandora_collections_get_collection_from_pid($pid) { module_load_include('inc', 'islandora', 'RestConnection'); - $restConnection = new RestConnection(); + $rest_connection = new RestConnection(); require_once 'sites/all/libraries/tuque/RepositoryQuery.php'; $query = 'select $parent from <#ri> @@ -484,7 +486,7 @@ function Islandora_collections_get_collection_from_pid($pid) { and $object \'' . $pid . '\' order by $object'; - $object_pids = $restConnection->repository->ri->itqlQuery($query, 'unlimited', '0'); + $object_pids = $rest_connection->repository->ri->itqlQuery($query, 'unlimited', '0'); $object_pids = array_values(array_filter($object_pids)); return $object_pids; } @@ -499,7 +501,7 @@ function Islandora_collections_get_collection_from_pid($pid) { */ function get_related_items_as_array($collection_pid, $relationship = array('isMemberOfCollection'), $limit = 10000, $offset = 0, $active_objects_only = TRUE, $cmodel = NULL, $orderby = '$title') { module_load_include('inc', 'islandora', 'RestConnection'); - $restConnection = new RestConnection(); + $rest_connection = new RestConnection(); require_once 'sites/all/libraries/tuque/RepositoryQuery.php'; global $user; @@ -539,7 +541,7 @@ function get_related_items_as_array($collection_pid, $relationship = array('isMe minus $content order by ' . $orderby; - $results = $restConnection->repository->ri->itqlQuery($query_string, $limit, $offset); + $results = $rest_connection->repository->ri->itqlQuery($query_string, $limit, $offset); return $results; } @@ -573,13 +575,13 @@ function get_related_items_as_array($collection_pid, $relationship = array('isMe // $collectionHelper = new CollectionClass(); module_load_include('inc', 'islandora', 'RestConnection'); require_once 'sites/all/libraries/tuque/RepositoryQuery.php'; - $restConnection = new RestConnection(); + $rest_connection = new RestConnection(); $pids = array(); $query = 'select $object from <#ri> where $object and $object '; // $content_models = $collectionHelper->getRelatedItems($pid, $query); - $content_models = $restConnection->repository->ri->itqlQuery($query, 'unlimited', '0'); + $content_models = $rest_connection->repository->ri->itqlQuery($query, 'unlimited', '0'); if (empty($content_models)) { return $pids; @@ -609,7 +611,7 @@ function get_related_items_as_array($collection_pid, $relationship = array('isMe */ function get_content_models_as_option_array() { module_load_include('inc', 'islandora', 'RestConnection'); - $restConnection = new RestConnection(); + $rest_connection = new RestConnection(); require_once 'sites/all/libraries/tuque/RepositoryQuery.php'; $restricted = variable_get('fedora_namespace_restriction_enforced', TRUE); @@ -627,7 +629,7 @@ function get_content_models_as_option_array() { and $object ) order by $title'; - $list = $restConnection->repository->ri->itqlQuery($query, 'unlimited', '0'); + $list = $rest_connection->repository->ri->itqlQuery($query, 'unlimited', '0'); $options = array(); foreach ($list as $item) { //removes blanks if ($item) { @@ -646,10 +648,10 @@ function get_content_models_as_option_array() { function getContentModels($collection_pid, $showError = TRUE) { module_load_include('inc', 'islandora', 'RestConnection'); - $restConnection = new RestConnection(); + $rest_connection = new RestConnection(); // module_load_include('inc', 'Fedora_Repository', 'ContentModel'); $collection_stream = $this->getCollectionPolicyStream($collection_pid); - $collection_object = new FedoraObject($collection_pid, $restConnection->repository); + $collection_object = new FedoraObject($collection_pid, $rest_connection->repository); $collection_stream = $collection_object->getDatastream('COLLECTION_POLICY'); try { $xml = new SimpleXMLElement($collection_stream); diff --git a/islandora_basic_collection/includes/DeleteCollection.inc b/islandora_basic_collection/includes/DeleteCollection.inc index a8598095..42821e37 100644 --- a/islandora_basic_collection/includes/DeleteCollection.inc +++ b/islandora_basic_collection/includes/DeleteCollection.inc @@ -17,7 +17,7 @@ function islandora_collection_deletion_form($form, &$form_state, $pid) { $potential_collections = get_collections_as_option_array(); $table = islandora_collection_table($pid); $deletion_message = ($table) ? "Delete Members of this Collection" : "Delete Collection"; - $submit_text_message = ($table) ? "Delete Selected Objects" : "Delete Collection"; + $submit_text_message = ($table) ? "Delete selected objects" : "Delete collection"; $form = array(); diff --git a/islandora_basic_collection/includes/ManagePolicies.inc b/islandora_basic_collection/includes/ManagePolicies.inc index 14a94a8b..d4924c1b 100644 --- a/islandora_basic_collection/includes/ManagePolicies.inc +++ b/islandora_basic_collection/includes/ManagePolicies.inc @@ -28,11 +28,6 @@ function islandora_manage_policies_form($form, &$form_state, $collection_pid) { } } - $new_options = array(); - if (is_array($content_models) && is_array($cm_options)) { - $new_options = array_diff_key($content_models, $cm_options); - } - $namespace = substr($collection_pid, 0, strpos($collection_pid, ":")); $collection_policy_dsid = variable_get('Islandora_Collection_Policy_DSID', 'COLLECTION_POLICY'); @@ -94,7 +89,7 @@ function islandora_manage_policies_form($form, &$form_state, $collection_pid) { $form['manage_collection_policy']['add']['submit'] = array( '#type' => 'submit', - '#value' => t('Add Content Model to Collection Policy'), + '#value' => t('Add content model to collection policy'), '#id' => 'add_cm' ); @@ -115,7 +110,7 @@ function islandora_manage_policies_form($form, &$form_state, $collection_pid) { $form['manage_collection_policy']['remove']['submit'] = array( '#type' => 'submit', - '#value' => t('Remove Content Model From Collection Policy'), + '#value' => t('Remove content model from collection policy'), '#id' => 'remove_cm' ); } @@ -127,7 +122,6 @@ 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'); $rest_connection = new RestConnection(); From 97af81022d845f2bac13cb45cf660d40e738ea14 Mon Sep 17 00:00:00 2001 From: Mitchell MacKenzie Date: Wed, 30 May 2012 10:59:14 -0300 Subject: [PATCH 3/3] Fix RELS_EXT --- includes/islandora.ingest.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/islandora.ingest.inc b/includes/islandora.ingest.inc index 0aa310a6..b4c44720 100644 --- a/includes/islandora.ingest.inc +++ b/includes/islandora.ingest.inc @@ -13,9 +13,9 @@ function islandora_ingest_get_object($content_models, $collection_pid, $relation $connection = new RestConnection($user); $object = $connection->repository->constructObject($namespace); foreach($content_models as $content_model) { - $object->relationships->add(FEDORA_MODEL_URI, 'hasModel', $content_model); + $object->relationships->add(FEDORA_MODEL_URI, 'hasModel', $content_model['pid']); } - $object->relationships->add($relationship['uri'], $relationship['value'], $collection_pid); + $object->relationships->add(FEDORA_RELS_EXT_URI, $relationship, $collection_pid); module_invoke_all('islandora_ingest_pre_ingest', $object, $content_models, $collection_pid); return $object; }