From 74bcd0664c2f21a9cfff72c7193aa073bc859ae4 Mon Sep 17 00:00:00 2001 From: Paul Pound Date: Fri, 1 Jun 2012 09:53:56 -0300 Subject: [PATCH 1/8] updated islandora api documentation --- islandora.api.php | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/islandora.api.php b/islandora.api.php index 96b283a3..b57c1a0a 100644 --- a/islandora.api.php +++ b/islandora.api.php @@ -2,13 +2,13 @@ function hook_islandora_purge_datastream ($object_id, $datastream_id){} -function hook_islandora_purge_object($object_id) {} +function hook_islandora_purge_object($object) {} -function hook_islandora_view_object($object_id){} +function hook_islandora_view_object($object){} function hook_islandora_get_types(){} -function hook_islandora_add_datastream($object_id) {} +function hook_islandora_add_datastream($object) {} /** * creates and populates a php Fedora object. @@ -25,4 +25,20 @@ function hook_islandora_datastream_edit($object, $dsid){} * array('name' => t('Ingest Route Name'), 'url' => 'ingest_route/url', 'weight' => 0), * ); */ -function hook_islandora_ingest_registry($collection_pid) {} \ No newline at end of file +function hook_islandora_ingest_registry($collection_pid) {} + + +/** + * alter an object before it gets used further down the stack + * @param type $object + * a tuque FedoraObject + */ +function hook_islandora_object_alter ($fedora_object){} + +/** + * insert or remove rendered elements by implementing this function + * in your module + * @param type $arr + * an arr of rendered views + */ +function hook_islandora_display_alter ($arr){} \ No newline at end of file From 633391b9e4c5008c8575f8a7d5738226eba70064 Mon Sep 17 00:00:00 2001 From: Danny Joris Date: Fri, 1 Jun 2012 10:02:31 -0300 Subject: [PATCH 2/8] added configure paths to .info files --- islandora.info | 1 + islandora_basic_collection/islandora_basic_collection.info | 1 + islandora_basic_image/islandora_basic_image.info | 1 + 3 files changed, 3 insertions(+) diff --git a/islandora.info b/islandora.info index 6d2cfb99..aae6bc98 100644 --- a/islandora.info +++ b/islandora.info @@ -3,5 +3,6 @@ description = "View and manage Fedora objects" package = Islandora version = 7.x-dev core = 7.x +configure = admin/islandora/configure stylesheets[all][] = css/islandora.base.css stylesheets[all][] = css/islandora.theme.css \ No newline at end of file diff --git a/islandora_basic_collection/islandora_basic_collection.info b/islandora_basic_collection/islandora_basic_collection.info index 7663b814..bf2e6387 100644 --- a/islandora_basic_collection/islandora_basic_collection.info +++ b/islandora_basic_collection/islandora_basic_collection.info @@ -3,5 +3,6 @@ description = "A default Islandora Repository module to handle simple collection dependencies[] = islandora package = Islandora core = 7.x +configure = admin/islandora/basic_collection stylesheets[all][] = css/islandora_basic_collection.base.css stylesheets[all][] = css/islandora_basic_collection.theme.css \ No newline at end of file diff --git a/islandora_basic_image/islandora_basic_image.info b/islandora_basic_image/islandora_basic_image.info index 26426dd0..459d1bbc 100644 --- a/islandora_basic_image/islandora_basic_image.info +++ b/islandora_basic_image/islandora_basic_image.info @@ -3,5 +3,6 @@ description = "A default Islandora Repository module to handle images" dependencies[] = islandora package = Islandora core = 7.x +configure = admin/islandora/basic_image stylesheets[all][] = css/islandora_basic_image.base.css stylesheets[all][] = css/islandora_basic_image.theme.css \ No newline at end of file From 3dd37810c199fd401166cf6c7384a8977a928288 Mon Sep 17 00:00:00 2001 From: rwincewicz Date: Fri, 1 Jun 2012 10:31:22 -0300 Subject: [PATCH 3/8] Fixed issue with child collections not being created --- islandora_basic_collection/includes/child_collection.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/islandora_basic_collection/includes/child_collection.inc b/islandora_basic_collection/includes/child_collection.inc index f696286a..e1204a41 100644 --- a/islandora_basic_collection/includes/child_collection.inc +++ b/islandora_basic_collection/includes/child_collection.inc @@ -136,7 +136,7 @@ function islandora_create_child_collection_form_submit($form, &$form_state) { $new_collection_pid = $form_state['values']['new_collection_pid']; $this_collection_pid = $form_state['values']['current']; if(empty($new_collection_pid)) { - $collection_namespace = substr($this_collection_pid, 0, strpos($this_collection_pid, ":")); + $new_collection_pid = substr($this_collection_pid, 0, strpos($this_collection_pid, ":")); } $new_collection_label = $form_state['values']['collection_name']; $namespace = $form_state['values']['collection_namespace']; @@ -185,5 +185,5 @@ function islandora_create_child_collection_form_submit($form, &$form_state) { $fedora_object->ingestDatastream($policy_datastream); $new_fedora_object = islandora_ingest_add_object($fedora_object); - drupal_goto('/islandora/object/' . $new_collection_pid); + drupal_goto('/islandora/object/' . $new_fedora_object->id); } \ No newline at end of file From c3b3ee15305a8f0ace2b08240d330adb867a16d1 Mon Sep 17 00:00:00 2001 From: rwincewicz Date: Fri, 1 Jun 2012 10:50:07 -0300 Subject: [PATCH 4/8] Fixed restConnection line in manage collection policies --- islandora_basic_collection/includes/manage_policies.inc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/islandora_basic_collection/includes/manage_policies.inc b/islandora_basic_collection/includes/manage_policies.inc index 9207edb4..291c2cc8 100644 --- a/islandora_basic_collection/includes/manage_policies.inc +++ b/islandora_basic_collection/includes/manage_policies.inc @@ -137,6 +137,7 @@ function islandora_manage_policies_form_validate($form, &$form_state) { * @param array $form_state */ function islandora_manage_policies_form_submit($form, &$form_state) { + module_load_include('module', 'islandora', 'islandora'); $collection_pid = $form_state['values']['parent_collection']; $collection_object = islandora_object_load($collection_pid); @@ -166,7 +167,8 @@ 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, $rest_connection->repository); +// $content_model_object = new FedoraObject($cp_content_model, $rest_connection->repository); + $content_model_object = islandora_object_load($cp_content_model); $content_model_datastream = $content_model_object->getDatastream(variable_get('Islandora_Content_Model_DSID', 'ISLANDORACM')); $content_models_element = $collection_policy_xml->getElementsByTagName('content_models'); From c7a0e1319b923d6a6fe6d5c053b2b98cd9956649 Mon Sep 17 00:00:00 2001 From: Danny Joris Date: Fri, 1 Jun 2012 10:54:47 -0300 Subject: [PATCH 5/8] created helper function to connect to Fedora --- admin/islandora.admin.inc | 15 +++++---------- includes/utilities.inc | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/admin/islandora.admin.inc b/admin/islandora.admin.inc index 03ef48e7..8194520e 100644 --- a/admin/islandora.admin.inc +++ b/admin/islandora.admin.inc @@ -8,6 +8,7 @@ function islandora_repository_admin($form, &$form_state) { module_load_include('inc', 'islandora', 'includes/tuque'); + module_load_include('inc', 'islandora', 'includes/utilities'); if (!IslandoraTuque::exists()) { $message = t('This module requires the !url. Please install sites all libraries folder before continuing.', array('!url' => l(t('Tuque Fedora API'), 'http://github.com/islandora/tuque'))); @@ -24,16 +25,10 @@ function islandora_repository_admin($form, &$form_state) { $url = variable_get('islandora_base_url', 'http://localhost:8080/fedora'); } - $connection = new IslandoraTuque(NULL, $url); - try { - $info = $connection->api->a->describeRepository(); - $connected = TRUE; - } - catch (RepositoryException $e) { - $connected = FALSE; - } - - if($connected) { + // Connect to Fedora + $info = islandora_describe_repository($url); + + if($info) { $confirmation_message = '' . t('Successfully connected to Fedora Server (Version !version).', array('!version' => $info['repositoryVersion'])); } diff --git a/includes/utilities.inc b/includes/utilities.inc index edb49780..0a85a467 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -45,4 +45,27 @@ function islandora_control_group_to_human_readable($control_group) { default: return $control_group; } +} + +/** + * Helper function to describe a Fedora repository. + * + * Can be used to check if Fedora is available. + * + * @param $url + * A url to a Fedora repository. + * @return + * Returns an array describing the repository. Returns FALSE if Fedora is down + * or if the url is incorrect. + */ +function islandora_describe_repository($url) { + + $connection = new IslandoraTuque(NULL, $url); + try { + $info = $connection->api->a->describeRepository(); + return $info; + } + catch (RepositoryException $e) { + return FALSE; + } } \ No newline at end of file From ea91ee6dd30dc0e9430c5794ef5af8ff686afaa7 Mon Sep 17 00:00:00 2001 From: jonathangreen Date: Fri, 1 Jun 2012 11:07:02 -0300 Subject: [PATCH 6/8] Fix my mistakes in collection manager. --- includes/utilities.inc | 28 +++++++++++++++++++ .../includes/change_content_models.inc | 8 +++--- .../includes/child_collection.inc | 19 +++++++++++-- .../includes/collection_management.inc | 4 +-- .../includes/delete_collection.inc | 6 ++-- .../includes/manage_policies.inc | 2 +- .../includes/move_collection.inc | 3 +- 7 files changed, 56 insertions(+), 14 deletions(-) diff --git a/includes/utilities.inc b/includes/utilities.inc index edb49780..ff84e279 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -45,4 +45,32 @@ function islandora_control_group_to_human_readable($control_group) { default: return $control_group; } +} + +/** + * valid pid ?? + * @param type $pid + * @return boolean + */ +function islandora_validate_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; +} + +/** + * Valid Dsid ?? + * @param type $dsid + * @return boolean + */ +function islandora_validadte_dsid($dsid) { + $valid = FALSE; + if (strlen(trim($dsid)) <= 64 && preg_match('/^[a-zA-Z0-9\_\-\.]+$/', trim($dsid))) { + $valid = TRUE; + } + + return $valid; } \ No newline at end of file diff --git a/islandora_basic_collection/includes/change_content_models.inc b/islandora_basic_collection/includes/change_content_models.inc index 344d8643..42b7fa76 100644 --- a/islandora_basic_collection/includes/change_content_models.inc +++ b/islandora_basic_collection/includes/change_content_models.inc @@ -86,7 +86,7 @@ function islandora_change_content_models_form_submit($form, &$form_state) { $collection_pid = $form_state['values']['collection_pid']; $current_content_model_object = islandora_object_load($current_content_model); - $collection_object = islandora_load_object($form_state['values']['collection_pid']); + $collection_object = islandora_object_load($form_state['values']['collection_pid']); $collection_policy_datastream = $collection_object->getDatastream(variable_get('Islandora_Collection_Policy_DSID', 'COLLECTION_POLICY')); $policy = new CollectionPolicy($collection_policy_datastream->content); @@ -105,7 +105,7 @@ function islandora_change_content_models_form_submit($form, &$form_state) { } } if ($add_to_policy) { - $new_content_model_object = new FedoraObject($new_content_model, $rest_connection->repository); + $new_content_model_object = islandora_object_load($new_content_model); $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'); @@ -129,14 +129,14 @@ function islandora_change_content_models_form_submit($form, &$form_state) { or \$object ) and \$object )"; - $objects = $rest_connection->repository->ri->itqlQuery($query, 'unlimited', '0'); + $objects = $collection_object->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 = islandora_object_load($object['object']['value']); $fedora_item->relationships->remove(FEDORA_MODEL_URI, 'hasModel', $current_content_model); $fedora_item->relationships->add(FEDORA_MODEL_URI, 'hasModel', $new_content_model); $count++; diff --git a/islandora_basic_collection/includes/child_collection.inc b/islandora_basic_collection/includes/child_collection.inc index f696286a..68aac2f3 100644 --- a/islandora_basic_collection/includes/child_collection.inc +++ b/islandora_basic_collection/includes/child_collection.inc @@ -119,7 +119,20 @@ function islandora_create_child_collection_form($form, &$form_state, $collection } function islandora_create_child_collection_form_validate($form, &$form_state) { - + module_load_include('inc', 'islandora', 'includes/utilities'); + $new_collection_pid = $form_state['values']['new_collection_pid']; + if($new_collection_pid) { + $valid = islandora_validate_pid($new_collection_pid); + if(!$valid) { + form_set_error('new_collection_pid', 'Collection PID is Invalid.'); + } + else { + $object = islandora_object_load($new_collection_pid); + if($object !== NULL) { + form_set_error('new_collection_pid', 'Collection PID already exists.'); + } + } + } } /** @@ -136,7 +149,7 @@ function islandora_create_child_collection_form_submit($form, &$form_state) { $new_collection_pid = $form_state['values']['new_collection_pid']; $this_collection_pid = $form_state['values']['current']; if(empty($new_collection_pid)) { - $collection_namespace = substr($this_collection_pid, 0, strpos($this_collection_pid, ":")); + $new_collection_pid = substr($this_collection_pid, 0, strpos($this_collection_pid, ":")); } $new_collection_label = $form_state['values']['collection_name']; $namespace = $form_state['values']['collection_namespace']; @@ -185,5 +198,5 @@ function islandora_create_child_collection_form_submit($form, &$form_state) { $fedora_object->ingestDatastream($policy_datastream); $new_fedora_object = islandora_ingest_add_object($fedora_object); - drupal_goto('/islandora/object/' . $new_collection_pid); + drupal_goto('/islandora/object/' . $fedora_object->id); } \ No newline at end of file diff --git a/islandora_basic_collection/includes/collection_management.inc b/islandora_basic_collection/includes/collection_management.inc index f65da225..e51e76a0 100644 --- a/islandora_basic_collection/includes/collection_management.inc +++ b/islandora_basic_collection/includes/collection_management.inc @@ -37,7 +37,7 @@ function get_child_collections($object) { $query = << where \$object - and \$object + and \$object id> EOD; $lines = $object->repository->ri->itqlQuery($query, 'unlimited', '0'); @@ -49,7 +49,7 @@ function islandora_collections_get_collection_from_pid($object) { $query = 'select $parent from <#ri> where ($object $parent or $object $parent) - and $object \'' . $pid . '\' + and $object \'' . $object->id . '\' order by $object'; $object_pids = $object->repository->ri->itqlQuery($query, 'unlimited', '0'); diff --git a/islandora_basic_collection/includes/delete_collection.inc b/islandora_basic_collection/includes/delete_collection.inc index e6c415cf..6e4a4bb8 100644 --- a/islandora_basic_collection/includes/delete_collection.inc +++ b/islandora_basic_collection/includes/delete_collection.inc @@ -67,7 +67,7 @@ function islandora_collection_deletion_form($form, &$form_state, $object) { function islandora_collection_deletion_form_submit($form, &$form_state) { $collection_pid = $form_state['values']['current']; - $fedora_object = islandora_object_load($collection_object); + $fedora_object = islandora_object_load($collection_pid); $parents = $fedora_object->relationships->get(NULL, 'isMemberOfCollection'); $parents = islandora_collections_get_collection_from_pid($fedora_object); @@ -77,14 +77,14 @@ function islandora_collection_deletion_form_submit($form, &$form_state) { drupal_goto("islandora/object/" . $parents[0]['parent']['value']); } - $child_collections = get_child_collections($collection_pid); + $child_collections = get_child_collections($fedora_object); $populated_child_collections = array(); $pids = @array_filter($form_state['values']['table']); if (!empty($child_collections)) { foreach ($child_collections as $child) { - $child_pids = get_related_items_as_array(islandora_object_load($child), 'isMemberOfCollection'); + $child_pids = get_related_items_as_array(islandora_object_load($child['object']['value']), 'isMemberOfCollection'); if (!empty($child_pids)) { $populated_child_collections[] = $child; } diff --git a/islandora_basic_collection/includes/manage_policies.inc b/islandora_basic_collection/includes/manage_policies.inc index 9207edb4..bccec154 100644 --- a/islandora_basic_collection/includes/manage_policies.inc +++ b/islandora_basic_collection/includes/manage_policies.inc @@ -166,7 +166,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, $rest_connection->repository); + $content_model_object = islandora_object_load($cp_content_model); $content_model_datastream = $content_model_object->getDatastream(variable_get('Islandora_Content_Model_DSID', 'ISLANDORACM')); $content_models_element = $collection_policy_xml->getElementsByTagName('content_models'); diff --git a/islandora_basic_collection/includes/move_collection.inc b/islandora_basic_collection/includes/move_collection.inc index 04e31d51..e3e5d411 100644 --- a/islandora_basic_collection/includes/move_collection.inc +++ b/islandora_basic_collection/includes/move_collection.inc @@ -64,7 +64,6 @@ function islandora_collection_migrate_form($form, &$form_state, $object) { * @param array $form_state */ function islandora_collection_migrate_form_submit($form, &$form_state) { - $pids = array_filter($form_state['values']['table']); $new_collection = $form_state['values']['new_collection']; $current = $form_state['values']['current']; @@ -73,4 +72,6 @@ function islandora_collection_migrate_form_submit($form, &$form_state) { $fedora_object->relationships->remove(FEDORA_RELS_EXT_URI, 'isMemberOfCollection', $current); $fedora_object->relationships->add(FEDORA_RELS_EXT_URI, 'isMemberOfCollection', $new_collection); } + + drupal_set_message("@count objects successfully migrated!", array('@count' => count($pids))); } \ No newline at end of file From 03b22bf39c51490e9ff9034d293e0c7436e1ebd8 Mon Sep 17 00:00:00 2001 From: Paul Pound Date: Fri, 1 Jun 2012 11:16:26 -0300 Subject: [PATCH 7/8] updated islandora.api.inc documentation --- islandora.api.php | 86 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 78 insertions(+), 8 deletions(-) diff --git a/islandora.api.php b/islandora.api.php index 87a43d0a..7231dff9 100644 --- a/islandora.api.php +++ b/islandora.api.php @@ -1,23 +1,83 @@ Date: Fri, 1 Jun 2012 11:21:18 -0300 Subject: [PATCH 8/8] another collection fix --- islandora_basic_collection/includes/move_collection.inc | 2 -- 1 file changed, 2 deletions(-) diff --git a/islandora_basic_collection/includes/move_collection.inc b/islandora_basic_collection/includes/move_collection.inc index e3e5d411..f5a3703e 100644 --- a/islandora_basic_collection/includes/move_collection.inc +++ b/islandora_basic_collection/includes/move_collection.inc @@ -72,6 +72,4 @@ function islandora_collection_migrate_form_submit($form, &$form_state) { $fedora_object->relationships->remove(FEDORA_RELS_EXT_URI, 'isMemberOfCollection', $current); $fedora_object->relationships->add(FEDORA_RELS_EXT_URI, 'isMemberOfCollection', $new_collection); } - - drupal_set_message("@count objects successfully migrated!", array('@count' => count($pids))); } \ No newline at end of file