From c57d2df00d44b64c716781b1a8bcea827706ac18 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Tue, 12 Mar 2013 12:43:09 -0300 Subject: [PATCH 001/172] Allow for altering of forms in the stepped ingest process. --- includes/ingest.form.inc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/includes/ingest.form.inc b/includes/ingest.form.inc index e2e97d5f..9434e9e4 100644 --- a/includes/ingest.form.inc +++ b/includes/ingest.form.inc @@ -295,11 +295,15 @@ function islandora_ingest_form_execute_step(array $form, array &$form_state) { * @return array * The stepified drupal form definition for the given step. */ -function islandora_ingest_form_stepify(array $form, array &$form_state) { +function islandora_ingest_form_stepify(array $form, array &$form_state, $step) { $first_step = islandora_ingest_form_on_first_step($form_state); $last_step = islandora_ingest_form_on_last_step($form_state); $form['prev'] = $first_step ? NULL : islandora_ingest_form_previous_button($form_state); $form['next'] = $last_step ? islandora_ingest_form_ingest_button($form_state) : islandora_ingest_form_next_button($form_state); + + // Allow for a hook_form_FORM_ID_alter(). + drupal_alter(array('form_' . $step['form_id'], 'form'), $form, $form_state, $step['form_id']); + return $form; } From 51e8f84023b210218c846e0d9cfa7e2caf7b099b Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Wed, 13 Mar 2013 01:51:47 +0100 Subject: [PATCH 002/172] Added a new function islandora_user_access() to simplify access callbacks. This function will check the given object/datastream against the given permissions and required content models using the given user. If no user is given the user identified by the GET token will be used, if no token is present the global user will be used. --- islandora.module | 82 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/islandora.module b/islandora.module index 94aedbe0..57ee5d9b 100644 --- a/islandora.module +++ b/islandora.module @@ -334,6 +334,88 @@ function islandora_forms($form_id) { return $forms; } +/** + * Checks whether the user can access the given object. + * + * Checks for repository access, object/datastream existance, namespace access, + * user permissions, content models. + * + * Will check the given user or the user repersented by the GET token parameter, + * failing that it will use the global user. + * + * @global $user + * + * @param mixed $object + * The FedoraObject or FedoraDatastream to test for accessibility, if NULL + * is given the object is assumed to not exist or be inaccessible. + * @param array $permissions + * The required user permissions. + * @param array $content_models + * The required content models. + * @param bool $access_any + * (optional) TRUE to grant access if any single requirement is met from both + * the permissions and content models parameters. FALSE if all requirements + * must be met from both the permissions and content model parameters. + * @param object $account + * (optional) The account to check, if not given check the GET parameters for + * a token to restore the user. If no GET parameter is present use currently + * logged in user. + * + * @return bool + * TRUE if the user is allowed to access this object/datastream, FALSE + * otherwise. + */ +function islandora_user_access($object, array $permissions, $content_models = array(), $access_any = TRUE, $account = NULL) { + module_load_include('inc', 'islandora', 'includes/utilities'); + $is_repository_accessible = &drupal_static(__FUNCTION__); + // If the repository is inaccessible then access always fails. + if (!isset($is_repository_accessible)) { + $is_repository_accessible = islandora_describe_repository(); + if (!$is_repository_accessible) { + // Only display the inaccessible message once. + islandora_display_repository_inaccessible_message(); + return FALSE; + } + } + if (!$is_repository_accessible || !is_object($object)) { + return FALSE; + } + // Determine the user account to test against. + if (!isset($account)) { + $token = filter_input(INPUT_GET, 'token', FILTER_SANITIZE_STRING); + if ($token) { + module_load_include('inc', 'islandora', 'includes/authtokens'); + $user = islandora_validate_object_token($object->id, $datastream->id, $token); + if ($user) { + $account = user_load($user->uid); + } + } + else { + global $user; + $account = $user; + } + } + // Determine what has been passed as $object. + if (is_subclass_of($object, 'FedoraObject')) { + $object = $object; + } + elseif (is_subclass_of($object, 'FedoraDatastream')) { + $datastream = $object; + $object = $datstream->parent; + } + // Check for access. + $accessible_namespace = islandora_namespace_accessible($object->id); + if ($access_any) { + $has_required_permissions = islandora_user_access_any($permissions, $account); + $has_required_content_models = empty($content_models) ? TRUE : count(array_intersect($object->models, $content_models)) > 0; + } + else { + $has_required_permissions = islandora_user_access_all($permissions, $account); + $has_required_content_models = count(array_diff($content_models, $object->models)) == 0; + } + return $accessible_namespace && $has_required_permissions && $has_required_content_models; +} + /** * Checks whether the user can access the given object. * From 6aa5226e58816e668a29e5bc30673d24bea4d17e Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Fri, 8 Mar 2013 15:25:20 +0100 Subject: [PATCH 003/172] Removed default ingest menu, ingest configuration can now take a object. Was not in use and excepting any parameters for the ingest process via GET was not very safe. Also the ingest configuration can now take an NewFedoraObject rather than building one from the configuration options. The old way is still supported for now though. --- includes/ingest.form.inc | 21 +++++++++-------- includes/ingest.menu.inc | 49 ---------------------------------------- 2 files changed, 12 insertions(+), 58 deletions(-) delete mode 100644 includes/ingest.menu.inc diff --git a/includes/ingest.form.inc b/includes/ingest.form.inc index 9434e9e4..ca6af592 100644 --- a/includes/ingest.form.inc +++ b/includes/ingest.form.inc @@ -96,15 +96,18 @@ function islandora_ingest_form_init_form_state_storage(array &$form_state, array */ function islandora_ingest_form_prepare_new_object(array $configuration) { module_load_include('inc', 'islandora', 'includes/utilities'); - // ID is more specific than namespace so it will take precedence. - $id = isset($configuration['namespace']) ? $configuration['namespace'] : 'islandora'; - $id = isset($configuration['id']) ? $configuration['id'] : $id; - $label = isset($configuration['label']) ? $configuration['label'] : 'New Object'; - $relationship_map = function($o) { - return array('relationship' => 'isMemberOfCollection', 'pid' => $o); - }; - $relationships = empty($configuration['collections']) ? array() : array_map($relationship_map, $configuration['collections']); - return islandora_prepare_new_object($id, $label, array(), array(), $relationships); + if (empty($configuration['object'])) { + // ID is more specific than namespace so it will take precedence. + $id = isset($configuration['namespace']) ? $configuration['namespace'] : 'islandora'; + $id = isset($configuration['id']) ? $configuration['id'] : $id; + $label = isset($configuration['label']) ? $configuration['label'] : 'New Object'; + $relationship_map = function($o) { + return array('relationship' => 'isMemberOfCollection', 'pid' => $o); + }; + $relationships = empty($configuration['collections']) ? array() : array_map($relationship_map, $configuration['collections']); + return islandora_prepare_new_object($id, $label, array(), array(), $relationships); + } + return $configuration['object']; } /** diff --git a/includes/ingest.menu.inc b/includes/ingest.menu.inc deleted file mode 100644 index a6f79891..00000000 --- a/includes/ingest.menu.inc +++ /dev/null @@ -1,49 +0,0 @@ -'; - // Redirect back to referer or top level collection. - drupal_goto($redirect); - } -} - -/** - * Fetches the ingest configuration from the $_GET parameters. - * - * Generic parameters as accepted by all ingest processes, other modules may - * add to this list. - * id -> The pid of the object to create. optional. - * models -> Comma delimited list of all the content models the created object - * should have. - * collections -> Comma delimited list of all the collections the created - * object should belong to. - * - * @return array - * The configuration options used to build the multi-paged ingest process. - */ -function islandora_ingest_get_configuration() { - $configuration = $_GET; - unset($configuration['q']); - $convert_to_array_keys = array_intersect(array('models', 'collections'), array_keys($configuration)); - foreach ($convert_to_array_keys as $key) { - $configuration[$key] = explode(',', $configuration[$key]); - } - return $configuration; -} From e7cc486d182a70ed1e1983d4011af85dd85e0d2f Mon Sep 17 00:00:00 2001 From: Jonathan Green Date: Wed, 13 Mar 2013 01:31:09 -0300 Subject: [PATCH 004/172] First try at getting travis building. --- .travis.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..ff5b51f5 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,26 @@ +language: php +php: + - 5.3 +before_script: + - mysql -u root -e 'create database drupal;' + - mysql -u root -e "create database fedora;" + - mysql -u root -e "GRANT ALL PRIVILEGES ON fedora.* To 'fedora'@'localhost' IDENTIFIED BY 'fedora';" + - mysql -u root -e "GRANT ALL PRIVILEGES ON drupal.* To 'drupal'@'localhost' IDENTIFIED BY 'drupal';" + - git clone git://github.com/Islandora/islandora_tomcat.git + - cd islandora_tomcat + - export CATALINA_HOME='.' + - ./bin/startup.sh + - cd .. + - pyrus channel-discover pear.drush.org + - pyrus install drush/drush + - phpenv rehash + - drush dl --yes drupal + - cd drupal-* + - drush si standard --db-url=mysql://drupal:drupal@localhost/drupal --yes + - drush en --yes simpletest + - drush cc all + - drush runserver --server=builtin 80 & + - sleep 4 + - drush vset --yes simpletest_verbose FALSE +script: + - drush test-run Syslog --xml --uri=http://127.0.0.1:8080 From ff0ed13e1f950fac62987e355d1ec8092e80861c Mon Sep 17 00:00:00 2001 From: Jonathan Green Date: Wed, 13 Mar 2013 02:52:53 -0300 Subject: [PATCH 005/172] Added a config for travis-ci This config will let islandora work with travis-ci. travis more travis This one should work. Test travis with apache. added sudo Added chown Fixed permissions... i hope.w Apache config back to non-apache Another try at a travis config Added some debug output woot Another update Added some debug data to sort out whats up with travis. more debug another More debug Perhaps this will finally work Revert "More debug" This reverts commit 508e993f4b02f7f3c9eb0d978514d0be89abbc78. Revert "another" This reverts commit cbf280eb4ebd22dda90788752787250a0ef71361. Revert "more debug" This reverts commit e6ce86ad77fdb89807c426adaa04a90a9955f343. Revert "Added some debug data to sort out whats up with travis." This reverts commit 5cb8e5b2f5dd20896f501a70167495b42d8f77f4. Holy jumping jesus it works. --- .travis.yml | 19 ++++++++++++++----- tests/travis.test_config.ini | 6 ++++++ 2 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 tests/travis.test_config.ini diff --git a/.travis.yml b/.travis.yml index ff5b51f5..fa7e5ca9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,26 +1,35 @@ language: php php: - 5.3 -before_script: +before_install: - mysql -u root -e 'create database drupal;' - mysql -u root -e "create database fedora;" - mysql -u root -e "GRANT ALL PRIVILEGES ON fedora.* To 'fedora'@'localhost' IDENTIFIED BY 'fedora';" - mysql -u root -e "GRANT ALL PRIVILEGES ON drupal.* To 'drupal'@'localhost' IDENTIFIED BY 'drupal';" + - cd $HOME + - sudo apt-get update -qq + - sudo apt-get install -qq php5-cgi + - sudo apt-get install -qq php5-mysql + - git clone git://github.com/Islandora/tuque.git - git clone git://github.com/Islandora/islandora_tomcat.git - cd islandora_tomcat - export CATALINA_HOME='.' - ./bin/startup.sh - - cd .. + - cd $HOME - pyrus channel-discover pear.drush.org - pyrus install drush/drush - phpenv rehash - drush dl --yes drupal - cd drupal-* - drush si standard --db-url=mysql://drupal:drupal@localhost/drupal --yes + - drush runserver 8081 > /dev/null & + - ln -s $TRAVIS_BUILD_DIR sites/all/modules/islandora + - mv sites/all/modules/islandora/tests/travis.test_config.ini sites/all/modules/islandora/tests/test_config.ini + - mkdir sites/all/libraries + - ln -s $HOME/tuque sites/all/libraries/tuque - drush en --yes simpletest + - drush en --user=1 --yes islandora - drush cc all - - drush runserver --server=builtin 80 & - sleep 4 - - drush vset --yes simpletest_verbose FALSE script: - - drush test-run Syslog --xml --uri=http://127.0.0.1:8080 + - drush test-run --uri=http://127.0.0.1:8081 Islandora diff --git a/tests/travis.test_config.ini b/tests/travis.test_config.ini new file mode 100644 index 00000000..61d63713 --- /dev/null +++ b/tests/travis.test_config.ini @@ -0,0 +1,6 @@ +[fedora] +fedora_url = "http://localhost:8080/fedora" +use_drupal_filter = TRUE +drupal_filter_file = "/home/travis/islandora_tomcat/fedora/server/config/filter-drupal.xml" +admin_user = "fedoraAdmin" +admin_pass = "fedoraAdmin" From d77c53492a7954f7daa7303728eea8698d338f24 Mon Sep 17 00:00:00 2001 From: Steve Osguthorpe Date: Mon, 18 Mar 2013 17:17:44 +0000 Subject: [PATCH 006/172] Created $keys variable to be passed by reference to stop PHP warning being shown. --- includes/ingest.form.inc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/includes/ingest.form.inc b/includes/ingest.form.inc index 9434e9e4..5742f3be 100644 --- a/includes/ingest.form.inc +++ b/includes/ingest.form.inc @@ -144,7 +144,8 @@ function islandora_ingest_form_get_step(array &$form_state, $step_id = NULL) { function islandora_ingest_form_get_current_step_id(array &$form_state) { if (empty($form_state['islandora']['step_id'])) { $steps = islandora_ingest_form_get_steps($form_state); - return array_shift(array_keys($steps)); + $keys = array_keys($steps); + return array_shift($keys); } return $form_state['islandora']['step_id']; } From 736c809c2eed3106c44f333b2e1ddd7082c53967 Mon Sep 17 00:00:00 2001 From: William Panting Date: Tue, 19 Mar 2013 17:25:56 -0300 Subject: [PATCH 007/172] Revived islandora_hooks_test module to get hook tests working --- tests/islandora_hooks_test.info | 7 ++ tests/islandora_hooks_test.module | 152 ++++++++++++++++++++++++++++++ 2 files changed, 159 insertions(+) create mode 100644 tests/islandora_hooks_test.info create mode 100644 tests/islandora_hooks_test.module diff --git a/tests/islandora_hooks_test.info b/tests/islandora_hooks_test.info new file mode 100644 index 00000000..9d211978 --- /dev/null +++ b/tests/islandora_hooks_test.info @@ -0,0 +1,7 @@ +name = Islandora Hook testing +description = Tests Hooks. Do not enable. +core = 7.x +package = Testing +hidden = TRUE +dependencies[] = islandora +files[] = islandora_hooks_test.module diff --git a/tests/islandora_hooks_test.module b/tests/islandora_hooks_test.module new file mode 100644 index 00000000..315b88ee --- /dev/null +++ b/tests/islandora_hooks_test.module @@ -0,0 +1,152 @@ +id == 'test:testIngestedObjectHook') { + $_SESSION['islandora_hooks']['alter'][ISLANDORA_OBJECT_INGESTED_HOOK] = TRUE; + if ($object->label == 'block') { + $context['block'] = TRUE; + } + } + break; + + case 'modify': + if ($object->id == 'test:testModifiedObjectHook') { + $_SESSION['islandora_hooks']['alter'][ISLANDORA_OBJECT_MODIFIED_HOOK] = TRUE; + if (isset($context['params']['label']) && $context['params']['label'] == 'block') { + $context['block'] = TRUE; + } + } + elseif ($object->id == 'test:testPurgedObjectHook') { + $_SESSION['islandora_hooks']['alter'][ISLANDORA_OBJECT_PURGED_HOOK] = TRUE; + if (isset($context['params']['label']) && $context['params']['label'] == 'block') { + $context['block'] = TRUE; + } + elseif (isset($context['params']['label']) && $context['params']['label'] == 'delete') { + $context['delete'] = TRUE; + } + } + break; + + case 'purge': + if ($object->id == 'test:testPurgedObjectHook') { + $_SESSION['islandora_hooks']['alter'][ISLANDORA_OBJECT_PURGED_HOOK] = TRUE; + if ($object->label == 'block') { + $context['block'] = TRUE; + } + elseif ($object->label == 'delete') { + $context['delete'] = TRUE; + } + } + break; + } +} + +/** + * Implements hook_islandora_object_alter(). + */ +function islandora_hooks_test_islandora_datastream_alter(AbstractFedoraObject $object, AbstractFedoraDatastream $datastream, array &$context) { + switch ($context['action']) { + case 'ingest': + if ($object->id == 'test:testIngestedDatastreamHook') { + $_SESSION['islandora_hooks']['alter'][ISLANDORA_DATASTREAM_INGESTED_HOOK] = TRUE; + if ($datastream->label == 'block') { + $context['block'] = TRUE; + } + } + break; + + case 'modify': + if ($object->id == 'test:testModifiedDatastreamHook') { + $_SESSION['islandora_hooks']['alter'][ISLANDORA_DATASTREAM_MODIFIED_HOOK] = TRUE; + if (isset($context['params']['dsLabel']) && $context['params']['dsLabel'] == 'block') { + $context['block'] = TRUE; + } + } + elseif ($object->id == 'test:testPurgedDatastreamHook') { + $_SESSION['islandora_hooks']['alter'][ISLANDORA_DATASTREAM_PURGED_HOOK] = TRUE; + if (isset($context['params']['dsLabel']) && $context['params']['dsLabel'] == 'block') { + $context['block'] = TRUE; + } + elseif (isset($context['params']['dsLabel']) && $context['params']['dsLabel'] == 'delete') { + $context['delete'] = TRUE; + } + } + break; + + case 'purge': + if ($object->id == 'test:testPurgedDatastreamHook') { + $_SESSION['islandora_hooks']['alter'][ISLANDORA_DATASTREAM_PURGED_HOOK] = TRUE; + if ($datastream->label == 'block') { + $context['block'] = TRUE; + } + elseif ($datastream->label == 'delete') { + $context['delete'] = TRUE; + } + } + break; + } +} + +/** + * Implements hook_islandora_object_ingested(). + */ +function islandora_hooks_test_islandora_object_ingested(FedoraObject $object) { + if ($object->id == 'test:testIngestedObjectHook') { + $_SESSION['islandora_hooks']['hook'][ISLANDORA_OBJECT_INGESTED_HOOK] = TRUE; + } +} + +/** + * Implements hook_islandora_object_modified(). + */ +function islandora_hooks_test_islandora_object_modified(FedoraObject $object) { + if ($object->id == 'test:testModifiedObjectHook') { + $_SESSION['islandora_hooks']['hook'][ISLANDORA_OBJECT_MODIFIED_HOOK] = TRUE; + } +} + +/** + * Implements hook_islandora_object_purged(). + */ +function islandora_hooks_test_islandora_object_purged($pid) { + if ($pid == 'test:testPurgedObjectHook') { + $_SESSION['islandora_hooks']['hook'][ISLANDORA_OBJECT_PURGED_HOOK] = TRUE; + } +} + +/** + * Implements hook_islandora_datastream_ingested(). + */ +function islandora_hooks_test_islandora_datastream_ingested(FedoraObject $object, FedoraDatastream $datastream) { + if ($object->id == 'test:testIngestedDatastreamHook' && $datastream->id == "TEST") { + $_SESSION['islandora_hooks']['hook'][ISLANDORA_DATASTREAM_INGESTED_HOOK] = TRUE; + } +} + +/** + * Implements hook_islandora_datastream_modified(). + */ +function islandora_hooks_test_islandora_datastream_modified(FedoraObject $object, FedoraDatastream $datastream) { + if ($object->id == 'test:testModifiedDatastreamHook' && $datastream->id == "TEST") { + $_SESSION['islandora_hooks']['hook'][ISLANDORA_DATASTREAM_MODIFIED_HOOK] = TRUE; + } +} + +/** + * Implements hook_islandora_datastream_purged(). + */ +function islandora_hooks_test_islandora_datastream_purged(FedoraObject $object, $dsid) { + if ($object->id == 'test:testPurgedDatastreamHook' && $dsid == "TEST") { + $_SESSION['islandora_hooks']['hook'][ISLANDORA_DATASTREAM_PURGED_HOOK] = TRUE; + } +} From f5c1729cd2de266b2ed82d61a960385a6b80e340 Mon Sep 17 00:00:00 2001 From: William Panting Date: Fri, 22 Mar 2013 10:11:35 -0300 Subject: [PATCH 008/172] test setup docs --- tests/README.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/README.txt b/tests/README.txt index 797d788b..3e7fe11d 100644 --- a/tests/README.txt +++ b/tests/README.txt @@ -1,3 +1,4 @@ You can define your own configurations specific to your enviroment by copying default.test_config.ini to test_config.ini, making your changes in the copied -file. \ No newline at end of file +file. These test need write access to the system's $FEDORA_HOME/server/config +directory as they need to temporarily replace the filter-drupal.xml file. \ No newline at end of file From 822c9211a27671b9efae05c0fb9e124ca6dc2124 Mon Sep 17 00:00:00 2001 From: William Panting Date: Fri, 22 Mar 2013 10:28:11 -0300 Subject: [PATCH 009/172] need access to the filter file too --- tests/README.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/README.txt b/tests/README.txt index 3e7fe11d..c03004ae 100644 --- a/tests/README.txt +++ b/tests/README.txt @@ -1,4 +1,4 @@ You can define your own configurations specific to your enviroment by copying default.test_config.ini to test_config.ini, making your changes in the copied file. These test need write access to the system's $FEDORA_HOME/server/config -directory as they need to temporarily replace the filter-drupal.xml file. \ No newline at end of file +directory as well as the filter-drupal.xml file. \ No newline at end of file From e8f5b8190a62533c9bbff335666121fd2afed191 Mon Sep 17 00:00:00 2001 From: Daniel Lamb Date: Wed, 27 Mar 2013 16:45:21 +0000 Subject: [PATCH 010/172] Buildfile and Doxyfile --- build.xml | 164 +++++++++++++++++++++---------------------------- build/Doxyfile | 3 + 2 files changed, 72 insertions(+), 95 deletions(-) diff --git a/build.xml b/build.xml index 854d3a0a..273f8ca8 100644 --- a/build.xml +++ b/build.xml @@ -1,110 +1,84 @@ - + - - - - - - - + + + + + + + - - - - - - - + + + + + + + - - - + + + - - - - - - + + + + + + + + + + - - - - - - - + + + + + - - - - - - - - + + + + + - - - - - - - - + + + + + - - - - - - - - - - + + + + + - - - - - - - + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + - - - - - - - - - - + + + + + diff --git a/build/Doxyfile b/build/Doxyfile index 1d4e3693..f41dc285 100644 --- a/build/Doxyfile +++ b/build/Doxyfile @@ -27,6 +27,9 @@ DOXYFILE_ENCODING = UTF-8 PROJECT_NAME = Islandora 7.x +# Put the git hash here using sed before generating the documentation. +PROJECT_NUMBER = + # The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) # base path where the generated documentation will be put. # If a relative path is entered, it will be relative to the location From 2c829f0241a289732efbc4ca56dfccc9bca61bd1 Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Tue, 26 Mar 2013 07:10:03 +0100 Subject: [PATCH 011/172] Cleaned up and moved grid/list display logic into islandora, since its now used in several modules. --- css/islandora.objects.css | 39 ++++++++++++++++++ islandora.module | 23 +++++++++++ theme/islandora-objects-grid.tpl.php | 17 ++++++++ theme/islandora-objects-list.tpl.php | 29 +++++++++++++ theme/islandora-objects.tpl.php | 15 +++++++ theme/theme.inc | 61 ++++++++++++++++++++++++++++ 6 files changed, 184 insertions(+) create mode 100644 css/islandora.objects.css create mode 100644 theme/islandora-objects-grid.tpl.php create mode 100644 theme/islandora-objects-list.tpl.php create mode 100644 theme/islandora-objects.tpl.php diff --git a/css/islandora.objects.css b/css/islandora.objects.css new file mode 100644 index 00000000..5e03d3f7 --- /dev/null +++ b/css/islandora.objects.css @@ -0,0 +1,39 @@ +/** + * @file + * Styles for rendering grids/lists of objects. + */ +.islandora-objects-display-switch { + float: right; +} +.islandora-objects-grid-item { + display: inline-block; + width: 20%; + min-width: 100px; + min-height: 180px; + display: -moz-inline-stack; + display: inline-block; + vertical-align: top; + margin: 1.5em 1.84%; + zoom: 1; + *display: inline; + _height: 180px; +} +.islandora-objects-list-item { + padding-bottom: 1.5em; + border-bottom: 1px solid #ddd; +} +.islandora-objects-list-item .islandora-object-thumb { + clear: left; + float: left; + padding: 3px 0 0; + text-align: center; + width: 100px; +} +.islandora-objects-list-item .islandora-object-caption, .islandora-objects-list-item .islandora-object-description { + margin: 0 0 0 130px; + padding-top: 2px; + padding-bottom: 2px; +} +.islandora-object-thumb img { + width: 100%; +} diff --git a/islandora.module b/islandora.module index 94aedbe0..f800cf6d 100644 --- a/islandora.module +++ b/islandora.module @@ -286,6 +286,29 @@ function islandora_theme() { 'file' => 'theme/theme.inc', 'variables' => array('object' => NULL, 'content' => array()), ), + // Render a bunch of objects as either a grid or a list. + 'islandora_objects' => array( + 'file' => 'theme/theme.inc', + 'template' => 'theme/islandora-objects', + 'variables' => array( + 'objects' => NULL, + 'display' => NULL, + 'page_size' => 20, + 'limit' => 10, + ), + ), + // Render a bunch of objects as a grid. + 'islandora_objects_grid' => array( + 'file' => 'theme/theme.inc', + 'template' => 'theme/islandora-objects-grid', + 'variables' => array('objects' => NULL), + ), + // Render a bunch of objects as a list. + 'islandora_objects_list' => array( + 'file' => 'theme/theme.inc', + 'template' => 'theme/islandora-objects-list', + 'variables' => array('objects' => NULL), + ), ); } diff --git a/theme/islandora-objects-grid.tpl.php b/theme/islandora-objects-grid.tpl.php new file mode 100644 index 00000000..e6d7e140 --- /dev/null +++ b/theme/islandora-objects-grid.tpl.php @@ -0,0 +1,17 @@ + +
+ +
+
+
+
+
+
+ +
diff --git a/theme/islandora-objects-list.tpl.php b/theme/islandora-objects-list.tpl.php new file mode 100644 index 00000000..67f5f02d --- /dev/null +++ b/theme/islandora-objects-list.tpl.php @@ -0,0 +1,29 @@ + +
+ + + +
+
+
+ +
+
+ + + +
+
+ +
+
+
+ + +
diff --git a/theme/islandora-objects.tpl.php b/theme/islandora-objects.tpl.php new file mode 100644 index 00000000..5b55eb88 --- /dev/null +++ b/theme/islandora-objects.tpl.php @@ -0,0 +1,15 @@ + +
+ + $display_links, 'attributes' => array('class' => array('links', 'inline')))); ?> + + + + +
diff --git a/theme/theme.inc b/theme/theme.inc index 87e44fc1..7c43deef 100644 --- a/theme/theme.inc +++ b/theme/theme.inc @@ -157,3 +157,64 @@ function islandora_preprocess_islandora_object_print(array &$variables) { function theme_islandora_object_print(array &$variables) { return drupal_render($variables['content']); } + +/** + * Implements hook_preprocess_theme(). + */ +function islandora_preprocess_islandora_objects(array &$variables) { + module_load_include('inc', 'islandora_paged_content', 'includes/utilities'); + $display = (empty($_GET['display'])) ? 'grid' : $_GET['display']; + $grid_display = $display == 'grid'; + $list_display = !$grid_display; + $query_params = drupal_get_query_parameters($_GET); + $variables['display_links'] = array( + array( + 'title' => t('Grid view'), + 'href' => url($_GET['q'], array('absolute' => TRUE)), + 'attributes' => array( + 'class' => $grid_display ? 'active' : '', + ), + 'query' => array('display' => 'grid') + $query_params, + ), + array( + 'title' => t('List view'), + 'href' => url($_GET['q'], array('absolute' => TRUE)), + 'attributes' => array( + 'class' => $list_display ? 'active' : '', + ), + 'query' => array('display' => 'list') + $query_params, + ), + ); + // Pager. + $objects = $variables['objects']; + $limit = $variables['limit']; + $page_size = $variables['page_size']; + $page = pager_default_initialize(count($objects), $limit); + $objects = array_slice($objects, $page * $limit, $limit); + $variables['pager'] = theme('pager', array('quantity' => 10)); + // Content. + $map_objects = function($o) { + $o = islandora_object_load($o); + $url = "islandora/object/{$o->id}"; + $link_options = array('html' => TRUE, 'attributes' => array('title' => $o->label)); + $img = theme_image(array('path' => url("$url/datastream/TN/view"), 'attributes' => array())); + $description = NULL; + $dc = DublinCore::importFromXMLString($o['DC']->content); + if ($dc) { + $dc = $dc->asArray(); + $description = $dc['dc:description']['value']; + } + return array( + 'label' => $o->label, + 'class' => drupal_strtolower(preg_replace('/[^A-Za-z0-9]/', '-', $o->id)), + 'link' => l($o->label, $url, $link_options), + 'thumb' => l($img, $url, $link_options), + 'description' => $description, + ); + }; + $objects = array_map($map_objects, $objects); + $theme = $grid_display ? 'islandora_objects_grid' : 'islandora_objects_list'; + $variables['content'] = theme($theme, array('objects' => $objects)); + $module_path = drupal_get_path('module', 'islandora'); + drupal_add_css("$module_path/css/islandora.objects.css"); +} From 212e113700ab5ed1da4ca2e2dee92480bf17363e Mon Sep 17 00:00:00 2001 From: jonathangreen Date: Thu, 28 Mar 2013 12:14:58 -0300 Subject: [PATCH 012/172] Updated travis config a bit --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index fa7e5ca9..a93edb4b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,7 +22,7 @@ before_install: - drush dl --yes drupal - cd drupal-* - drush si standard --db-url=mysql://drupal:drupal@localhost/drupal --yes - - drush runserver 8081 > /dev/null & + - drush runserver localhost:8081 > /dev/null & - ln -s $TRAVIS_BUILD_DIR sites/all/modules/islandora - mv sites/all/modules/islandora/tests/travis.test_config.ini sites/all/modules/islandora/tests/test_config.ini - mkdir sites/all/libraries @@ -32,4 +32,4 @@ before_install: - drush cc all - sleep 4 script: - - drush test-run --uri=http://127.0.0.1:8081 Islandora + - sudo -u www-data drush test-run --uri=http://localhost:8081 Islandora From 1f915cad127373b3fe7e042cd514c6ad7437fe0a Mon Sep 17 00:00:00 2001 From: jonathangreen Date: Thu, 28 Mar 2013 12:27:19 -0300 Subject: [PATCH 013/172] Another try at travis --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index a93edb4b..8fae0457 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,6 +19,7 @@ before_install: - pyrus channel-discover pear.drush.org - pyrus install drush/drush - phpenv rehash + - sudo -u www-data phpenv rehash - drush dl --yes drupal - cd drupal-* - drush si standard --db-url=mysql://drupal:drupal@localhost/drupal --yes From ff8a7aa301316872f515e551ee1444469d7856fd Mon Sep 17 00:00:00 2001 From: daitken Date: Thu, 28 Mar 2013 12:39:35 -0300 Subject: [PATCH 014/172] object_properties.form.inc grammar fixes --- includes/object_properties.form.inc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/object_properties.form.inc b/includes/object_properties.form.inc index 29875d28..0898db0c 100644 --- a/includes/object_properties.form.inc +++ b/includes/object_properties.form.inc @@ -30,7 +30,7 @@ function islandora_object_properties_form(array $form, array &$form_state, Fedor '#title' => t('Item Label'), '#default_value' => $object->label, '#required' => 'TRUE', - '#description' => t('A Human readable label'), + '#description' => t('A human-readable label'), // Double the normal length. '#size' => 120, // Max length for a Fedora Label. @@ -43,14 +43,14 @@ function islandora_object_properties_form(array $form, array &$form_state, Fedor '#title' => t('Owner'), '#default_value' => $object->owner, '#required' => FALSE, - '#description' => t('The owner id'), + '#description' => t('The owner\'s account name'), '#type' => 'textfield', ), 'object_state' => array( '#title' => t('State'), '#default_value' => $object->state, '#required' => TRUE, - '#description' => t('The items state one of active, inactive or deleted'), + '#description' => t('The object\'s state (active, inactive or deleted)'), '#type' => 'select', '#options' => array('A' => 'Active', 'I' => 'Inactive', 'D' => 'Deleted'), ), From 815e3dc9bb9442047662b207a4fd2975999e8d43 Mon Sep 17 00:00:00 2001 From: daitken Date: Thu, 28 Mar 2013 12:43:35 -0300 Subject: [PATCH 015/172] add_datastream.form.inc grammar fixes --- includes/add_datastream.form.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/add_datastream.form.inc b/includes/add_datastream.form.inc index fa94148f..d19d5757 100644 --- a/includes/add_datastream.form.inc +++ b/includes/add_datastream.form.inc @@ -39,7 +39,7 @@ function islandora_add_datastream_form(array $form, array &$form_state, FedoraOb '#collapsed' => FALSE, 'dsid' => array( '#title' => 'Datastream ID', - '#description' => t("An ID for this stream that is unique to this object. Must start with a letter and contain only alphanumeric characters and dashes and underscores. Datastreams that are defined by the content model don't currently exist: @unused_dsids.", array('@unused_dsids' => $unused_datastreams)), + '#description' => t("An ID for this stream that is unique to this object. Must start with a letter and contain only alphanumeric characters, dashes and underscores. The following datastreams are defined by this content model but don't currently exist: @unused_dsids.", array('@unused_dsids' => $unused_datastreams)), ), '#type' => 'textfield', '#size' => 64, @@ -57,7 +57,7 @@ function islandora_add_datastream_form(array $form, array &$form_state, FedoraOb '#required' => TRUE, '#size' => 64, '#maxlength' => 64, - '#description' => t('A Human readable label'), + '#description' => t('A human-readable label'), '#type' => 'textfield', '#element_validate' => array('islandora_add_datastream_form_field_does_not_contain_a_forward_slash'), ), From 2763f2b267f80d42a1c0d8e8bf1ac66c0c5369d8 Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Thu, 28 Mar 2013 12:44:35 -0300 Subject: [PATCH 016/172] Use build_hook_list so we get correct hook_names when altering. --- includes/tuque_wrapper.inc | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/includes/tuque_wrapper.inc b/includes/tuque_wrapper.inc index 8bd3c3e6..9904af60 100644 --- a/includes/tuque_wrapper.inc +++ b/includes/tuque_wrapper.inc @@ -35,10 +35,7 @@ $islandora_module_path = drupal_get_path('module', 'islandora'); * Allow modules to alter an object before a mutable event occurs. */ function islandora_alter_object(AbstractFedoraObject $object, array &$context) { - $types = array('islandora_object'); - foreach ($object->models as $model) { - $types[] = "{$model}_islandora_object"; - } + $types = islandora_build_hook_list('islandora_object', $object->models); drupal_alter($types, $object, $context); } @@ -46,11 +43,11 @@ function islandora_alter_object(AbstractFedoraObject $object, array &$context) { * Allow modules to alter a datastream before a mutable event occurs. */ function islandora_alter_datastream(AbstractFedoraObject $object, AbstractDatastream $datastream, array &$context) { - $types = array('islandora_datastream'); + $types = array(); foreach ($object->models as $model) { - $types[] = "{$model}_{$datastream->id}_islandora_datastream"; + $types[] = "{$model}_{$datastream->id}"; } - drupal_alter($types, $object, $datastream, $context); + drupal_alter(islandora_build_hook_list('islandora_datastream', $types), $object, $datastream, $context); } /** From ac50236252628003e5a8cb50d21a2fe75f489036 Mon Sep 17 00:00:00 2001 From: daitken Date: Thu, 28 Mar 2013 12:49:05 -0300 Subject: [PATCH 017/172] admin.form.inc grammar fixes --- includes/admin.form.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/admin.form.inc b/includes/admin.form.inc index d3bccd5a..a1f22652 100644 --- a/includes/admin.form.inc +++ b/includes/admin.form.inc @@ -146,7 +146,7 @@ function islandora_repository_admin(array $form, array &$form_state) { '#type' => 'textfield', '#title' => t('PID namespaces allowed in this Drupal install'), '#default_value' => variable_get('islandora_pids_allowed', 'default: demo: changeme: ilives: islandora-book: books: newspapers: '), - '#description' => t('A space separated list of PID namespaces that users are permitted to access from this Drupal installation.
This could be more than a simple namespace ie demo:mydemos.
islandora: is reserved and is always allowed.'), + '#description' => t('A list of PID namespaces, separated by spaces, that users are permitted to access from this Drupal installation.
This could be more than a simple namespace, e.g. demo:mydemos.
The namespace islandora: is reserved, and is always allowed.'), '#weight' => 0, ); } From af933e66ff97e3316b7f5cbaacdbdc24f564c1b6 Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Thu, 28 Mar 2013 12:52:55 -0300 Subject: [PATCH 018/172] Add module_loads just incase and more consistency. --- includes/tuque_wrapper.inc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/includes/tuque_wrapper.inc b/includes/tuque_wrapper.inc index 9904af60..8e4e8a0f 100644 --- a/includes/tuque_wrapper.inc +++ b/includes/tuque_wrapper.inc @@ -35,14 +35,15 @@ $islandora_module_path = drupal_get_path('module', 'islandora'); * Allow modules to alter an object before a mutable event occurs. */ function islandora_alter_object(AbstractFedoraObject $object, array &$context) { - $types = islandora_build_hook_list('islandora_object', $object->models); - drupal_alter($types, $object, $context); + module_load_include('inc', 'islandora', 'includes/utilities'); + drupal_alter(islandora_build_hook_list('islandora_object', $object->models) ,$object, $context); } /** * Allow modules to alter a datastream before a mutable event occurs. */ function islandora_alter_datastream(AbstractFedoraObject $object, AbstractDatastream $datastream, array &$context) { + module_load_include('inc', 'islandora', 'includes/utilities'); $types = array(); foreach ($object->models as $model) { $types[] = "{$model}_{$datastream->id}"; From 8204d1f8fd8a8409701003a45fa4c77305ddedb0 Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Mon, 1 Apr 2013 16:33:49 +0200 Subject: [PATCH 019/172] Standards Compliance --- tests/islandora_manage_permissions.test | 64 ++++++++++++++----------- 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/tests/islandora_manage_permissions.test b/tests/islandora_manage_permissions.test index 76f43a6d..5e20b374 100644 --- a/tests/islandora_manage_permissions.test +++ b/tests/islandora_manage_permissions.test @@ -1,7 +1,17 @@ 'Islandora Manage Permissions', @@ -10,69 +20,65 @@ class IslandoraPermissionsTestCase extends IslandoraWebTestCase { ); } + /** + * Prepares enviroment for testing. + * + * @see IslandoraWebTestCase::setUp() + */ public function setUp() { parent::setUp(array('islandora')); } + /** + * Test manage permissions. + */ public function testManagePermissions() { - - - // permission FEDORA_VIEW_OBJECTS - // create a user with permission + // Test permission FEDORA_VIEW_OBJECTS. + // Create a user with permission. $user = $this->drupalCreateUser(array(FEDORA_VIEW_OBJECTS)); - // log the user in + // Log the user in. $this->drupalLogin($user); $this->clickLink(t('Islandora Repository')); $this->assertNoLink('Manage', 'Manage tab is not on current page.'); - - - // permission FEDORA_VIEW_OBJECTS, FEDORA_MANAGE_PROPERTIES + + // Test permission FEDORA_VIEW_OBJECTS, FEDORA_MANAGE_PROPERTIES. $user = $this->drupalCreateUser(array(FEDORA_VIEW_OBJECTS, FEDORA_MANAGE_PROPERTIES)); - // log the user in $this->drupalLogin($user); $this->clickLink(t('Islandora Repository')); $this->assertLink('Manage', 0, 'Manage tab is on current page.'); $this->clickLink(t('Manage')); $this->assertLink('Properties', 0, 'Properties tab is on current page.'); $this->assertNoLink('Datastreams', 'Datastreams tab is not on current page.'); - $this->assertNoLink('Collection','Collection tab is not on current page.'); + $this->assertNoLink('Collection', 'Collection tab is not on current page.'); - - // permission FEDORA_VIEW_OBJECTS, FEDORA_ADD_DS + // Test permission FEDORA_VIEW_OBJECTS, FEDORA_ADD_DS. $user = $this->drupalCreateUser(array(FEDORA_VIEW_OBJECTS, FEDORA_ADD_DS)); - // log the user in $this->drupalLogin($user); $this->clickLink(t('Islandora Repository')); $this->assertLink('Manage', 0, 'Manage tab is on current page.'); $this->clickLink(t('Manage')); $this->assertLink('Datastreams', 0, 'Datastreams tab is on current page.'); $this->assertNoLink('Properties', 'Properties tab is not on current page.'); - $this->assertNoLink('Collection','Collection tab is not on current page.'); - - - // permission FEDORA_VIEW_OBJECTS, FEDORA_METADATA_EDIT + $this->assertNoLink('Collection', 'Collection tab is not on current page.'); + + // Test permission FEDORA_VIEW_OBJECTS, FEDORA_METADATA_EDIT. $user = $this->drupalCreateUser(array(FEDORA_VIEW_OBJECTS, FEDORA_METADATA_EDIT)); - // log the user in - $this->drupalLogin($user); + $this->drupalLogin($user); $this->clickLink(t('Islandora Repository')); $this->assertLink('Manage', 0, 'Manage tab is on current page.'); $this->clickLink(t('Manage')); $this->assertLink('Datastreams', 0, 'Datastreams tab is on current page.'); $this->assertNoLink('Properties', 'Properties tab is not on current page.'); - $this->assertNoLink('Collection','Collection tab is not on current page.'); - - - // permission FEDORA_VIEW_OBJECTS, FEDORA_PURGE + $this->assertNoLink('Collection', 'Collection tab is not on current page.'); + + // Test permission FEDORA_VIEW_OBJECTS, FEDORA_PURGE. $user = $this->drupalCreateUser(array(FEDORA_VIEW_OBJECTS, FEDORA_PURGE)); - // log the user in $this->drupalLogin($user); $this->clickLink(t('Islandora Repository')); $this->assertLink('Manage', 0, 'Manage tab is on current page.'); $this->clickLink(t('Manage')); $this->assertLink('Datastreams', 0, 'Datastreams tab is on current page.'); $this->assertNoLink('Properties', 'Properties tab is not on current page.'); - $this->assertNoLink('Collection','Collection tab is not on current page.'); - + $this->assertNoLink('Collection', 'Collection tab is not on current page.'); } - - } \ No newline at end of file +} From 68bbbe163e3e67fddb4adf26eb4fd02a31d1597b Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Mon, 1 Apr 2013 17:30:41 +0200 Subject: [PATCH 020/172] Added tests for islandora_user_access(). Caught a spelling mistake as part of the testing writing. --- islandora.module | 2 +- tests/islandora_manage_permissions.test | 52 +++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/islandora.module b/islandora.module index 57ee5d9b..47fed2e6 100644 --- a/islandora.module +++ b/islandora.module @@ -401,7 +401,7 @@ function islandora_user_access($object, array $permissions, $content_models = ar } elseif (is_subclass_of($object, 'FedoraDatastream')) { $datastream = $object; - $object = $datstream->parent; + $object = $datastream->parent; } // Check for access. $accessible_namespace = islandora_namespace_accessible($object->id); diff --git a/tests/islandora_manage_permissions.test b/tests/islandora_manage_permissions.test index 5e20b374..72aebd89 100644 --- a/tests/islandora_manage_permissions.test +++ b/tests/islandora_manage_permissions.test @@ -81,4 +81,56 @@ class IslandoraPermissionsTestCase extends IslandoraWebTestCase { $this->assertNoLink('Properties', 'Properties tab is not on current page.'); $this->assertNoLink('Collection', 'Collection tab is not on current page.'); } + + /** + * Test generic access functions. + * + * Note that we can't test with the Global user as SimpleTest doesn't support + * it. Therefore we can't test the authtoken support. + */ + public function testAccessFunctions() { + $object = islandora_object_load(variable_get('islandora_repository_pid', 'islandora:root')); + // Test islandora_user_access(); + // Test no object/permissions. + $ret = islandora_user_access(NULL, array()); + $this->assertFalse($ret, 'User access denied when no object/permissions are provided.'); + // Test with object no permissions. + $ret = islandora_user_access($object, array()); + $this->assertFalse($ret, 'User access denied when no permissions are provided.'); + // Test access with matching permission. + $user = $this->drupalCreateUser(array(FEDORA_VIEW_OBJECTS)); + $ret = islandora_user_access($object, array(FEDORA_VIEW_OBJECTS), array(), TRUE, $user); + $this->assertTrue($ret, 'User access granted when permissions match.'); + // Test access with matching permission but access any is FALSE. + $user = $this->drupalCreateUser(array(FEDORA_VIEW_OBJECTS)); + $ret = islandora_user_access($object, array(FEDORA_VIEW_OBJECTS, FEDORA_PURGE), array(), FALSE, $user); + $this->assertFalse($ret, 'User access denied for matching permission but with access any set to FALSE.'); + // Test access with non-matching permission. + $user = $this->drupalCreateUser(array(FEDORA_PURGE)); + $ret = islandora_user_access($object, array(FEDORA_VIEW_OBJECTS), array(), TRUE, $user); + $this->assertFalse($ret, 'User access denied when permissions did not match.'); + // Test access with both permissions and content model. + $user = $this->drupalCreateUser(array(FEDORA_VIEW_OBJECTS)); + $model = $object->models; + $model = reset($model); + $ret = islandora_user_access($object, array(FEDORA_VIEW_OBJECTS), array($model), TRUE, $user); + $this->assertTrue($ret, 'User access granted for matching permission and model.'); + // Test access with matching permissions and non-matching content model. + $user = $this->drupalCreateUser(array(FEDORA_VIEW_OBJECTS)); + $ret = islandora_user_access($object, array(FEDORA_VIEW_OBJECTS), array('islandora:obviouslyNotACModel'), TRUE, $user); + $this->assertFalse($ret, 'User access denied for matching permission and non-matching model.'); + // Test access with all matching permissions and one matching model but + // access any is FALSE. + $user = $this->drupalCreateUser(array(FEDORA_VIEW_OBJECTS, FEDORA_PURGE)); + $model = $object->models; + $model = reset($model); + $ret = islandora_user_access($object, array(FEDORA_VIEW_OBJECTS, FEDORA_PURGE), array($model, 'islandora:obviouslyNotACModel'), FALSE, $user); + $this->assertFalse($ret, 'User access denied for all matching permissions and one matching model but with access any set to FALSE.'); + $ret = islandora_user_access($object, array(FEDORA_VIEW_OBJECTS, FEDORA_PURGE), array($model), FALSE, $user); + $this->assertTrue($ret, 'User access granted for all matching permissions and matching models with access any set to FALSE.'); + // Test passing in a Datastream. + $user = $this->drupalCreateUser(array(FEDORA_VIEW_OBJECTS, FEDORA_PURGE)); + $ret = islandora_user_access($object['DC'], array(FEDORA_VIEW_OBJECTS), array(), TRUE, $user); + $this->assertTrue($ret, 'User access granted for matching permissions, with a datastream given instead of an object.'); + } } From 90b9b6ceb602ac68b2c4daa9b0548d3321b09b55 Mon Sep 17 00:00:00 2001 From: Jonathan Green Date: Tue, 2 Apr 2013 19:33:43 +0000 Subject: [PATCH 021/172] Some updates of tests for Travis --- tests/hooks.test | 2 +- tests/web_test_case.inc | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/hooks.test b/tests/hooks.test index 0a667fee..bc3020f3 100644 --- a/tests/hooks.test +++ b/tests/hooks.test @@ -32,7 +32,7 @@ class IslandoraHooksTestCase extends IslandoraWebTestCase { * @see IslandoraWebTestCase::setUp() */ public function setUp() { - parent::setUp('islandora_hooks_test', 'devel'); + parent::setUp('islandora_hooks_test'); $this->repository = $this->admin->repository; $this->purgeTestObjects(); } diff --git a/tests/web_test_case.inc b/tests/web_test_case.inc index a513de43..3651e3db 100644 --- a/tests/web_test_case.inc +++ b/tests/web_test_case.inc @@ -18,6 +18,10 @@ class IslandoraWebTestCase extends DrupalWebTestCase { // Always enable islandora. $args[] = 'islandora'; parent::setUp($args); + // Its possible test are running before class autoloading + module_load_include('inc', 'islandora', 'includes/tuque'); + module_load_include('inc', 'islandora', 'includes/tuque_wrapper'); + $this->configuration = $this->getTestConfiguration(); if ($this->configuration['use_drupal_filter']) { $this->backUpDrupalFilter(); From b1e57b16d89d95af9abe96cc13dfc29103638927 Mon Sep 17 00:00:00 2001 From: jonathangreen Date: Tue, 2 Apr 2013 16:38:57 -0300 Subject: [PATCH 022/172] Another change to the travis-ci config --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8fae0457..c5284425 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,7 @@ before_install: - sudo apt-get install -qq php5-cgi - sudo apt-get install -qq php5-mysql - git clone git://github.com/Islandora/tuque.git - - git clone git://github.com/Islandora/islandora_tomcat.git + - git clone -b 3.5 git://github.com/Islandora/islandora_tomcat.git - cd islandora_tomcat - export CATALINA_HOME='.' - ./bin/startup.sh @@ -23,7 +23,7 @@ before_install: - drush dl --yes drupal - cd drupal-* - drush si standard --db-url=mysql://drupal:drupal@localhost/drupal --yes - - drush runserver localhost:8081 > /dev/null & + - drush runserver localhost:8081 &>/dev/null & - ln -s $TRAVIS_BUILD_DIR sites/all/modules/islandora - mv sites/all/modules/islandora/tests/travis.test_config.ini sites/all/modules/islandora/tests/test_config.ini - mkdir sites/all/libraries @@ -33,4 +33,4 @@ before_install: - drush cc all - sleep 4 script: - - sudo -u www-data drush test-run --uri=http://localhost:8081 Islandora + - drush test-run --uri=http://localhost:8081 Islandora From 12dcbb5b17340653c249c14b00e117ca642994a3 Mon Sep 17 00:00:00 2001 From: jonathangreen Date: Tue, 2 Apr 2013 16:44:01 -0300 Subject: [PATCH 023/172] Another travis config change --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c5284425..b1c550de 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,7 +19,6 @@ before_install: - pyrus channel-discover pear.drush.org - pyrus install drush/drush - phpenv rehash - - sudo -u www-data phpenv rehash - drush dl --yes drupal - cd drupal-* - drush si standard --db-url=mysql://drupal:drupal@localhost/drupal --yes From 54acff362ba344c81c8897fca5830797af839afe Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Wed, 3 Apr 2013 12:06:11 -0300 Subject: [PATCH 024/172] Handle downloading of clips in core (ONTIME-1262). --- islandora.module | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/islandora.module b/islandora.module index 05a3a57b..43b363fe 100644 --- a/islandora.module +++ b/islandora.module @@ -245,6 +245,14 @@ function islandora_menu() { 'type' => MENU_SUGGESTED_ITEM, 'access arguments' => array(FEDORA_INGEST), ); + $items['islandora/object/%islandora_object/download_clip'] = array( + 'page callback' => 'islandora_download_clip', + 'page arguments' => array(2), + 'type' => MENU_CALLBACK, + 'access callback' => 'islandora_object_access_callback', + 'access arguments' => array(FEDORA_VIEW_OBJECTS, 2), + 'load arguments' => array(2), + ); return $items; } @@ -1073,3 +1081,25 @@ function islandora_print_object(FedoraObject $object) { drupal_set_title($object->label); return theme('islandora_object_print', array('object' => $object)); } + +/** + * Menu callback downloads the given clip. + */ +function islandora_download_clip(FedoraObject $object) { + if (isset($_GET['clip'])) { + $is_https = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on'; + $http_protocol = $is_https ? 'https' : 'http'; + $url = $http_protocol . '://' . $_SERVER['HTTP_HOST'] . $_GET['clip']; + $filename = $object->label; + header("Content-Disposition: attachment; filename=\"{$filename}.jpg\""); + header("Content-type: image/jpeg"); + header("Content-Transfer-Encoding: binary"); + $ch = curl_init(); + curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); + curl_setopt($ch, CURLOPT_HEADER, 0); + curl_setopt($ch, CURLOPT_URL, $url); + $response = curl_exec ($ch); + curl_close($ch); + } + exit(); +} \ No newline at end of file From 0b0acd0759dc323b060872d1c5e341d6bdc321fc Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Wed, 3 Apr 2013 12:08:00 -0300 Subject: [PATCH 025/172] New line and codesniffer changes. --- islandora.module | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/islandora.module b/islandora.module index 43b363fe..c9ea373b 100644 --- a/islandora.module +++ b/islandora.module @@ -120,7 +120,7 @@ function islandora_menu() { FEDORA_METADATA_EDIT, FEDORA_ADD_DS, FEDORA_PURGE, - FEDORA_INGEST + FEDORA_INGEST, ), 2), ); @@ -1098,8 +1098,8 @@ function islandora_download_clip(FedoraObject $object) { curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_URL, $url); - $response = curl_exec ($ch); + $response = curl_exec($ch); curl_close($ch); } exit(); -} \ No newline at end of file +} From 13efc16b6a57720d9c07913a2c87174773a52920 Mon Sep 17 00:00:00 2001 From: jonathangreen Date: Thu, 4 Apr 2013 15:31:53 -0300 Subject: [PATCH 026/172] Updated travis config again --- .travis.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index b1c550de..b0883342 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: php php: - - 5.3 + - 5.3.3 before_install: - mysql -u root -e 'create database drupal;' - mysql -u root -e "create database fedora;" @@ -8,8 +8,6 @@ before_install: - mysql -u root -e "GRANT ALL PRIVILEGES ON drupal.* To 'drupal'@'localhost' IDENTIFIED BY 'drupal';" - cd $HOME - sudo apt-get update -qq - - sudo apt-get install -qq php5-cgi - - sudo apt-get install -qq php5-mysql - git clone git://github.com/Islandora/tuque.git - git clone -b 3.5 git://github.com/Islandora/islandora_tomcat.git - cd islandora_tomcat From 35117d4f3046d8e5fb63b87edbaf74951893ca2d Mon Sep 17 00:00:00 2001 From: jonathangreen Date: Thu, 4 Apr 2013 15:40:33 -0300 Subject: [PATCH 027/172] added another updated travis config --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index b0883342..6455bb7f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: php php: - - 5.3.3 + - 5.4 before_install: - mysql -u root -e 'create database drupal;' - mysql -u root -e "create database fedora;" @@ -20,7 +20,7 @@ before_install: - drush dl --yes drupal - cd drupal-* - drush si standard --db-url=mysql://drupal:drupal@localhost/drupal --yes - - drush runserver localhost:8081 &>/dev/null & + - drush runserver --server=builtin localhost:8081 &>/dev/null & - ln -s $TRAVIS_BUILD_DIR sites/all/modules/islandora - mv sites/all/modules/islandora/tests/travis.test_config.ini sites/all/modules/islandora/tests/test_config.ini - mkdir sites/all/libraries From 258688747606cefd664a704164ce51db37c927e3 Mon Sep 17 00:00:00 2001 From: jonathangreen Date: Thu, 4 Apr 2013 15:54:45 -0300 Subject: [PATCH 028/172] Updated travis to build with different fedora versions --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 6455bb7f..e9909ebe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,9 @@ language: php php: - 5.4 +env: + - FEDORA_VERSION="3.5" + - FEDORA_VERSION="3.6.2" before_install: - mysql -u root -e 'create database drupal;' - mysql -u root -e "create database fedora;" From 2ac9ce5507d3bee1d8911b8569641105ec5778b0 Mon Sep 17 00:00:00 2001 From: jonathangreen Date: Thu, 4 Apr 2013 16:11:53 -0300 Subject: [PATCH 029/172] Updated travis to build with different fedora versions --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e9909ebe..ffd4d8df 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,7 @@ before_install: - cd $HOME - sudo apt-get update -qq - git clone git://github.com/Islandora/tuque.git - - git clone -b 3.5 git://github.com/Islandora/islandora_tomcat.git + - git clone -b $FEDORA_VERSION git://github.com/Islandora/islandora_tomcat.git - cd islandora_tomcat - export CATALINA_HOME='.' - ./bin/startup.sh From 64ff24a0853c4978e76f93f8e7744e30f9c73924 Mon Sep 17 00:00:00 2001 From: jonathangreen Date: Thu, 4 Apr 2013 16:27:36 -0300 Subject: [PATCH 030/172] Updated travis to build with different fedora versions --- .travis.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index ffd4d8df..6626bf0e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,16 +1,15 @@ language: php php: + - 5.3.3 - 5.4 env: - FEDORA_VERSION="3.5" - - FEDORA_VERSION="3.6.2" before_install: - mysql -u root -e 'create database drupal;' - mysql -u root -e "create database fedora;" - mysql -u root -e "GRANT ALL PRIVILEGES ON fedora.* To 'fedora'@'localhost' IDENTIFIED BY 'fedora';" - mysql -u root -e "GRANT ALL PRIVILEGES ON drupal.* To 'drupal'@'localhost' IDENTIFIED BY 'drupal';" - cd $HOME - - sudo apt-get update -qq - git clone git://github.com/Islandora/tuque.git - git clone -b $FEDORA_VERSION git://github.com/Islandora/islandora_tomcat.git - cd islandora_tomcat @@ -23,7 +22,7 @@ before_install: - drush dl --yes drupal - cd drupal-* - drush si standard --db-url=mysql://drupal:drupal@localhost/drupal --yes - - drush runserver --server=builtin localhost:8081 &>/dev/null & + - drush runserver localhost:8081 &>/dev/null & - ln -s $TRAVIS_BUILD_DIR sites/all/modules/islandora - mv sites/all/modules/islandora/tests/travis.test_config.ini sites/all/modules/islandora/tests/test_config.ini - mkdir sites/all/libraries From 031d1579ad71771ef415dbf260a6ddb561974c88 Mon Sep 17 00:00:00 2001 From: jonathangreen Date: Thu, 4 Apr 2013 16:53:37 -0300 Subject: [PATCH 031/172] Updated travis to build with different fedora versions --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6626bf0e..277a591b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,7 +22,7 @@ before_install: - drush dl --yes drupal - cd drupal-* - drush si standard --db-url=mysql://drupal:drupal@localhost/drupal --yes - - drush runserver localhost:8081 &>/dev/null & + - drush runserver --php-cgi=$HOME/.phpenv/shims/php-cgi localhost:8081 &>/dev/null & - ln -s $TRAVIS_BUILD_DIR sites/all/modules/islandora - mv sites/all/modules/islandora/tests/travis.test_config.ini sites/all/modules/islandora/tests/test_config.ini - mkdir sites/all/libraries From 80aa8ed756df0dfb020f496eae5ddaadb566394f Mon Sep 17 00:00:00 2001 From: jonathangreen Date: Thu, 4 Apr 2013 17:15:18 -0300 Subject: [PATCH 032/172] moved travis setup to a script --- .travis.yml | 27 +-------------------------- tests/travis_setup.sh | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 26 deletions(-) create mode 100755 tests/travis_setup.sh diff --git a/.travis.yml b/.travis.yml index 277a591b..1adb38a4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,31 +5,6 @@ php: env: - FEDORA_VERSION="3.5" before_install: - - mysql -u root -e 'create database drupal;' - - mysql -u root -e "create database fedora;" - - mysql -u root -e "GRANT ALL PRIVILEGES ON fedora.* To 'fedora'@'localhost' IDENTIFIED BY 'fedora';" - - mysql -u root -e "GRANT ALL PRIVILEGES ON drupal.* To 'drupal'@'localhost' IDENTIFIED BY 'drupal';" - - cd $HOME - - git clone git://github.com/Islandora/tuque.git - - git clone -b $FEDORA_VERSION git://github.com/Islandora/islandora_tomcat.git - - cd islandora_tomcat - - export CATALINA_HOME='.' - - ./bin/startup.sh - - cd $HOME - - pyrus channel-discover pear.drush.org - - pyrus install drush/drush - - phpenv rehash - - drush dl --yes drupal - - cd drupal-* - - drush si standard --db-url=mysql://drupal:drupal@localhost/drupal --yes - - drush runserver --php-cgi=$HOME/.phpenv/shims/php-cgi localhost:8081 &>/dev/null & - - ln -s $TRAVIS_BUILD_DIR sites/all/modules/islandora - - mv sites/all/modules/islandora/tests/travis.test_config.ini sites/all/modules/islandora/tests/test_config.ini - - mkdir sites/all/libraries - - ln -s $HOME/tuque sites/all/libraries/tuque - - drush en --yes simpletest - - drush en --user=1 --yes islandora - - drush cc all - - sleep 4 + - $TRAVIS_BUILD_DIR/test/setup_travis.sh script: - drush test-run --uri=http://localhost:8081 Islandora diff --git a/tests/travis_setup.sh b/tests/travis_setup.sh new file mode 100755 index 00000000..936aea0d --- /dev/null +++ b/tests/travis_setup.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +mysql -u root -e 'create database drupal;' +mysql -u root -e "create database fedora;" +mysql -u root -e "GRANT ALL PRIVILEGES ON fedora.* To 'fedora'@'localhost' IDENTIFIED BY 'fedora';" +mysql -u root -e "GRANT ALL PRIVILEGES ON drupal.* To 'drupal'@'localhost' IDENTIFIED BY 'drupal';" +cd $HOME +git clone git://github.com/Islandora/tuque.git +git clone -b $FEDORA_VERSION git://github.com/Islandora/islandora_tomcat.git +cd islandora_tomcat +export CATALINA_HOME='.' +./bin/startup.sh +cd $HOME +pyrus channel-discover pear.drush.org +pyrus install drush/drush +phpenv rehash +drush dl --yes drupal +cd drupal-* +drush si standard --db-url=mysql://drupal:drupal@localhost/drupal --yes +drush runserver --php-cgi=$HOME/.phpenv/shims/php-cgi localhost:8081 &>/dev/null & +ln -s $TRAVIS_BUILD_DIR sites/all/modules/islandora +mv sites/all/modules/islandora/tests/travis.test_config.ini sites/all/modules/islandora/tests/test_config.ini +mkdir sites/all/libraries +ln -s $HOME/tuque sites/all/libraries/tuque +drush en --yes simpletest +drush en --user=1 --yes islandora +drush cc all +sleep 4 From f4c758684b977b672b84152a6f1913039265ff7f Mon Sep 17 00:00:00 2001 From: jonathangreen Date: Thu, 4 Apr 2013 17:18:24 -0300 Subject: [PATCH 033/172] Minor mistake from previous travis config --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 1adb38a4..acc9a0dc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,6 @@ php: env: - FEDORA_VERSION="3.5" before_install: - - $TRAVIS_BUILD_DIR/test/setup_travis.sh + - $TRAVIS_BUILD_DIR/tests/setup_travis.sh script: - drush test-run --uri=http://localhost:8081 Islandora From 3b5e7cda938c3adb2171816cb79605ea94d80bf5 Mon Sep 17 00:00:00 2001 From: jonathangreen Date: Thu, 4 Apr 2013 17:20:42 -0300 Subject: [PATCH 034/172] Another dumb path error --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index acc9a0dc..dcd11c3e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,6 @@ php: env: - FEDORA_VERSION="3.5" before_install: - - $TRAVIS_BUILD_DIR/tests/setup_travis.sh + - $TRAVIS_BUILD_DIR/tests/travis_setup.sh script: - drush test-run --uri=http://localhost:8081 Islandora From 6e49122ad090a815663227c85c37092d943e77ca Mon Sep 17 00:00:00 2001 From: jonathangreen Date: Thu, 4 Apr 2013 17:27:15 -0300 Subject: [PATCH 035/172] should work again --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index dcd11c3e..99d605b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,5 +6,6 @@ env: - FEDORA_VERSION="3.5" before_install: - $TRAVIS_BUILD_DIR/tests/travis_setup.sh + - cd drupal-* script: - drush test-run --uri=http://localhost:8081 Islandora From 28b66eaf8e5a33e040c520c49a7d853320f3c390 Mon Sep 17 00:00:00 2001 From: jonathangreen Date: Thu, 4 Apr 2013 17:34:35 -0300 Subject: [PATCH 036/172] another update for paths --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 99d605b4..96872f5c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,6 @@ env: - FEDORA_VERSION="3.5" before_install: - $TRAVIS_BUILD_DIR/tests/travis_setup.sh - - cd drupal-* + - cd $HOME/drupal-* script: - drush test-run --uri=http://localhost:8081 Islandora From 9d714e1c81ab7e67040514d73f79dbadcd687cff Mon Sep 17 00:00:00 2001 From: jonathangreen Date: Thu, 4 Apr 2013 17:56:16 -0300 Subject: [PATCH 037/172] Added some branch exclusions. Renamed readme. --- .travis.yml | 3 +++ README.txt => README.md | 0 2 files changed, 3 insertions(+) rename README.txt => README.md (100%) diff --git a/.travis.yml b/.travis.yml index 96872f5c..e5ced01d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,9 @@ language: php php: - 5.3.3 - 5.4 +branches: + only: + - 7.x env: - FEDORA_VERSION="3.5" before_install: diff --git a/README.txt b/README.md similarity index 100% rename from README.txt rename to README.md From a501d8a6495caf7ba15a58cb79b44539a3008448 Mon Sep 17 00:00:00 2001 From: jonathangreen Date: Thu, 4 Apr 2013 19:41:47 -0300 Subject: [PATCH 038/172] Added Jenkins status to readme --- README.md | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index ce276d7b..dceaec0e 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,10 @@ -CONTENTS OF THIS FILE ---------------------- - - * summary - * requirements - * installation - * configuration - * customization - * troubleshooting - * faq - * contact - * sponsors +BUILD STATUS +------------ +Current build status: +[![Build Status](https://travis-ci.org/Islandora/islandora.png?branch=7.x)](https://travis-ci.org/Islandora/islandora) +CI Server: +http://jenkins.discoverygarden.ca:8080 SUMMARY ------- From 092133272e6c910936db36b1e7e4411a28f0a9e6 Mon Sep 17 00:00:00 2001 From: jonathangreen Date: Thu, 4 Apr 2013 20:09:18 -0300 Subject: [PATCH 039/172] Added codesniffer to travisci When code is pushed it is now failed if it fails codesniffer. Also pushed a number of coding standards fixes so that this commit will build correctly. --- .travis.yml | 3 ++- includes/object_properties.form.inc | 4 ++-- includes/tuque_wrapper.inc | 2 +- islandora.install | 5 +++-- islandora.module | 2 +- tests/travis_setup.sh | 3 +++ tests/web_test_case.inc | 3 ++- theme/islandora-objects.tpl.php | 8 +++++++- 8 files changed, 21 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index e5ced01d..dc0a8794 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,5 +10,6 @@ env: before_install: - $TRAVIS_BUILD_DIR/tests/travis_setup.sh - cd $HOME/drupal-* -script: +script: + - drush dcs sites/all/modules/islandora - drush test-run --uri=http://localhost:8081 Islandora diff --git a/includes/object_properties.form.inc b/includes/object_properties.form.inc index 0898db0c..c9de5e8f 100644 --- a/includes/object_properties.form.inc +++ b/includes/object_properties.form.inc @@ -43,14 +43,14 @@ function islandora_object_properties_form(array $form, array &$form_state, Fedor '#title' => t('Owner'), '#default_value' => $object->owner, '#required' => FALSE, - '#description' => t('The owner\'s account name'), + '#description' => t("The owner's account name"), '#type' => 'textfield', ), 'object_state' => array( '#title' => t('State'), '#default_value' => $object->state, '#required' => TRUE, - '#description' => t('The object\'s state (active, inactive or deleted)'), + '#description' => t("The object's state (active, inactive or deleted)"), '#type' => 'select', '#options' => array('A' => 'Active', 'I' => 'Inactive', 'D' => 'Deleted'), ), diff --git a/includes/tuque_wrapper.inc b/includes/tuque_wrapper.inc index 8e4e8a0f..4d989e9f 100644 --- a/includes/tuque_wrapper.inc +++ b/includes/tuque_wrapper.inc @@ -36,7 +36,7 @@ $islandora_module_path = drupal_get_path('module', 'islandora'); */ function islandora_alter_object(AbstractFedoraObject $object, array &$context) { module_load_include('inc', 'islandora', 'includes/utilities'); - drupal_alter(islandora_build_hook_list('islandora_object', $object->models) ,$object, $context); + drupal_alter(islandora_build_hook_list('islandora_object', $object->models), $object, $context); } /** diff --git a/islandora.install b/islandora.install index 9a1825b5..caff7d75 100644 --- a/islandora.install +++ b/islandora.install @@ -10,13 +10,14 @@ */ function islandora_requirements($phase) { $requirements = array(); - // Ensure translations don't break at install time + + // Ensure translations don't break at install time. $t = get_t(); if (!class_exists('XSLTProcessor', FALSE)) { $requirements['islandora_xsltprocessor']['title'] = $t('Islandora XSLTProcessor Prerequisite'); $requirements['islandora_xsltprocessor']['value'] = $t('Not installed'); - $link = l($t('PHP XSL extension'), 'http://us2.php.net/manual/en/book.xsl.php', array('attributes' => array('target'=>'_blank'))); + $link = l($t('PHP XSL extension'), 'http://us2.php.net/manual/en/book.xsl.php', array('attributes' => array('target' => '_blank'))); $requirements['islandora_xsltprocessor']['description'] = $t('The !xsllink is required. Check your installed PHP extensions and php.ini file.', array('!xsllink' => $link)); $requirements['islandora_xsltprocessor']['severity'] = REQUIREMENT_ERROR; } diff --git a/islandora.module b/islandora.module index 05a3a57b..981189bc 100644 --- a/islandora.module +++ b/islandora.module @@ -120,7 +120,7 @@ function islandora_menu() { FEDORA_METADATA_EDIT, FEDORA_ADD_DS, FEDORA_PURGE, - FEDORA_INGEST + FEDORA_INGEST, ), 2), ); diff --git a/tests/travis_setup.sh b/tests/travis_setup.sh index 936aea0d..abbaccd2 100755 --- a/tests/travis_setup.sh +++ b/tests/travis_setup.sh @@ -13,6 +13,7 @@ export CATALINA_HOME='.' cd $HOME pyrus channel-discover pear.drush.org pyrus install drush/drush +pyrus install pear/PHP_CodeSniffer phpenv rehash drush dl --yes drupal cd drupal-* @@ -22,6 +23,8 @@ ln -s $TRAVIS_BUILD_DIR sites/all/modules/islandora mv sites/all/modules/islandora/tests/travis.test_config.ini sites/all/modules/islandora/tests/test_config.ini mkdir sites/all/libraries ln -s $HOME/tuque sites/all/libraries/tuque +drush dl --yes coder +drush en --yes coder_review drush en --yes simpletest drush en --user=1 --yes islandora drush cc all diff --git a/tests/web_test_case.inc b/tests/web_test_case.inc index 3651e3db..8a5b9a00 100644 --- a/tests/web_test_case.inc +++ b/tests/web_test_case.inc @@ -18,7 +18,8 @@ class IslandoraWebTestCase extends DrupalWebTestCase { // Always enable islandora. $args[] = 'islandora'; parent::setUp($args); - // Its possible test are running before class autoloading + + // Its possible test are running before class autoloading. module_load_include('inc', 'islandora', 'includes/tuque'); module_load_include('inc', 'islandora', 'includes/tuque_wrapper'); diff --git a/theme/islandora-objects.tpl.php b/theme/islandora-objects.tpl.php index 5b55eb88..f1893ef6 100644 --- a/theme/islandora-objects.tpl.php +++ b/theme/islandora-objects.tpl.php @@ -7,7 +7,13 @@ ?>
- $display_links, 'attributes' => array('class' => array('links', 'inline')))); ?> + $display_links, + 'attributes' => array('class' => array('links', 'inline')), + ) + ); + ?> From b9d0eaebb09a171e82eca34a9d174e63aa93447c Mon Sep 17 00:00:00 2001 From: jonathangreen Date: Thu, 4 Apr 2013 20:15:17 -0300 Subject: [PATCH 040/172] Added a lint to travis. Just in case. --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index dc0a8794..124d7ce9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,5 +11,6 @@ before_install: - $TRAVIS_BUILD_DIR/tests/travis_setup.sh - cd $HOME/drupal-* script: + - ant lint - drush dcs sites/all/modules/islandora - drush test-run --uri=http://localhost:8081 Islandora From d67c95f90174876700121d3b56aea8062c65a29f Mon Sep 17 00:00:00 2001 From: jonathangreen Date: Thu, 4 Apr 2013 20:22:27 -0300 Subject: [PATCH 041/172] Fixed ant path issue --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 124d7ce9..0c5fe32a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,6 @@ before_install: - $TRAVIS_BUILD_DIR/tests/travis_setup.sh - cd $HOME/drupal-* script: - - ant lint + - ant -buildfile sites/all/modules/islandora/build.xml lint - drush dcs sites/all/modules/islandora - drush test-run --uri=http://localhost:8081 Islandora From a55d03c12a20a3943876c6ea68d91ffd2208156d Mon Sep 17 00:00:00 2001 From: Jonathan Green Date: Fri, 5 Apr 2013 10:03:54 -0300 Subject: [PATCH 042/172] Update README.md Removed 8080 from the jenkins URL. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index dceaec0e..fd2663b7 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Current build status: [![Build Status](https://travis-ci.org/Islandora/islandora.png?branch=7.x)](https://travis-ci.org/Islandora/islandora) CI Server: -http://jenkins.discoverygarden.ca:8080 +http://jenkins.discoverygarden.ca SUMMARY ------- From 82fa859e3ba62a73330281c96a07092f52ddceff Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Fri, 5 Apr 2013 12:57:58 -0300 Subject: [PATCH 043/172] Coding style fixes. --- islandora.module | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/islandora.module b/islandora.module index c9ea373b..64c81628 100644 --- a/islandora.module +++ b/islandora.module @@ -1077,7 +1077,7 @@ function islandora_entity_property_info() { * @return array * A renderable array. */ -function islandora_print_object(FedoraObject $object) { +function islandora_print_object(AbstractObject $object) { drupal_set_title($object->label); return theme('islandora_object_print', array('object' => $object)); } @@ -1085,7 +1085,7 @@ function islandora_print_object(FedoraObject $object) { /** * Menu callback downloads the given clip. */ -function islandora_download_clip(FedoraObject $object) { +function islandora_download_clip(AbstractObject $object) { if (isset($_GET['clip'])) { $is_https = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on'; $http_protocol = $is_https ? 'https' : 'http'; From 54401f71e0d736b02e38dd8ad03c5d6bf9f58690 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Fri, 5 Apr 2013 14:24:40 -0300 Subject: [PATCH 044/172] Work around to handle the PHP-native stream wrappers. --- includes/utilities.inc | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/includes/utilities.inc b/includes/utilities.inc index f061f72c..05c5320f 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -465,20 +465,41 @@ function islandora_prepare_new_object($namespace = NULL, $label = NULL, $datastr if (isset($ds['control_group']) && in_array($ds['control_group'], $groups)) { $control_group = $ds['control_group']; } - $ds_uri = FALSE; + + $as_file = FALSE; if (file_valid_uri($ds['datastream_file'])) { + // A local file with as a Drupal file/stream wrapper URI. $datastream_file = $ds['datastream_file']; - $ds_uri = TRUE; + $as_file = TRUE; + } + elseif (is_readable($ds['datastream_file'])) { + // A local file as a filesystem path. + $datastream_file = drupal_realpath($ds['datastream_file']); + $as_file = TRUE; } else { - $datastream_file = url($ds['datastream_file'], array('absolute' => TRUE)); + $scheme = parse_url($ds['datastream_file'], PHP_URL_SCHEME); + if (in_array($scheme, stream_get_wrappers())) { + // A URI which gets handled by one of the PHP-native stream wrappers. + $datastream_file = $ds['datastream_file']; + $as_file = TRUE; + } + else { + // XXX: Dunno... No promises? Let's try to make a URL out of whatever + // this is. + $datastream_file = url($ds['datastream_file'], array('absolute' => TRUE)); + watchdog('islandora', 'Attempting to ingest %file in islandora_prepare_new_object(), but it does not appear to be readable. We will pass the path through url(), and pass along as such.', array( + '%file' => $datastream_file, + ), WATCHDOG_WARNING); + } } + $datastream = $object->constructDatastream($dsid, $control_group); $datastream->label = $label; $datastream->mimetype = $mimetype; switch ($control_group) { case 'M': - if ($ds_uri) { + if ($as_file) { $datastream->setContentFromFile($datastream_file); } else { @@ -490,8 +511,10 @@ function islandora_prepare_new_object($namespace = NULL, $label = NULL, $datastr $datastream->setContentFromString(file_get_contents($datastream_file)); break; } + $object->ingestDatastream($datastream); } + return $object; } From 13e8839d5002c2a95b515c24c0be4b6b3958e40e Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Sat, 6 Apr 2013 16:36:04 -0300 Subject: [PATCH 045/172] Allow breadcrumbs to reliably be generated multiple times. --- includes/breadcrumb.inc | 88 +++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 42 deletions(-) diff --git a/includes/breadcrumb.inc b/includes/breadcrumb.inc index dd8544a8..94dbd122 100644 --- a/includes/breadcrumb.inc +++ b/includes/breadcrumb.inc @@ -25,13 +25,8 @@ * drupal_set_breadcrumb(). */ function islandora_get_breadcrumbs($object) { - $breadcrumbs = array(); - islandora_get_breadcrumbs_recursive($object->id, $breadcrumbs, $object->repository); - if (isset($breadcrumbs[0])) { - // Remove the actual object. - unset($breadcrumbs[0]); - } - $breadcrumbs = array_reverse($breadcrumbs); + $breadcrumbs = islandora_get_breadcrumbs_recursive($object->id, $object->repository); + array_pop($breadcrumbs); return $breadcrumbs; } @@ -40,9 +35,6 @@ function islandora_get_breadcrumbs($object) { * * @todo Make fully recursive... * - * @todo Could use some clean up, can't be called multiple times safely due to - * the use of static variables. - * * @param string $pid * THe object id whose parent will be fetched for the next link. * @param array $breadcrumbs @@ -50,39 +42,44 @@ function islandora_get_breadcrumbs($object) { * @param FedoraRepository $repository * The fedora repository. */ -function islandora_get_breadcrumbs_recursive($pid, array &$breadcrumbs, FedoraRepository $repository) { +function islandora_get_breadcrumbs_recursive($pid, FedoraRepository $repository, array &$context = NULL) { // Before executing the query, we have a base case of accessing the top-level // collection. - static $max_level = 10; - static $level = -1; - - if (count($breadcrumbs) === 0) { - $level = $max_level; + if ($context === NULL) { + $context['level'] = 10; } $root = variable_get('islandora_repository_pid', 'islandora:root'); if ($pid == $root) { - $breadcrumbs[] = l(menu_get_active_title(), 'islandora'); - $breadcrumbs[] = l(t('Home'), ''); + return array( + l(t('Home'), ''), + l(menu_get_active_title(), 'islandora'), + ); } else { - $query_string = 'select $parentObject $title $content from <#ri> - where ( - $title - and $parentObject $content - and ( - $parentObject - or $parentObject - or $parentObject - ) - and $parentObject - ) - minus $content - minus $parentObject - order by $title desc'; - $results = $repository->ri->itqlQuery($query_string); + $query_string = << +WHERE { + ?object ?title ; + { + ?object ?parentObject . + } + UNION { + ?object ?parentObject . + } + UNION { + ?object ?parentObject . + } + ?parentObject . + FILTER (sameTerm(?object, )) + FILTER (!sameTerm(?object, ?parentObject)) +} +ORDER BY ?title +EOQ; + $results = $repository->ri->sparqlQuery($query_string); - if (count($results) > 0 && $level > 0) { + if (count($results) > 0 && $context['level'] > 0) { $parent = $results[0]['parentObject']['value']; $this_title = $results[0]['title']['value']; @@ -90,16 +87,23 @@ function islandora_get_breadcrumbs_recursive($pid, array &$breadcrumbs, FedoraRe $this_title = t('-'); } - $breadcrumbs[] = l($this_title, "islandora/object/$pid"); - - $level--; - islandora_get_breadcrumbs_recursive($parent, $breadcrumbs, $repository); + $context['level']--; + return array_merge( + islandora_get_breadcrumbs_recursive($parent, $repository, $context), + array( + l($this_title, "islandora/object/$pid"), + ) + ); } else { - // Add an non-link, as we don't know how to get back to the root. - $breadcrumbs[] = '...'; - // And render the last two links and break (on the next pass). - islandora_get_breadcrumbs_recursive($root, $breadcrumbs, $repository); + // Add an non-link, as we don't know how to get back to the root, and + // render the last two links and break (on the next pass). + return array_merge( + islandora_get_breadcrumbs_recursive($root, $repository), + array( + '...' + ) + ); } } } From 7c9b20237bb8a2487a79040f1baed9a19ca37c10 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Sat, 6 Apr 2013 16:40:08 -0300 Subject: [PATCH 046/172] Add content model dependant call of hook_islandora_object_view_alter(). --- islandora.api.php | 13 +++++++++++++ islandora.module | 5 +++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/islandora.api.php b/islandora.api.php index 5e976194..a4fe1552 100644 --- a/islandora.api.php +++ b/islandora.api.php @@ -50,6 +50,19 @@ function hook_CMODEL_PID_islandora_view_object($object) { function hook_islandora_view_object_alter(&$object, &$rendered) { } +/** + * Alter display output if the object has the given model. + * + * @see hook_islandora_view_object_alter() + * @param FedoraObject $object + * A Tuque FedoraObject being operated on. + * @param array $rendered + * An arr of rendered views. + */ +function hook_CMODEL_PID_islandora_view_object_alter(&$object, &$rendered) { + +} + /** * Generate an object's management display. * diff --git a/islandora.module b/islandora.module index 981189bc..eafa271a 100644 --- a/islandora.module +++ b/islandora.module @@ -675,7 +675,8 @@ function islandora_view_object(FedoraObject $object) { $page_number = (empty($_GET['page'])) ? '1' : $_GET['page']; $page_size = (empty($_GET['pagesize'])) ? '10' : $_GET['pagesize']; $output = array(); - foreach (islandora_build_hook_list(ISLANDORA_VIEW_HOOK, $object->models) as $hook) { + $hooks = islandora_build_hook_list(ISLANDORA_VIEW_HOOK, $object->models); + foreach ($hooks as $hook) { // @todo Remove page number and size from this hook, implementers of the // hook should use drupal page handling directly. $temp = module_invoke_all($hook, $object, $page_number, $page_size); @@ -688,7 +689,7 @@ function islandora_view_object(FedoraObject $object) { $output = islandora_default_islandora_view_object($object); } arsort($output); - drupal_alter(ISLANDORA_VIEW_HOOK, $object, $output); + drupal_alter($hooks, $object, $output); return implode('', $output); } From fa569990643c0e29a42df7b73a78411b3361a1df Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Sat, 6 Apr 2013 17:17:20 -0300 Subject: [PATCH 047/172] Revert "Work around to handle the PHP-native stream wrappers." This reverts commit 54401f71e0d736b02e38dd8ad03c5d6bf9f58690. --- includes/utilities.inc | 31 ++++--------------------------- 1 file changed, 4 insertions(+), 27 deletions(-) diff --git a/includes/utilities.inc b/includes/utilities.inc index 05c5320f..f061f72c 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -465,41 +465,20 @@ function islandora_prepare_new_object($namespace = NULL, $label = NULL, $datastr if (isset($ds['control_group']) && in_array($ds['control_group'], $groups)) { $control_group = $ds['control_group']; } - - $as_file = FALSE; + $ds_uri = FALSE; if (file_valid_uri($ds['datastream_file'])) { - // A local file with as a Drupal file/stream wrapper URI. $datastream_file = $ds['datastream_file']; - $as_file = TRUE; - } - elseif (is_readable($ds['datastream_file'])) { - // A local file as a filesystem path. - $datastream_file = drupal_realpath($ds['datastream_file']); - $as_file = TRUE; + $ds_uri = TRUE; } else { - $scheme = parse_url($ds['datastream_file'], PHP_URL_SCHEME); - if (in_array($scheme, stream_get_wrappers())) { - // A URI which gets handled by one of the PHP-native stream wrappers. - $datastream_file = $ds['datastream_file']; - $as_file = TRUE; - } - else { - // XXX: Dunno... No promises? Let's try to make a URL out of whatever - // this is. - $datastream_file = url($ds['datastream_file'], array('absolute' => TRUE)); - watchdog('islandora', 'Attempting to ingest %file in islandora_prepare_new_object(), but it does not appear to be readable. We will pass the path through url(), and pass along as such.', array( - '%file' => $datastream_file, - ), WATCHDOG_WARNING); - } + $datastream_file = url($ds['datastream_file'], array('absolute' => TRUE)); } - $datastream = $object->constructDatastream($dsid, $control_group); $datastream->label = $label; $datastream->mimetype = $mimetype; switch ($control_group) { case 'M': - if ($as_file) { + if ($ds_uri) { $datastream->setContentFromFile($datastream_file); } else { @@ -511,10 +490,8 @@ function islandora_prepare_new_object($namespace = NULL, $label = NULL, $datastr $datastream->setContentFromString(file_get_contents($datastream_file)); break; } - $object->ingestDatastream($datastream); } - return $object; } From 945d8f4188a2a6dcb4d856035d830f40f6e85a9d Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Sat, 6 Apr 2013 17:19:44 -0300 Subject: [PATCH 048/172] Revert back to iTQL query for breadcrumbs. --- includes/breadcrumb.inc | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/includes/breadcrumb.inc b/includes/breadcrumb.inc index 94dbd122..497caeaa 100644 --- a/includes/breadcrumb.inc +++ b/includes/breadcrumb.inc @@ -57,27 +57,21 @@ function islandora_get_breadcrumbs_recursive($pid, FedoraRepository $repository, ); } else { - $query_string = << -WHERE { - ?object ?title ; - { - ?object ?parentObject . - } - UNION { - ?object ?parentObject . - } - UNION { - ?object ?parentObject . - } - ?parentObject . - FILTER (sameTerm(?object, )) - FILTER (!sameTerm(?object, ?parentObject)) -} -ORDER BY ?title -EOQ; - $results = $repository->ri->sparqlQuery($query_string); + $query_string = 'select $parentObject $title $content from <#ri> + where ( + $title + and $parentObject $content + and ( + $parentObject + or $parentObject + or $parentObject + ) + and $parentObject + ) + minus $content + minus $parentObject + order by $title desc'; + $results = $repository->ri->itqlQuery($query_string); if (count($results) > 0 && $context['level'] > 0) { $parent = $results[0]['parentObject']['value']; From 068535ce95f8f5680dfd252586ea30f34ba60eb3 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Sat, 6 Apr 2013 17:31:03 -0300 Subject: [PATCH 049/172] Fixes for Travis... Oops. --- includes/breadcrumb.inc | 6 ++---- islandora.api.php | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/includes/breadcrumb.inc b/includes/breadcrumb.inc index 497caeaa..01d4b9f7 100644 --- a/includes/breadcrumb.inc +++ b/includes/breadcrumb.inc @@ -36,9 +36,7 @@ function islandora_get_breadcrumbs($object) { * @todo Make fully recursive... * * @param string $pid - * THe object id whose parent will be fetched for the next link. - * @param array $breadcrumbs - * The list of existing bread-crumb links in reverse order. + * The object id whose parent will be fetched for the next link. * @param FedoraRepository $repository * The fedora repository. */ @@ -95,7 +93,7 @@ function islandora_get_breadcrumbs_recursive($pid, FedoraRepository $repository, return array_merge( islandora_get_breadcrumbs_recursive($root, $repository), array( - '...' + '...', ) ); } diff --git a/islandora.api.php b/islandora.api.php index a4fe1552..b47bbcdc 100644 --- a/islandora.api.php +++ b/islandora.api.php @@ -54,13 +54,13 @@ function hook_islandora_view_object_alter(&$object, &$rendered) { * Alter display output if the object has the given model. * * @see hook_islandora_view_object_alter() + * * @param FedoraObject $object * A Tuque FedoraObject being operated on. * @param array $rendered * An arr of rendered views. */ function hook_CMODEL_PID_islandora_view_object_alter(&$object, &$rendered) { - } /** From f9586f9f9b05b4653b82ea733aeb289d751972bd Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Mon, 8 Apr 2013 18:36:54 -0300 Subject: [PATCH 050/172] Fix where the context failed to get passed. --- includes/breadcrumb.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/breadcrumb.inc b/includes/breadcrumb.inc index 01d4b9f7..5a21b86c 100644 --- a/includes/breadcrumb.inc +++ b/includes/breadcrumb.inc @@ -91,7 +91,7 @@ function islandora_get_breadcrumbs_recursive($pid, FedoraRepository $repository, // Add an non-link, as we don't know how to get back to the root, and // render the last two links and break (on the next pass). return array_merge( - islandora_get_breadcrumbs_recursive($root, $repository), + islandora_get_breadcrumbs_recursive($root, $repository, $context), array( '...', ) From 12bd3005841d4f87ed08deec52d73f01b021d9ad Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Mon, 8 Apr 2013 18:52:40 -0300 Subject: [PATCH 051/172] Flesh out inline function documentation. --- includes/breadcrumb.inc | 8 ++++++++ islandora.api.php | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/includes/breadcrumb.inc b/includes/breadcrumb.inc index 5a21b86c..6fdf9e4a 100644 --- a/includes/breadcrumb.inc +++ b/includes/breadcrumb.inc @@ -39,6 +39,14 @@ function islandora_get_breadcrumbs($object) { * The object id whose parent will be fetched for the next link. * @param FedoraRepository $repository * The fedora repository. + * @param array $context + * An associative array of context for internal use when recursing. Currently + * only used to track a single value: + * - level: The number of child-parent relationships to follow. Defaults to + * 10. + * + * @return array + * An array of links representing the breadcrumb trail, "root" first. */ function islandora_get_breadcrumbs_recursive($pid, FedoraRepository $repository, array &$context = NULL) { // Before executing the query, we have a base case of accessing the top-level diff --git a/islandora.api.php b/islandora.api.php index b47bbcdc..d1d58f4f 100644 --- a/islandora.api.php +++ b/islandora.api.php @@ -45,7 +45,7 @@ function hook_CMODEL_PID_islandora_view_object($object) { * @param FedoraObject $object * A Tuque FedoraObject being operated on. * @param array $rendered - * An arr of rendered views. + * The array of rendered views. */ function hook_islandora_view_object_alter(&$object, &$rendered) { } @@ -58,7 +58,7 @@ function hook_islandora_view_object_alter(&$object, &$rendered) { * @param FedoraObject $object * A Tuque FedoraObject being operated on. * @param array $rendered - * An arr of rendered views. + * The array of rendered views. */ function hook_CMODEL_PID_islandora_view_object_alter(&$object, &$rendered) { } From 8ef10660538411a0107707510388f35bdeb11bfb Mon Sep 17 00:00:00 2001 From: Islandora Date: Tue, 9 Apr 2013 13:42:17 -0300 Subject: [PATCH 052/172] Updated islandora_prepare_new_object to work with file system paths instead of a url. --- includes/utilities.inc | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/includes/utilities.inc b/includes/utilities.inc index f061f72c..05c5320f 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -465,20 +465,41 @@ function islandora_prepare_new_object($namespace = NULL, $label = NULL, $datastr if (isset($ds['control_group']) && in_array($ds['control_group'], $groups)) { $control_group = $ds['control_group']; } - $ds_uri = FALSE; + + $as_file = FALSE; if (file_valid_uri($ds['datastream_file'])) { + // A local file with as a Drupal file/stream wrapper URI. $datastream_file = $ds['datastream_file']; - $ds_uri = TRUE; + $as_file = TRUE; + } + elseif (is_readable($ds['datastream_file'])) { + // A local file as a filesystem path. + $datastream_file = drupal_realpath($ds['datastream_file']); + $as_file = TRUE; } else { - $datastream_file = url($ds['datastream_file'], array('absolute' => TRUE)); + $scheme = parse_url($ds['datastream_file'], PHP_URL_SCHEME); + if (in_array($scheme, stream_get_wrappers())) { + // A URI which gets handled by one of the PHP-native stream wrappers. + $datastream_file = $ds['datastream_file']; + $as_file = TRUE; + } + else { + // XXX: Dunno... No promises? Let's try to make a URL out of whatever + // this is. + $datastream_file = url($ds['datastream_file'], array('absolute' => TRUE)); + watchdog('islandora', 'Attempting to ingest %file in islandora_prepare_new_object(), but it does not appear to be readable. We will pass the path through url(), and pass along as such.', array( + '%file' => $datastream_file, + ), WATCHDOG_WARNING); + } } + $datastream = $object->constructDatastream($dsid, $control_group); $datastream->label = $label; $datastream->mimetype = $mimetype; switch ($control_group) { case 'M': - if ($ds_uri) { + if ($as_file) { $datastream->setContentFromFile($datastream_file); } else { @@ -490,8 +511,10 @@ function islandora_prepare_new_object($namespace = NULL, $label = NULL, $datastr $datastream->setContentFromString(file_get_contents($datastream_file)); break; } + $object->ingestDatastream($datastream); } + return $object; } From 663589d8fcf05074f772f913753d546a4b4a6136 Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Wed, 10 Apr 2013 11:31:56 -0300 Subject: [PATCH 053/172] added function to create tableselect form item for content model selection --- includes/utilities.inc | 98 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 81 insertions(+), 17 deletions(-) diff --git a/includes/utilities.inc b/includes/utilities.inc index f061f72c..ae7f4b61 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -124,8 +124,7 @@ function islandora_describe_repository($url = NULL) { try { $info = $connection->api->a->describeRepository(); return $info; - } - catch (RepositoryException $e) { + } catch (RepositoryException $e) { return FALSE; } } @@ -204,13 +203,13 @@ function islandora_escape_pid_for_function($pid) { // Apparently, case doesn't matter for function calls in PHP, so let's not // really worry about changing the case. return str_replace( - // Any PID characters which are not valid in the name of a PHP function. - array( - ':', - '-', - ), - '_', - $pid + // Any PID characters which are not valid in the name of a PHP function. + array( + ':', + '-', + ), + '_', + $pid ); } @@ -281,16 +280,15 @@ function islandora_namespace_accessible($id) { function islandora_get_parents_from_rels_ext(FedoraObject $object) { try { $collections = array_merge( - $object->relationships->get(FEDORA_RELS_EXT_URI, 'isMemberOfCollection'), - $object->relationships->get(FEDORA_RELS_EXT_URI, 'isMemberOf')); - } - catch (RepositoryException $e) { + $object->relationships->get(FEDORA_RELS_EXT_URI, 'isMemberOfCollection'), + $object->relationships->get(FEDORA_RELS_EXT_URI, 'isMemberOf')); + } catch (RepositoryException $e) { // @todo some logging would be nice, not sure what this throws. return array(); } $map = function($o) { - return islandora_object_load($o['object']['value']); - }; + return islandora_object_load($o['object']['value']); + }; $collections = array_map($map, $collections); return array_filter($collections); } @@ -505,7 +503,7 @@ function islandora_display_repository_inaccessible_message() { $text = t('Islandora configuration'); $link = l($text, 'admin/islandora/configure', array('attributes' => array('title' => $text))); $message = t('Could not connect to the repository. Please check the settings on the !link page.', - array('!link' => $link)); + array('!link' => $link)); drupal_set_message($message, 'error', FALSE); } @@ -731,10 +729,76 @@ function islandora_get_content_models($ignore_system_namespace = TRUE) { $label = $result['label']['value']; $namespace = islandora_get_namespace($content_model); $ignore = $ignore_system_namespace && $namespace == 'fedora-system'; - $ignore |= !islandora_namespace_accessible($namespace); + $ignore |= ! islandora_namespace_accessible($namespace); if (!$ignore) { $content_models[$content_model] = array('pid' => $content_model, 'label' => $label); } } return $content_models; } + +/** + * Returns Drupal tableselect element allowing selection of one or more Content Models + * Primarily useful for Admin screens + * @param string $variable + * the name of the Drupal variable holding selected content models + * Content models held in this variable will appear at the top of the displyed list + * @return array Drupal form element allowing content model selection + */ + +function islandora_content_model_select_table_form_element($variable) { + $connection = islandora_get_tuque_connection(); + $restricted = variable_get('islandora_namespace_restriction_enforced', FALSE); + $allowed_string = variable_get('islandora_pids_allowed', 'default: demo: changeme: islandora:'); + $namespaces = explode(':', $allowed_string); + foreach ($namespaces as $namespace) { + if ($namespace) { + $allowed[] = trim($namespace); + } + } + $query = 'select $object $title from <#ri> + where ($object $title + and ($object + or $object ) + and $object ) + order by $title'; + + $list = $connection->repository->ri->itqlQuery($query, 'unlimited'); + $other_list = islandora_get_content_models(TRUE); + $options = array(); + + foreach ($other_list as $pid => $label) { + if ($pid) { + $item_namespace = explode(':', $pid); + if (!$restricted || in_array($item_namespace[0], $allowed)) { + + if (!preg_match('/fedora-system/', $pid)) { + $options[$pid] = $label; + } + } + } + } + + $selected = variable_get($variable, array('')); + foreach ($selected as $cmodel) { + $options = array($cmodel => $options[$cmodel]) + $options; + } + foreach ($options as $key => $value) { + $rows[$key] = array( + 'pid' => $key, + 'title' => $value, + ); + in_array($key, $selected) ? $defaults[$key] = TRUE : $defaults[$key] = FALSE; + } + $header = array( + 'pid' => array('data' => t('PID')), + 'title' => array('data' => t('Content Model')), + ); +//build and return table element + return array( + '#type' => 'tableselect', + '#header' => $header, + '#options' => $rows, + '#default_value' => $defaults, + ); +} \ No newline at end of file From 128cc45ac3b59116c7ba2843ceb706a9416df4bf Mon Sep 17 00:00:00 2001 From: Islandora Date: Wed, 10 Apr 2013 14:31:25 -0300 Subject: [PATCH 054/172] Updated comments in islandora_prepare_new_object() function. --- includes/utilities.inc | 15 +++++++++------ islandora.module | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/includes/utilities.inc b/includes/utilities.inc index 05c5320f..27c53150 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -485,12 +485,15 @@ function islandora_prepare_new_object($namespace = NULL, $label = NULL, $datastr $as_file = TRUE; } else { - // XXX: Dunno... No promises? Let's try to make a URL out of whatever - // this is. + // Schema does not match available php stream wrapper. Attempt to + // set datastream_file by url for the given scheme. Https (SSL) can + // cause this to fail, and trigger an output log in watchdog. $datastream_file = url($ds['datastream_file'], array('absolute' => TRUE)); - watchdog('islandora', 'Attempting to ingest %file in islandora_prepare_new_object(), but it does not appear to be readable. We will pass the path through url(), and pass along as such.', array( - '%file' => $datastream_file, - ), WATCHDOG_WARNING); + watchdog('islandora', 'Attempting to ingest %file in islandora_prepare_new_object(), ' . + ' but it does not appear to be readable. We will pass the path through' . + ' url(), and pass along as such.', + array('%file' => $datastream_file, ) , + WATCHDOG_WARNING); } } @@ -529,7 +532,7 @@ function islandora_display_repository_inaccessible_message() { $link = l($text, 'admin/islandora/configure', array('attributes' => array('title' => $text))); $message = t('Could not connect to the repository. Please check the settings on the !link page.', array('!link' => $link)); - drupal_set_message($message, 'error', FALSE); + drupal_set_message(check_plain($message), 'error', FALSE); } /** diff --git a/islandora.module b/islandora.module index 981189bc..e54fe0d6 100644 --- a/islandora.module +++ b/islandora.module @@ -964,7 +964,7 @@ function islandora_delete_object(FedoraObject &$object) { $object = NULL; return TRUE; } - catch(Exception $e) { + catch (Exception $e) { // Exception message gets logged in Tuque Wrapper. return FALSE; } From 66d0b6404d8ac63cabb8e4f02b44472c00fdabf2 Mon Sep 17 00:00:00 2001 From: jonathangreen Date: Wed, 10 Apr 2013 20:50:36 -0300 Subject: [PATCH 055/172] Some modifications, remove duplicate code, run copy paste detector --- .travis.yml | 1 + tests/islandora_test.info | 6 -- tests/islandora_test.module | 152 ------------------------------------ 3 files changed, 1 insertion(+), 158 deletions(-) delete mode 100644 tests/islandora_test.info delete mode 100644 tests/islandora_test.module diff --git a/.travis.yml b/.travis.yml index 0c5fe32a..d95cfb54 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,4 +13,5 @@ before_install: script: - ant -buildfile sites/all/modules/islandora/build.xml lint - drush dcs sites/all/modules/islandora + - phpcpd sites/all/modules/islandora - drush test-run --uri=http://localhost:8081 Islandora diff --git a/tests/islandora_test.info b/tests/islandora_test.info deleted file mode 100644 index c6cb57ad..00000000 --- a/tests/islandora_test.info +++ /dev/null @@ -1,6 +0,0 @@ -name = Islandora Test Module -description = Tests Hooks. Do not enable. -core = 7.x -package = Testing -hidden = TRUE -dependencies[] = islandora diff --git a/tests/islandora_test.module b/tests/islandora_test.module deleted file mode 100644 index 315b88ee..00000000 --- a/tests/islandora_test.module +++ /dev/null @@ -1,152 +0,0 @@ -id == 'test:testIngestedObjectHook') { - $_SESSION['islandora_hooks']['alter'][ISLANDORA_OBJECT_INGESTED_HOOK] = TRUE; - if ($object->label == 'block') { - $context['block'] = TRUE; - } - } - break; - - case 'modify': - if ($object->id == 'test:testModifiedObjectHook') { - $_SESSION['islandora_hooks']['alter'][ISLANDORA_OBJECT_MODIFIED_HOOK] = TRUE; - if (isset($context['params']['label']) && $context['params']['label'] == 'block') { - $context['block'] = TRUE; - } - } - elseif ($object->id == 'test:testPurgedObjectHook') { - $_SESSION['islandora_hooks']['alter'][ISLANDORA_OBJECT_PURGED_HOOK] = TRUE; - if (isset($context['params']['label']) && $context['params']['label'] == 'block') { - $context['block'] = TRUE; - } - elseif (isset($context['params']['label']) && $context['params']['label'] == 'delete') { - $context['delete'] = TRUE; - } - } - break; - - case 'purge': - if ($object->id == 'test:testPurgedObjectHook') { - $_SESSION['islandora_hooks']['alter'][ISLANDORA_OBJECT_PURGED_HOOK] = TRUE; - if ($object->label == 'block') { - $context['block'] = TRUE; - } - elseif ($object->label == 'delete') { - $context['delete'] = TRUE; - } - } - break; - } -} - -/** - * Implements hook_islandora_object_alter(). - */ -function islandora_hooks_test_islandora_datastream_alter(AbstractFedoraObject $object, AbstractFedoraDatastream $datastream, array &$context) { - switch ($context['action']) { - case 'ingest': - if ($object->id == 'test:testIngestedDatastreamHook') { - $_SESSION['islandora_hooks']['alter'][ISLANDORA_DATASTREAM_INGESTED_HOOK] = TRUE; - if ($datastream->label == 'block') { - $context['block'] = TRUE; - } - } - break; - - case 'modify': - if ($object->id == 'test:testModifiedDatastreamHook') { - $_SESSION['islandora_hooks']['alter'][ISLANDORA_DATASTREAM_MODIFIED_HOOK] = TRUE; - if (isset($context['params']['dsLabel']) && $context['params']['dsLabel'] == 'block') { - $context['block'] = TRUE; - } - } - elseif ($object->id == 'test:testPurgedDatastreamHook') { - $_SESSION['islandora_hooks']['alter'][ISLANDORA_DATASTREAM_PURGED_HOOK] = TRUE; - if (isset($context['params']['dsLabel']) && $context['params']['dsLabel'] == 'block') { - $context['block'] = TRUE; - } - elseif (isset($context['params']['dsLabel']) && $context['params']['dsLabel'] == 'delete') { - $context['delete'] = TRUE; - } - } - break; - - case 'purge': - if ($object->id == 'test:testPurgedDatastreamHook') { - $_SESSION['islandora_hooks']['alter'][ISLANDORA_DATASTREAM_PURGED_HOOK] = TRUE; - if ($datastream->label == 'block') { - $context['block'] = TRUE; - } - elseif ($datastream->label == 'delete') { - $context['delete'] = TRUE; - } - } - break; - } -} - -/** - * Implements hook_islandora_object_ingested(). - */ -function islandora_hooks_test_islandora_object_ingested(FedoraObject $object) { - if ($object->id == 'test:testIngestedObjectHook') { - $_SESSION['islandora_hooks']['hook'][ISLANDORA_OBJECT_INGESTED_HOOK] = TRUE; - } -} - -/** - * Implements hook_islandora_object_modified(). - */ -function islandora_hooks_test_islandora_object_modified(FedoraObject $object) { - if ($object->id == 'test:testModifiedObjectHook') { - $_SESSION['islandora_hooks']['hook'][ISLANDORA_OBJECT_MODIFIED_HOOK] = TRUE; - } -} - -/** - * Implements hook_islandora_object_purged(). - */ -function islandora_hooks_test_islandora_object_purged($pid) { - if ($pid == 'test:testPurgedObjectHook') { - $_SESSION['islandora_hooks']['hook'][ISLANDORA_OBJECT_PURGED_HOOK] = TRUE; - } -} - -/** - * Implements hook_islandora_datastream_ingested(). - */ -function islandora_hooks_test_islandora_datastream_ingested(FedoraObject $object, FedoraDatastream $datastream) { - if ($object->id == 'test:testIngestedDatastreamHook' && $datastream->id == "TEST") { - $_SESSION['islandora_hooks']['hook'][ISLANDORA_DATASTREAM_INGESTED_HOOK] = TRUE; - } -} - -/** - * Implements hook_islandora_datastream_modified(). - */ -function islandora_hooks_test_islandora_datastream_modified(FedoraObject $object, FedoraDatastream $datastream) { - if ($object->id == 'test:testModifiedDatastreamHook' && $datastream->id == "TEST") { - $_SESSION['islandora_hooks']['hook'][ISLANDORA_DATASTREAM_MODIFIED_HOOK] = TRUE; - } -} - -/** - * Implements hook_islandora_datastream_purged(). - */ -function islandora_hooks_test_islandora_datastream_purged(FedoraObject $object, $dsid) { - if ($object->id == 'test:testPurgedDatastreamHook' && $dsid == "TEST") { - $_SESSION['islandora_hooks']['hook'][ISLANDORA_DATASTREAM_PURGED_HOOK] = TRUE; - } -} From 3f71651af4cd0395683f679c8950af81da8559b5 Mon Sep 17 00:00:00 2001 From: jonathangreen Date: Wed, 10 Apr 2013 20:51:03 -0300 Subject: [PATCH 056/172] Add travis_setup --- tests/travis_setup.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/travis_setup.sh b/tests/travis_setup.sh index abbaccd2..041eb57f 100755 --- a/tests/travis_setup.sh +++ b/tests/travis_setup.sh @@ -12,8 +12,10 @@ export CATALINA_HOME='.' ./bin/startup.sh cd $HOME pyrus channel-discover pear.drush.org +pyrus channel-discover pear.phpqatools.org pyrus install drush/drush pyrus install pear/PHP_CodeSniffer +pyrus install pear.phpunit.de/phpcpd phpenv rehash drush dl --yes drupal cd drupal-* From 010fd655a9edbb1d6090680f072c2807ab911612 Mon Sep 17 00:00:00 2001 From: jonathangreen Date: Wed, 10 Apr 2013 20:57:44 -0300 Subject: [PATCH 057/172] Added dependancy --- tests/travis_setup.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/travis_setup.sh b/tests/travis_setup.sh index 041eb57f..b870edb3 100755 --- a/tests/travis_setup.sh +++ b/tests/travis_setup.sh @@ -13,6 +13,7 @@ export CATALINA_HOME='.' cd $HOME pyrus channel-discover pear.drush.org pyrus channel-discover pear.phpqatools.org +pyrus channel-discover pear.netpirates.net pyrus install drush/drush pyrus install pear/PHP_CodeSniffer pyrus install pear.phpunit.de/phpcpd From 86631a3787ca69d893cf90367e1bb8f8d60308fc Mon Sep 17 00:00:00 2001 From: jonathangreen Date: Wed, 10 Apr 2013 23:26:48 -0300 Subject: [PATCH 058/172] Some minor travis changes --- .travis.yml | 1 + tests/travis_setup.sh | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d95cfb54..3592876e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,7 @@ branches: env: - FEDORA_VERSION="3.5" before_install: + - ISLANDORA_DIR=$TRAVIS_BUILD_DIR - $TRAVIS_BUILD_DIR/tests/travis_setup.sh - cd $HOME/drupal-* script: diff --git a/tests/travis_setup.sh b/tests/travis_setup.sh index b870edb3..c0a5f0f2 100755 --- a/tests/travis_setup.sh +++ b/tests/travis_setup.sh @@ -22,7 +22,7 @@ drush dl --yes drupal cd drupal-* drush si standard --db-url=mysql://drupal:drupal@localhost/drupal --yes drush runserver --php-cgi=$HOME/.phpenv/shims/php-cgi localhost:8081 &>/dev/null & -ln -s $TRAVIS_BUILD_DIR sites/all/modules/islandora +ln -s $ISLANDORA_DIR sites/all/modules/islandora mv sites/all/modules/islandora/tests/travis.test_config.ini sites/all/modules/islandora/tests/test_config.ini mkdir sites/all/libraries ln -s $HOME/tuque sites/all/libraries/tuque From 11d3cc64ee98080a1211a883711c64688f54a0cb Mon Sep 17 00:00:00 2001 From: jonathangreen Date: Wed, 10 Apr 2013 23:36:12 -0300 Subject: [PATCH 059/172] Export environment variable --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 3592876e..6a42dda0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ branches: env: - FEDORA_VERSION="3.5" before_install: - - ISLANDORA_DIR=$TRAVIS_BUILD_DIR + - export ISLANDORA_DIR=$TRAVIS_BUILD_DIR - $TRAVIS_BUILD_DIR/tests/travis_setup.sh - cd $HOME/drupal-* script: From e6cb85bbb19852423a02715b13645c935afc3e4a Mon Sep 17 00:00:00 2001 From: jonathangreen Date: Thu, 11 Apr 2013 00:25:30 -0300 Subject: [PATCH 060/172] Updated phpcpd command --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6a42dda0..7ded78f4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,5 +14,5 @@ before_install: script: - ant -buildfile sites/all/modules/islandora/build.xml lint - drush dcs sites/all/modules/islandora - - phpcpd sites/all/modules/islandora + - phpcpd --names *.module,*.inc,*.test sites/all/modules/islandora - drush test-run --uri=http://localhost:8081 Islandora From f9667e66fa2acfb170fec261ff8b4d8827b7b097 Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Thu, 11 Apr 2013 09:46:17 -0300 Subject: [PATCH 061/172] Crufty menu path that was left behind. --- islandora.module | 7 ------- 1 file changed, 7 deletions(-) diff --git a/islandora.module b/islandora.module index 64c81628..d7ac4684 100644 --- a/islandora.module +++ b/islandora.module @@ -238,13 +238,6 @@ function islandora_menu() { 'access arguments' => array(FEDORA_VIEW_OBJECTS, 2), 'load arguments' => array(2), ); - $items['islandora/ingest'] = array( - 'title' => 'Add an Object', - 'page callback' => 'islandora_ingest_callback', - 'file' => 'includes/ingest.menu.inc', - 'type' => MENU_SUGGESTED_ITEM, - 'access arguments' => array(FEDORA_INGEST), - ); $items['islandora/object/%islandora_object/download_clip'] = array( 'page callback' => 'islandora_download_clip', 'page arguments' => array(2), From 7175316d11157dc67c68684a46b50b3e2fd3e173 Mon Sep 17 00:00:00 2001 From: Islandora Date: Thu, 11 Apr 2013 10:32:14 -0300 Subject: [PATCH 062/172] Corrected coding standards violations. --- includes/ingest.form.inc | 4 ++-- includes/tuque_wrapper.inc | 8 ++++---- includes/utilities.inc | 12 ++++++------ tests/hooks.test | 10 +++++----- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/includes/ingest.form.inc b/includes/ingest.form.inc index 0f8e843e..db031dc0 100644 --- a/includes/ingest.form.inc +++ b/includes/ingest.form.inc @@ -35,7 +35,7 @@ function islandora_ingest_form(array $form, array &$form_state, array $configura islandora_ingest_form_init_form_state_storage($form_state, $configuration); return islandora_ingest_form_execute_step($form, $form_state); } - catch(Exception $e) { + catch (Exception $e) { drupal_set_message($e->getMessage(), 'error'); return array(array( '#markup' => l(t('Back'), 'javascript:window.history.back();', array('external' => TRUE)))); @@ -242,7 +242,7 @@ function islandora_ingest_get_approximate_steps(array $configuration) { try { islandora_ingest_form_validate_configuration($configuration); } - catch(InvalidArgumentException $e) { + catch (InvalidArgumentException $e) { // Don't log or display exception. return array(); } diff --git a/includes/tuque_wrapper.inc b/includes/tuque_wrapper.inc index 4d989e9f..14a770e2 100644 --- a/includes/tuque_wrapper.inc +++ b/includes/tuque_wrapper.inc @@ -205,7 +205,7 @@ class IslandoraFedoraApiM extends FedoraApiM { } return $ret; } - catch(Exception $e) { + catch (Exception $e) { watchdog('islandora', 'Failed to modify datastream @dsid from @pid
code: @code
message: @msg', array( '@pid' => $pid, '@dsid' => $dsid, @@ -239,7 +239,7 @@ class IslandoraFedoraApiM extends FedoraApiM { } return $ret; } - catch(Exception $e) { + catch (Exception $e) { watchdog('islandora', 'Failed to modify object: @pid
code: @code
message: @msg', array( '@pid' => $pid, '@code' => $e->getCode(), @@ -281,7 +281,7 @@ class IslandoraFedoraApiM extends FedoraApiM { return $ret; } } - catch(Exception $e) { + catch (Exception $e) { watchdog('islandora', 'Failed to purge datastream @dsid from @pid
code: @code
message: @msg', array( '@pid' => $pid, '@dsid' => $dsid, @@ -325,7 +325,7 @@ class IslandoraFedoraApiM extends FedoraApiM { return $ret; } } - catch(Exception $e) { + catch (Exception $e) { watchdog('islandora', 'Failed to purge object @pid
code: @code
message: @msg', array( '@pid' => $pid, '@code' => $e->getCode(), diff --git a/includes/utilities.inc b/includes/utilities.inc index 27c53150..ec155eb9 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -486,13 +486,13 @@ function islandora_prepare_new_object($namespace = NULL, $label = NULL, $datastr } else { // Schema does not match available php stream wrapper. Attempt to - // set datastream_file by url for the given scheme. Https (SSL) can + // set datastream_file by url for the given scheme. Https (SSL) can // cause this to fail, and trigger an output log in watchdog. $datastream_file = url($ds['datastream_file'], array('absolute' => TRUE)); - watchdog('islandora', 'Attempting to ingest %file in islandora_prepare_new_object(), ' . - ' but it does not appear to be readable. We will pass the path through' . - ' url(), and pass along as such.', - array('%file' => $datastream_file, ) , + watchdog('islandora', 'Attempting to ingest %file in islandora_prepare_new_object(), ' . + ' but it does not appear to be readable. We will pass the path through' . + ' url(), and pass along as such.', + array('%file' => $datastream_file), WATCHDOG_WARNING); } } @@ -531,7 +531,7 @@ function islandora_display_repository_inaccessible_message() { $text = t('Islandora configuration'); $link = l($text, 'admin/islandora/configure', array('attributes' => array('title' => $text))); $message = t('Could not connect to the repository. Please check the settings on the !link page.', - array('!link' => $link)); + array('!link' => $link)); drupal_set_message(check_plain($message), 'error', FALSE); } diff --git a/tests/hooks.test b/tests/hooks.test index bc3020f3..3133d656 100644 --- a/tests/hooks.test +++ b/tests/hooks.test @@ -67,7 +67,7 @@ class IslandoraHooksTestCase extends IslandoraWebTestCase { $object->label = "Don't Block"; $this->repository->purgeObject($object->id); } - catch(Exception $e) { + catch (Exception $e) { // Meh... Either it didn't exist or the purge failed. } } @@ -95,7 +95,7 @@ class IslandoraHooksTestCase extends IslandoraWebTestCase { $this->fail('Blocked ingest should throw an Exception.'); $this->repository->purgeObject($object->id); } - catch(Exception $e) { + catch (Exception $e) { $this->pass('Ingest blocked and exception thrown.'); $this->assert($_SESSION['islandora_hooks']['alter'][ISLANDORA_OBJECT_INGESTED_HOOK], 'Called "hook_islandora_object_alter" when blocking ingesting via FedoraRepository::ingestObject.'); $this->assertFalse($_SESSION['islandora_hooks']['hook'][ISLANDORA_OBJECT_INGESTED_HOOK], 'Did not called ISLANDORA_OBJECT_INGESTED_HOOK when blocking ingesting via FedoraRepository::ingestObject.'); @@ -115,7 +115,7 @@ class IslandoraHooksTestCase extends IslandoraWebTestCase { $object->label = 'block'; $this->fail('Blocked modify should throw an Exception.'); } - catch(Exception $e) { + catch (Exception $e) { $this->pass('Modify blocked and exception thrown.'); $this->assertNotEqual($object->label, 'block', 'Modification did not stick.'); $this->assert($_SESSION['islandora_hooks']['alter'][ISLANDORA_OBJECT_MODIFIED_HOOK], 'Called "hook_islandora_object_alter" when blocking modifying via set magic functions.'); @@ -149,7 +149,7 @@ class IslandoraHooksTestCase extends IslandoraWebTestCase { $this->repository->purgeObject($object->id); $this->fail('Blocked modify should throw an Exception.'); } - catch(Exception $e) { + catch (Exception $e) { $this->pass('Modify blocked and exception thrown.'); $this->assert($_SESSION['islandora_hooks']['alter'][ISLANDORA_OBJECT_PURGED_HOOK], 'Called "hook_islandora_object_alter" when blocking purge via FedoraRepository::purgeObject.'); $this->assertFalse($_SESSION['islandora_hooks']['hook'][ISLANDORA_OBJECT_PURGED_HOOK], 'Called ISLANDORA_OBJECT_PURGED_HOOK when blocking purge via FedoraRepository::purgeObject.'); @@ -191,7 +191,7 @@ class IslandoraHooksTestCase extends IslandoraWebTestCase { $ds->label = 'block'; $this->fail('Blocked modify should throw an Exception.'); } - catch(Exception $e) { + catch (Exception $e) { $this->pass('Modify blocked and exception thrown.'); $this->assert($_SESSION['islandora_hooks']['alter'][ISLANDORA_DATASTREAM_MODIFIED_HOOK], 'Called "hook_islandora_datastream_alter" when blocking modifying via set magic functions.'); $this->assertFALSE($_SESSION['islandora_hooks']['hook'][ISLANDORA_DATASTREAM_MODIFIED_HOOK], 'Called ISLANDORA_DATASTREAM_MODIFIED_HOOK when blocking modifying via set magic functions.'); From 1d1e72e1e79c39d9209ceaabfad5d818d4fee4ac Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Thu, 11 Apr 2013 13:44:43 -0300 Subject: [PATCH 063/172] simplified method --- includes/utilities.inc | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/includes/utilities.inc b/includes/utilities.inc index ae7f4b61..4d51c05e 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -745,7 +745,6 @@ function islandora_get_content_models($ignore_system_namespace = TRUE) { * Content models held in this variable will appear at the top of the displyed list * @return array Drupal form element allowing content model selection */ - function islandora_content_model_select_table_form_element($variable) { $connection = islandora_get_tuque_connection(); $restricted = variable_get('islandora_namespace_restriction_enforced', FALSE); @@ -756,29 +755,7 @@ function islandora_content_model_select_table_form_element($variable) { $allowed[] = trim($namespace); } } - $query = 'select $object $title from <#ri> - where ($object $title - and ($object - or $object ) - and $object ) - order by $title'; - - $list = $connection->repository->ri->itqlQuery($query, 'unlimited'); - $other_list = islandora_get_content_models(TRUE); - $options = array(); - - foreach ($other_list as $pid => $label) { - if ($pid) { - $item_namespace = explode(':', $pid); - if (!$restricted || in_array($item_namespace[0], $allowed)) { - - if (!preg_match('/fedora-system/', $pid)) { - $options[$pid] = $label; - } - } - } - } - + $options = islandora_get_content_models(TRUE); $selected = variable_get($variable, array('')); foreach ($selected as $cmodel) { $options = array($cmodel => $options[$cmodel]) + $options; From 74beb0ca6591a14a6cf2cce57836c961d0506173 Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Thu, 11 Apr 2013 14:48:31 -0300 Subject: [PATCH 064/172] coder changes --- includes/utilities.inc | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/includes/utilities.inc b/includes/utilities.inc index 4d51c05e..a7ec74e0 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -124,7 +124,8 @@ function islandora_describe_repository($url = NULL) { try { $info = $connection->api->a->describeRepository(); return $info; - } catch (RepositoryException $e) { + } + catch (RepositoryException $e) { return FALSE; } } @@ -282,7 +283,8 @@ function islandora_get_parents_from_rels_ext(FedoraObject $object) { $collections = array_merge( $object->relationships->get(FEDORA_RELS_EXT_URI, 'isMemberOfCollection'), $object->relationships->get(FEDORA_RELS_EXT_URI, 'isMemberOf')); - } catch (RepositoryException $e) { + } + catch (RepositoryException $e) { // @todo some logging would be nice, not sure what this throws. return array(); } @@ -398,7 +400,7 @@ function islandora_get_datastreams_requirements_from_content_model(FedoraObject $xml = new SimpleXMLElement($object[DS_COMP_STREAM]->content); foreach ($xml->dsTypeModel as $ds) { $dsid = (string) $ds['ID']; - $optional = strtolower((string) $ds['optional']); + $optional = drupal_strtolower((string) $ds['optional']); $mime = array(); foreach ($ds->form as $form) { $mime[] = (string) $form['MIME']; @@ -740,12 +742,12 @@ function islandora_get_content_models($ignore_system_namespace = TRUE) { /** * Returns Drupal tableselect element allowing selection of one or more Content Models * Primarily useful for Admin screens - * @param string $variable + * @param string $drupal_variable * the name of the Drupal variable holding selected content models * Content models held in this variable will appear at the top of the displyed list * @return array Drupal form element allowing content model selection */ -function islandora_content_model_select_table_form_element($variable) { +function islandora_content_model_select_table_form_element($drupal_variable) { $connection = islandora_get_tuque_connection(); $restricted = variable_get('islandora_namespace_restriction_enforced', FALSE); $allowed_string = variable_get('islandora_pids_allowed', 'default: demo: changeme: islandora:'); @@ -756,7 +758,7 @@ function islandora_content_model_select_table_form_element($variable) { } } $options = islandora_get_content_models(TRUE); - $selected = variable_get($variable, array('')); + $selected = variable_get($drupal_variable, array('')); foreach ($selected as $cmodel) { $options = array($cmodel => $options[$cmodel]) + $options; } @@ -772,10 +774,12 @@ function islandora_content_model_select_table_form_element($variable) { 'title' => array('data' => t('Content Model')), ); //build and return table element - return array( + $element = array( '#type' => 'tableselect', '#header' => $header, '#options' => $rows, '#default_value' => $defaults, ); + + return $element; } \ No newline at end of file From 2e02f32402c9356e63aedf82c363f42f65baf6a8 Mon Sep 17 00:00:00 2001 From: jonathangreen Date: Thu, 11 Apr 2013 14:52:06 -0300 Subject: [PATCH 065/172] Some changes for travis --- tests/scripts/line_endings.sh | 14 ++++++++++++++ tests/{ => scripts}/travis_setup.sh | 0 2 files changed, 14 insertions(+) create mode 100755 tests/scripts/line_endings.sh rename tests/{ => scripts}/travis_setup.sh (100%) diff --git a/tests/scripts/line_endings.sh b/tests/scripts/line_endings.sh new file mode 100755 index 00000000..b72dde22 --- /dev/null +++ b/tests/scripts/line_endings.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +RETURN=0 +FILES=`find -L $1 -name "*.info" -o -name "*.txt" -o -name "*.md"` +echo "Testing for files with DOS line endings..." +for FILE in $FILES +do + file $FILE | grep CRLF + if [ $? == 0 ] + then + RETURN=1 + fi +done +exit $RETURN diff --git a/tests/travis_setup.sh b/tests/scripts/travis_setup.sh similarity index 100% rename from tests/travis_setup.sh rename to tests/scripts/travis_setup.sh From c3baf652d24b5066bf4b130a3a9ba4a3d6b4bcfa Mon Sep 17 00:00:00 2001 From: jonathangreen Date: Thu, 11 Apr 2013 14:53:50 -0300 Subject: [PATCH 066/172] added missing .travis.yml --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7ded78f4..a7bd2a84 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,10 +9,11 @@ env: - FEDORA_VERSION="3.5" before_install: - export ISLANDORA_DIR=$TRAVIS_BUILD_DIR - - $TRAVIS_BUILD_DIR/tests/travis_setup.sh + - $TRAVIS_BUILD_DIR/tests/scripts/travis_setup.sh - cd $HOME/drupal-* script: - ant -buildfile sites/all/modules/islandora/build.xml lint + - $ISLANDORA_DIR/tests/scripts/line_endings.sh sites/all/modules/islandora - drush dcs sites/all/modules/islandora - phpcpd --names *.module,*.inc,*.test sites/all/modules/islandora - drush test-run --uri=http://localhost:8081 Islandora From 177aaced8685de682dbbc5c71d098e5fc5be1692 Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Thu, 11 Apr 2013 14:55:29 -0300 Subject: [PATCH 067/172] format changes --- includes/utilities.inc | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/includes/utilities.inc b/includes/utilities.inc index a7ec74e0..ea0fc849 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -204,13 +204,13 @@ function islandora_escape_pid_for_function($pid) { // Apparently, case doesn't matter for function calls in PHP, so let's not // really worry about changing the case. return str_replace( - // Any PID characters which are not valid in the name of a PHP function. - array( - ':', - '-', - ), - '_', - $pid + // Any PID characters which are not valid in the name of a PHP function. + array( + ':', + '-', + ), + '_', + $pid ); } @@ -281,16 +281,16 @@ function islandora_namespace_accessible($id) { function islandora_get_parents_from_rels_ext(FedoraObject $object) { try { $collections = array_merge( - $object->relationships->get(FEDORA_RELS_EXT_URI, 'isMemberOfCollection'), - $object->relationships->get(FEDORA_RELS_EXT_URI, 'isMemberOf')); + $object->relationships->get(FEDORA_RELS_EXT_URI, 'isMemberOfCollection'), + $object->relationships->get(FEDORA_RELS_EXT_URI, 'isMemberOf')); } catch (RepositoryException $e) { // @todo some logging would be nice, not sure what this throws. return array(); } $map = function($o) { - return islandora_object_load($o['object']['value']); - }; + return islandora_object_load($o['object']['value']); + }; $collections = array_map($map, $collections); return array_filter($collections); } @@ -400,7 +400,7 @@ function islandora_get_datastreams_requirements_from_content_model(FedoraObject $xml = new SimpleXMLElement($object[DS_COMP_STREAM]->content); foreach ($xml->dsTypeModel as $ds) { $dsid = (string) $ds['ID']; - $optional = drupal_strtolower((string) $ds['optional']); + $optional = strtolower((string) $ds['optional']); $mime = array(); foreach ($ds->form as $form) { $mime[] = (string) $form['MIME']; @@ -505,7 +505,7 @@ function islandora_display_repository_inaccessible_message() { $text = t('Islandora configuration'); $link = l($text, 'admin/islandora/configure', array('attributes' => array('title' => $text))); $message = t('Could not connect to the repository. Please check the settings on the !link page.', - array('!link' => $link)); + array('!link' => $link)); drupal_set_message($message, 'error', FALSE); } @@ -731,7 +731,7 @@ function islandora_get_content_models($ignore_system_namespace = TRUE) { $label = $result['label']['value']; $namespace = islandora_get_namespace($content_model); $ignore = $ignore_system_namespace && $namespace == 'fedora-system'; - $ignore |= ! islandora_namespace_accessible($namespace); + $ignore |= !islandora_namespace_accessible($namespace); if (!$ignore) { $content_models[$content_model] = array('pid' => $content_model, 'label' => $label); } From 3b9ae796ef06725459f822b6a7251adfb275ef4d Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Thu, 11 Apr 2013 15:18:05 -0300 Subject: [PATCH 068/172] code sniffer compliant --- includes/utilities.inc | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/includes/utilities.inc b/includes/utilities.inc index ea0fc849..11c65b50 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -740,12 +740,15 @@ function islandora_get_content_models($ignore_system_namespace = TRUE) { } /** - * Returns Drupal tableselect element allowing selection of one or more Content Models - * Primarily useful for Admin screens + * Returns Drupal tableselect element allowing selection of Content Models. + * * @param string $drupal_variable * the name of the Drupal variable holding selected content models - * Content models held in this variable will appear at the top of the displyed list - * @return array Drupal form element allowing content model selection + * Content models held in this variable will appear at the top of + * the displayed list + * + * @return array + * Drupal form element allowing content model selection */ function islandora_content_model_select_table_form_element($drupal_variable) { $connection = islandora_get_tuque_connection(); @@ -773,7 +776,7 @@ function islandora_content_model_select_table_form_element($drupal_variable) { 'pid' => array('data' => t('PID')), 'title' => array('data' => t('Content Model')), ); -//build and return table element + // Build and return table element. $element = array( '#type' => 'tableselect', '#header' => $header, @@ -782,4 +785,4 @@ function islandora_content_model_select_table_form_element($drupal_variable) { ); return $element; -} \ No newline at end of file +} From b4b33df1f5eed4f07ef37861e6aeaf6012d7eef9 Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Thu, 11 Apr 2013 15:36:50 -0300 Subject: [PATCH 069/172] removed space, coding standards --- includes/utilities.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/utilities.inc b/includes/utilities.inc index 11c65b50..54fe9317 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -776,7 +776,7 @@ function islandora_content_model_select_table_form_element($drupal_variable) { 'pid' => array('data' => t('PID')), 'title' => array('data' => t('Content Model')), ); - // Build and return table element. + // Build and return table element. $element = array( '#type' => 'tableselect', '#header' => $header, From bc5717f16eed0fd5b33e5a8650866b5a239620ea Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Fri, 12 Apr 2013 03:48:30 -0300 Subject: [PATCH 070/172] Fix a couple code-style issues in inline comments. --- includes/utilities.inc | 58 ++++++++++--------------- tests/islandora_manage_permissions.test | 2 +- 2 files changed, 23 insertions(+), 37 deletions(-) diff --git a/includes/utilities.inc b/includes/utilities.inc index ec155eb9..f7363bbe 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -380,18 +380,13 @@ function islandora_get_datastreams_requirements_from_models(array $models) { * determine what datastreams are required. * * @return array - * The DS-COMPOSITE-MODEL defined datastreams that are required for the given - * object. - * - * @code - * array( - * 'DC' => array( - * 'id' => 'DC', - * 'mime' => 'text/xml', - * 'optional' => FALSE, - * ) - * ) - * @endcode + * An associative array mapping datastream IDs to associative arrays + * containing the values parsed from the DS-COMPOSITE-MODEL on the given + * object--of the form: + * - DSID: A datastream ID being described. + * - "id": A string containing ID of the datastream. + * - "mime": A array containing MIME-types the stream may have. + * - "optional": A boolean indicating if the given stream is optional. */ function islandora_get_datastreams_requirements_from_content_model(FedoraObject $object) { if (empty($object[DS_COMP_STREAM])) { @@ -621,33 +616,24 @@ function islandora_system_settings_form_default_value($name, $default_value, arr /** * Returns basic information about DS-COMPOSITE-MODEL. * + * @deprecated + * The pre-existing--and more flexible-- + * islandora_get_datastreams_requirements_from_content_model() should be + * preferred, as it addresses the case where a stream can be allowed to have + * one of a set of mimetypes (this functions appears to only return the last + * declared mimetype for a given datastream). + * * @param string $pid - * PID of content model containing DS_COMP stream. + * The PID of content model containing DS_COMP stream. * * @return array - * array of values in the following form - * - * [DC] => Array - * ( - * [mimetype] => text/xml - * ) - * - * [MODS] => Array - * ( - * [optional] => true - * [mimetype] => text/xml - * ) - * - * [RELS-EXT] => Array - * ( - * [mimetype] => application/rdf+xml - * ) - * - * [RELS-INT] => Array - * ( - * [optional] => true - * [mimetype] => application/rdf+xml - * ) + * An associative array mapping datastream IDs to an associative array + * representing the parsed DS-COMPOSITE-MODEL of the form: + * - DSID: A string containing the datastream ID. + * - "mimetype": A string containing the last mimetype declared for the + * given datastream ID. + * - "optional": An optional boolean indicating that the given datastream + * is optional. */ function islandora_get_comp_ds_mappings($pid) { $cm_object = islandora_object_load($pid); diff --git a/tests/islandora_manage_permissions.test b/tests/islandora_manage_permissions.test index 72aebd89..8fc1549f 100644 --- a/tests/islandora_manage_permissions.test +++ b/tests/islandora_manage_permissions.test @@ -90,7 +90,7 @@ class IslandoraPermissionsTestCase extends IslandoraWebTestCase { */ public function testAccessFunctions() { $object = islandora_object_load(variable_get('islandora_repository_pid', 'islandora:root')); - // Test islandora_user_access(); + // Test islandora_user_access(). // Test no object/permissions. $ret = islandora_user_access(NULL, array()); $this->assertFalse($ret, 'User access denied when no object/permissions are provided.'); From 1b404273c33ef0fbafbcd91790021c7d93e42ff2 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Fri, 12 Apr 2013 04:24:25 -0300 Subject: [PATCH 071/172] Address issues from the translation coder report. --- includes/solution_packs.inc | 115 +++++++++++++++++++++--------------- 1 file changed, 68 insertions(+), 47 deletions(-) diff --git a/includes/solution_packs.inc b/includes/solution_packs.inc index e1cf8478..a455680d 100644 --- a/includes/solution_packs.inc +++ b/includes/solution_packs.inc @@ -187,30 +187,48 @@ function islandora_solution_pack_form_submit(array $form, array &$form_state) { */ function islandora_solution_pack_batch_operation_reingest_object(NewFedoraObject $object, array &$context) { $existing_object = islandora_object_load($object->id); + $deleted = FALSE; if ($existing_object) { $deleted = islandora_delete_object($existing_object); if (!$deleted) { $object_link = l($existing_object->label, "islandora/object/{$existing_object->id}"); - drupal_set_message(t('Failed to purge existing object !object_link.', array( + drupal_set_message(filter_xss(t('Failed to purge existing object !object_link.', array( '!object_link' => $object_link, - )), 'error'); + ))), 'error'); // Failed to purge don't attempt to ingest. return; } } + // Object was deleted or did not exist. $pid = $object->id; $label = $object->label; - $action = $deleted ? 'reinstalled' : 'installed'; $object_link = l($label, "islandora/object/{$pid}"); $object = islandora_add_object($object); - $msg = $object ? "Successfully $action !object_link." : "Failed to $action @label identified by @pid."; + $params = array( + '@pid' => $pid, + '@label' => $label, + '!object_link' => $object_link, + ); + + $msg = ''; + if ($object) { + if ($deleted) { + $msg = t('Successfully reinstalled !object_link.', $params); + } + else { + $msg = t('Successfully installed !object_link.', $params); + } + } + elseif ($deleted) { + $msg = t('Failed to reinstall @label, identified by @pid.', $params); + } + else { + $msg = t('Failed to install @label, identified by @pid.', $params); + } + $status = $object ? 'status' : 'error'; - drupal_set_message(t($msg, array( - '@pid' => $pid, - '@label' => $label, - '!object_link' => $object_link, - )), $status); + drupal_set_message(filter_xss($msg), $status); } /** @@ -237,33 +255,37 @@ function islandora_install_solution_pack($module, $op = 'install') { islandora_uninstall_solution_pack($module); return; } + + $t = get_t(); + + // Some general replacements. + $admin_link = l($t('Solution Pack admin'), 'admin/islandora/solution_packs'); + $config_link = l($t('Islandora configuration'), 'admin/islandora/configure'); + $t_params = array( + '@module' => $module_name, + '!config_link' => $config_link, + '!admin_link' => $admin_link, + ); + module_load_include('module', 'islandora', 'islandora'); module_load_include('inc', 'islandora', 'includes/utilities'); module_load_include('module', $module, $module); $info_file = drupal_get_path('module', $module) . "/{$module}.info"; $info_array = drupal_parse_info_file($info_file); $module_name = $info_array['name']; - $admin_link = l(t('Solution Pack admin'), 'admin/islandora/solution_packs'); - $config_link = l(t('Islandora configuration'), 'admin/islandora/configure'); if (!islandora_describe_repository()) { - $msg = '@module: Did not install any objects. Could not connect to the '; - $msg .= 'repository. Please check the settings on the !config_link page '; - $msg .= 'and install the required objects manually on the !admin_link page.'; - drupal_set_message(st($msg, array( - '@module' => $module_name, - '!config_link' => $config_link, - '@admin_link' => $admin_link, - )), 'error'); + $msg = $t('@module: Did not install any objects. Could not connect to the repository. Please check the settings on the !config_link page and install the required objects manually on the !admin_link page.', $t_params); + drupal_set_message(filter_xss($msg), 'error'); return; } $connection = islandora_get_tuque_connection(); $required_objects = module_invoke($module, 'islandora_required_objects', $connection); $objects = $required_objects[$module]['objects']; $status_messages = array( - 'up_to_date' => 'The object already exists and is up-to-date', - 'missing_datastream' => 'The object already exists but is missing a datastream. Please reinstall the object on the !admin_link page', - 'out_of_date' => 'The object already exists but is out-of-date. Please update the object on the !admin_link page', - 'modified_datastream' => 'The object already exists but datastreams are modified. Please reinstall the object on the !admin_link page', + 'up_to_date' => $t('The object already exists and is up-to-date.', $t_params), + 'missing_datastream' => $t('The object already exists but is missing a datastream. Please reinstall the object on the !admin_link page.', $t_params), + 'out_of_date' => $t('The object already exists but is out-of-date. Please update the object on the !admin_link page.', $t_params), + 'modified_datastream' => $t('The object already exists but datastreams are modified. Please reinstall the object on the !admin_link page.', $t_params), ); foreach ($objects as $object) { $query = $connection->api->a->findObjects('query', 'pid=' . $object->id); @@ -272,26 +294,25 @@ function islandora_install_solution_pack($module, $op = 'install') { $object_link = l($label, "islandora/object/{$object->id}"); if ($already_exists) { $object_status = islandora_check_object_status($object); - $status_msg = $status_messages[$object_status['status']]; - drupal_set_message(st("@module: Did not install !object_link. $status_msg.", array( - '@module' => $module_name, + $here_params = array( + '!summary' => $t("@module: Did not install !object_link.", array( '!object_link' => $object_link, - '!admin_link' => $admin_link, - )), 'warning'); + ) + $t_params), + '!description' => $status_messages[$object_status['status']], + ); + drupal_set_message(filter_xss(format_string('!summary !description', $here_params)), 'warning'); } else { $object = islandora_add_object($object); if ($object) { - drupal_set_message(t('@module: Successfully installed. !object_link.', array( - '@module' => $module_name, + drupal_set_message(filter_xss($t('@module: Successfully installed. !object_link.', array( '!object_link' => $object_link, - )), 'status'); + ) + $t_params)), 'status'); } else { - drupal_set_message(t('@module: Failed to install. @label.', array( - '@module' => $module_name, + drupal_set_message($t('@module: Failed to install. @label.', array( '@label' => $label, - )), 'warning'); + ) + $t_params), 'warning'); } } } @@ -307,21 +328,20 @@ function islandora_install_solution_pack($module, $op = 'install') { * directly for each solution pack. */ function islandora_uninstall_solution_pack($module) { + $t = get_t(); module_load_include('module', 'islandora', 'islandora'); module_load_include('inc', 'islandora', 'includes/utilities'); module_load_include('module', $module, $module); - $config_link = l(t('Islandora configuration'), 'admin/islandora/configure'); + $config_link = l($t('Islandora configuration'), 'admin/islandora/configure'); $info_file = drupal_get_path('module', $module) . "/{$module}.info"; $info_array = drupal_parse_info_file($info_file); $module_name = $info_array['name']; if (!islandora_describe_repository()) { - $msg = '@module: Did not uninstall any objects. Could not connect to the '; - $msg .= 'repository. Please check the settings on the !config_link page '; - $msg .= 'and uninstall the required objects manually if necessary.'; - drupal_set_message(st($msg, array( - '@module' => $module_name, - '!config_link' => $config_link, - )), 'error'); + $msg = $t('@module: Did not uninstall any objects. Could not connect to the repository. Please check the settings on the !config_link page and uninstall the required objects manually if necessary.', array( + '@module' => $module_name, + '!config_link' => $config_link, + )); + drupal_set_message(filter_xss($msg), 'error'); return; } $connection = islandora_get_tuque_connection(); @@ -334,12 +354,13 @@ function islandora_uninstall_solution_pack($module) { }; $existing_objects = array_filter($objects, $filter); foreach ($existing_objects as $object) { - $msg = '@module: Did not remove !object_link. It may be used by other sites.'; $object_link = l($object->label, "islandora/object/{$object->id}"); - drupal_set_message(st($msg, array( - '!object_link' => $object_link, - '@module' => $module_name, - )), 'warning'); + $msg = $t('@module: Did not remove !object_link. It may be used by other sites.', array( + '!object_link' => $object_link, + '@module' => $module_name, + )); + + drupal_set_message(filter_xss($msg), 'warning'); } } From e0362cea25c8071ce44b7948ea58f7824300354d Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Fri, 12 Apr 2013 04:47:35 -0300 Subject: [PATCH 072/172] Fix a variable name. --- includes/solution_packs.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/solution_packs.inc b/includes/solution_packs.inc index a455680d..aa09c8a4 100644 --- a/includes/solution_packs.inc +++ b/includes/solution_packs.inc @@ -262,7 +262,7 @@ function islandora_install_solution_pack($module, $op = 'install') { $admin_link = l($t('Solution Pack admin'), 'admin/islandora/solution_packs'); $config_link = l($t('Islandora configuration'), 'admin/islandora/configure'); $t_params = array( - '@module' => $module_name, + '@module' => $module, '!config_link' => $config_link, '!admin_link' => $admin_link, ); From c5d7485153cb44192e0ac45f54364f1ce0cf4ca1 Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Fri, 12 Apr 2013 09:46:29 -0300 Subject: [PATCH 073/172] Converted CM query to sparql to allow for unlabeled Content Models --- includes/utilities.inc | 75 +++++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 33 deletions(-) diff --git a/includes/utilities.inc b/includes/utilities.inc index 54fe9317..7e5a339a 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -124,8 +124,7 @@ function islandora_describe_repository($url = NULL) { try { $info = $connection->api->a->describeRepository(); return $info; - } - catch (RepositoryException $e) { + } catch (RepositoryException $e) { return FALSE; } } @@ -204,13 +203,13 @@ function islandora_escape_pid_for_function($pid) { // Apparently, case doesn't matter for function calls in PHP, so let's not // really worry about changing the case. return str_replace( - // Any PID characters which are not valid in the name of a PHP function. - array( - ':', - '-', - ), - '_', - $pid + // Any PID characters which are not valid in the name of a PHP function. + array( + ':', + '-', + ), + '_', + $pid ); } @@ -281,16 +280,15 @@ function islandora_namespace_accessible($id) { function islandora_get_parents_from_rels_ext(FedoraObject $object) { try { $collections = array_merge( - $object->relationships->get(FEDORA_RELS_EXT_URI, 'isMemberOfCollection'), - $object->relationships->get(FEDORA_RELS_EXT_URI, 'isMemberOf')); - } - catch (RepositoryException $e) { + $object->relationships->get(FEDORA_RELS_EXT_URI, 'isMemberOfCollection'), + $object->relationships->get(FEDORA_RELS_EXT_URI, 'isMemberOf')); + } catch (RepositoryException $e) { // @todo some logging would be nice, not sure what this throws. return array(); } $map = function($o) { - return islandora_object_load($o['object']['value']); - }; + return islandora_object_load($o['object']['value']); + }; $collections = array_map($map, $collections); return array_filter($collections); } @@ -505,7 +503,7 @@ function islandora_display_repository_inaccessible_message() { $text = t('Islandora configuration'); $link = l($text, 'admin/islandora/configure', array('attributes' => array('title' => $text))); $message = t('Could not connect to the repository. Please check the settings on the !link page.', - array('!link' => $link)); + array('!link' => $link)); drupal_set_message($message, 'error', FALSE); } @@ -718,20 +716,23 @@ function islandora_get_allowed_namespaces() { function islandora_get_content_models($ignore_system_namespace = TRUE) { module_load_include('inc', 'islandora', 'includes/utilities'); $tuque = islandora_get_tuque_connection(); - $query = 'select $object $label from <#ri> - where ($object $label - and ($object - or $object ) - and $object ) - order by $label'; + $query = 'PREFIX fm: + SELECT ?object ?label + FROM <#ri> + WHERE { + ?object fm:hasModel ; + OPTIONAL{ + ?object fm:label ?label + } + }'; $content_models = array(); - $results = $tuque->repository->ri->itqlQuery($query, 'unlimited'); + $results = $tuque->repository->ri->sparqlQuery($query, 'unlimited'); foreach ($results as $result) { $content_model = $result['object']['value']; $label = $result['label']['value']; $namespace = islandora_get_namespace($content_model); $ignore = $ignore_system_namespace && $namespace == 'fedora-system'; - $ignore |= !islandora_namespace_accessible($namespace); + $ignore |= ! islandora_namespace_accessible($namespace); if (!$ignore) { $content_models[$content_model] = array('pid' => $content_model, 'label' => $label); } @@ -760,17 +761,25 @@ function islandora_content_model_select_table_form_element($drupal_variable) { $allowed[] = trim($namespace); } } - $options = islandora_get_content_models(TRUE); - $selected = variable_get($drupal_variable, array('')); - foreach ($selected as $cmodel) { - $options = array($cmodel => $options[$cmodel]) + $options; + $defaults = array(); + $options = array(); + $options = $options + islandora_get_content_models(TRUE); + + foreach($options as $option){ + $content_models[$option['pid']] = $option['label']; } - foreach ($options as $key => $value) { - $rows[$key] = array( - 'pid' => $key, - 'title' => $value, + + $selected = array_values(variable_get($drupal_variable, array(''))); + foreach($selected as $selection){ + $content_models = array($selection => $content_models[$selection]) + $content_models; + } + + foreach ($content_models as $pid => $label) { + $rows[$pid] = array( + 'pid' => $pid, + 'title' => $label, ); - in_array($key, $selected) ? $defaults[$key] = TRUE : $defaults[$key] = FALSE; + in_array($pid, $selected) ? $defaults[$pid] = TRUE : $defaults[$pid] = FALSE; } $header = array( 'pid' => array('data' => t('PID')), From cb3e9b083d50a9cf29dce7ba383c7875d4c8be79 Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Fri, 12 Apr 2013 09:59:51 -0300 Subject: [PATCH 074/172] Converted CM query to sparql to allow for unlabeled Content Models --- includes/utilities.inc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/includes/utilities.inc b/includes/utilities.inc index 7e5a339a..cd2cbd86 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -762,8 +762,9 @@ function islandora_content_model_select_table_form_element($drupal_variable) { } } $defaults = array(); - $options = array(); - $options = $options + islandora_get_content_models(TRUE); + $rows = array(); + $content_models = array(); + $options = islandora_get_content_models(TRUE); foreach($options as $option){ $content_models[$option['pid']] = $option['label']; @@ -771,7 +772,9 @@ function islandora_content_model_select_table_form_element($drupal_variable) { $selected = array_values(variable_get($drupal_variable, array(''))); foreach($selected as $selection){ - $content_models = array($selection => $content_models[$selection]) + $content_models; + if(isset($content_models[$selection])){ + $content_models = array($selection => $content_models[$selection]) + $content_models; + } } foreach ($content_models as $pid => $label) { @@ -791,6 +794,7 @@ function islandora_content_model_select_table_form_element($drupal_variable) { '#header' => $header, '#options' => $rows, '#default_value' => $defaults, + '#empty' => t("There are no content models in this Fedora Repository.") ); return $element; From 0731a26e15c303516c08d04d4c739631f7459ccb Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Fri, 12 Apr 2013 10:57:28 -0300 Subject: [PATCH 075/172] Made query more robust --- includes/utilities.inc | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/includes/utilities.inc b/includes/utilities.inc index cd2cbd86..f5922ddc 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -717,14 +717,24 @@ function islandora_get_content_models($ignore_system_namespace = TRUE) { module_load_include('inc', 'islandora', 'includes/utilities'); $tuque = islandora_get_tuque_connection(); $query = 'PREFIX fm: + PREFIX fr: SELECT ?object ?label FROM <#ri> WHERE { - ?object fm:hasModel ; + {?object fm:hasModel ; + fm:state + OPTIONAL{ + ?object fm:label ?label + } + } + UNION + {?object fr:isMemberOfCollection ; + fm:state OPTIONAL{ ?object fm:label ?label } - }'; + } + }'; $content_models = array(); $results = $tuque->repository->ri->sparqlQuery($query, 'unlimited'); foreach ($results as $result) { @@ -754,18 +764,11 @@ function islandora_get_content_models($ignore_system_namespace = TRUE) { function islandora_content_model_select_table_form_element($drupal_variable) { $connection = islandora_get_tuque_connection(); $restricted = variable_get('islandora_namespace_restriction_enforced', FALSE); - $allowed_string = variable_get('islandora_pids_allowed', 'default: demo: changeme: islandora:'); - $namespaces = explode(':', $allowed_string); - foreach ($namespaces as $namespace) { - if ($namespace) { - $allowed[] = trim($namespace); - } - } $defaults = array(); $rows = array(); $content_models = array(); + $options = islandora_get_content_models(TRUE); - foreach($options as $option){ $content_models[$option['pid']] = $option['label']; } From 273e591f6e33b3da45a202b419876238be193754 Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Fri, 12 Apr 2013 11:01:41 -0300 Subject: [PATCH 076/172] reverted auto-formatting --- includes/utilities.inc | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/includes/utilities.inc b/includes/utilities.inc index f5922ddc..90117d59 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -124,7 +124,8 @@ function islandora_describe_repository($url = NULL) { try { $info = $connection->api->a->describeRepository(); return $info; - } catch (RepositoryException $e) { + } + catch (RepositoryException $e) { return FALSE; } } @@ -203,13 +204,13 @@ function islandora_escape_pid_for_function($pid) { // Apparently, case doesn't matter for function calls in PHP, so let's not // really worry about changing the case. return str_replace( - // Any PID characters which are not valid in the name of a PHP function. - array( - ':', - '-', - ), - '_', - $pid + // Any PID characters which are not valid in the name of a PHP function. + array( + ':', + '-', + ), + '_', + $pid ); } @@ -280,15 +281,16 @@ function islandora_namespace_accessible($id) { function islandora_get_parents_from_rels_ext(FedoraObject $object) { try { $collections = array_merge( - $object->relationships->get(FEDORA_RELS_EXT_URI, 'isMemberOfCollection'), - $object->relationships->get(FEDORA_RELS_EXT_URI, 'isMemberOf')); - } catch (RepositoryException $e) { + $object->relationships->get(FEDORA_RELS_EXT_URI, 'isMemberOfCollection'), + $object->relationships->get(FEDORA_RELS_EXT_URI, 'isMemberOf')); + } + catch (RepositoryException $e) { // @todo some logging would be nice, not sure what this throws. return array(); } $map = function($o) { - return islandora_object_load($o['object']['value']); - }; + return islandora_object_load($o['object']['value']); + }; $collections = array_map($map, $collections); return array_filter($collections); } @@ -503,7 +505,7 @@ function islandora_display_repository_inaccessible_message() { $text = t('Islandora configuration'); $link = l($text, 'admin/islandora/configure', array('attributes' => array('title' => $text))); $message = t('Could not connect to the repository. Please check the settings on the !link page.', - array('!link' => $link)); + array('!link' => $link)); drupal_set_message($message, 'error', FALSE); } From c431a070f32213247a44716af63f248070a0348e Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Fri, 12 Apr 2013 11:18:49 -0300 Subject: [PATCH 077/172] minor formatting changes --- includes/utilities.inc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/includes/utilities.inc b/includes/utilities.inc index 90117d59..52186681 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -744,7 +744,7 @@ function islandora_get_content_models($ignore_system_namespace = TRUE) { $label = $result['label']['value']; $namespace = islandora_get_namespace($content_model); $ignore = $ignore_system_namespace && $namespace == 'fedora-system'; - $ignore |= ! islandora_namespace_accessible($namespace); + $ignore |= !islandora_namespace_accessible($namespace); if (!$ignore) { $content_models[$content_model] = array('pid' => $content_model, 'label' => $label); } @@ -771,13 +771,13 @@ function islandora_content_model_select_table_form_element($drupal_variable) { $content_models = array(); $options = islandora_get_content_models(TRUE); - foreach($options as $option){ + foreach ($options as $option){ $content_models[$option['pid']] = $option['label']; } $selected = array_values(variable_get($drupal_variable, array(''))); - foreach($selected as $selection){ - if(isset($content_models[$selection])){ + foreach ($selected as $selection){ + if (isset($content_models[$selection])){ $content_models = array($selection => $content_models[$selection]) + $content_models; } } @@ -799,7 +799,7 @@ function islandora_content_model_select_table_form_element($drupal_variable) { '#header' => $header, '#options' => $rows, '#default_value' => $defaults, - '#empty' => t("There are no content models in this Fedora Repository.") + '#empty' => t("There are no content models in this Fedora Repository."), ); return $element; From 37071f0ec084e1f950a4fcb7bebca080676ac611 Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Fri, 12 Apr 2013 11:31:48 -0300 Subject: [PATCH 078/172] minor formatting changes --- includes/utilities.inc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/utilities.inc b/includes/utilities.inc index 52186681..f1d221fc 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -771,13 +771,13 @@ function islandora_content_model_select_table_form_element($drupal_variable) { $content_models = array(); $options = islandora_get_content_models(TRUE); - foreach ($options as $option){ + foreach ($options as $option) { $content_models[$option['pid']] = $option['label']; } $selected = array_values(variable_get($drupal_variable, array(''))); - foreach ($selected as $selection){ - if (isset($content_models[$selection])){ + foreach ($selected as $selection) { + if (isset($content_models[$selection])) { $content_models = array($selection => $content_models[$selection]) + $content_models; } } From 8f5cf316041f997ddb5be9502668c6ec704342c1 Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Mon, 15 Apr 2013 20:01:16 -0300 Subject: [PATCH 079/172] used constants, removed unused variable --- includes/utilities.inc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/includes/utilities.inc b/includes/utilities.inc index f1d221fc..df924dce 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -718,8 +718,8 @@ function islandora_get_allowed_namespaces() { function islandora_get_content_models($ignore_system_namespace = TRUE) { module_load_include('inc', 'islandora', 'includes/utilities'); $tuque = islandora_get_tuque_connection(); - $query = 'PREFIX fm: - PREFIX fr: + $query = "PREFIX fm: <" . FEDORA_MODEL_URI . "> + PREFIX fr: <" . FEDORA_RELS_EXT_URI . "> SELECT ?object ?label FROM <#ri> WHERE { @@ -736,7 +736,7 @@ function islandora_get_content_models($ignore_system_namespace = TRUE) { ?object fm:label ?label } } - }'; + }"; $content_models = array(); $results = $tuque->repository->ri->sparqlQuery($query, 'unlimited'); foreach ($results as $result) { @@ -765,7 +765,6 @@ function islandora_get_content_models($ignore_system_namespace = TRUE) { */ function islandora_content_model_select_table_form_element($drupal_variable) { $connection = islandora_get_tuque_connection(); - $restricted = variable_get('islandora_namespace_restriction_enforced', FALSE); $defaults = array(); $rows = array(); $content_models = array(); From 5deab4f3e3df5ba6a62009e17f29772125bcf70c Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Tue, 16 Apr 2013 13:25:58 -0300 Subject: [PATCH 080/172] Update to ingest_steps to add the callback type and logic associated with that. --- includes/ingest.form.inc | 187 ++++++++++++++++++++++++++++++++++++--- islandora.api.php | 33 +++++-- 2 files changed, 202 insertions(+), 18 deletions(-) diff --git a/includes/ingest.form.inc b/includes/ingest.form.inc index db031dc0..9a6c2b9c 100644 --- a/includes/ingest.form.inc +++ b/includes/ingest.form.inc @@ -188,6 +188,8 @@ function islandora_ingest_form_get_next_step_id(array &$form_state) { */ function islandora_ingest_form_get_previous_step_id(array &$form_state) { $step_id = islandora_ingest_form_get_current_step_id($form_state); + $step = islandora_ingest_form_get_step($form_state, $step_id); + $step_ids = array_keys(islandora_ingest_form_get_steps($form_state)); $index = array_search($step_id, $step_ids); if ($index !== FALSE && --$index >= 0) { @@ -270,10 +272,10 @@ function islandora_ingest_get_approximate_steps(array $configuration) { * @return array * The form definition of the current step. */ -function islandora_ingest_form_execute_step(array $form, array &$form_state) { +function islandora_ingest_form_execute_step(array $form, array &$form_state, $step_id = NULL) { // Load any required files for the current step. islandora_ingest_form_load_include($form_state); - $step = islandora_ingest_form_get_step($form_state); + $step = isset($step_id) ? islandora_ingest_form_get_step($form_state) : islandora_ingest_form_get_step($form_state, $step_id); switch ($step['type']) { case 'form': $args = array($form, &$form_state); @@ -284,10 +286,36 @@ function islandora_ingest_form_execute_step(array $form, array &$form_state) { case 'batch': // @todo Implement if possible. break; + + case 'callback': + call_user_func_array($step['do_function']['function'], $step['do_function']['args']); + $next_step = islandora_ingest_form_get_next_step_id($form_state); + if ($next_step) { + islandora_ingest_form_increment_step($form_state); + return islandora_ingest_form_execute_step($form, $form_state, $next_step); + } } return array(); } +/** + * Handles occurances where a callback is executed to grab the next form type. + * + * @param array $form_state + * The Drupal form state. + * @param array $step + * Describes the current step. + * + * @return array + * The stepified Drupal form definition for the given step. + */ +function islandora_ingest_callback_stepify(array &$form_state, $step) { + $next_step = islandora_ingest_form_get_step($form_state, $step); + $form = call_user_func_array($next_step['form_id'], $args); + islandora_ingest_form_increment_step($form_state); + return islandora_ingest_form_stepify($form, $form_state, $next_step); +} + /** * Append Prev/Next buttons submit/validation handlers etc. * @@ -297,7 +325,7 @@ function islandora_ingest_form_execute_step(array $form, array &$form_state) { * The Drupal form state. * * @return array - * The stepified drupal form definition for the given step. + * The stepified Drupal form definition for the given step. */ function islandora_ingest_form_stepify(array $form, array &$form_state, $step) { $first_step = islandora_ingest_form_on_first_step($form_state); @@ -307,7 +335,6 @@ function islandora_ingest_form_stepify(array $form, array &$form_state, $step) { // Allow for a hook_form_FORM_ID_alter(). drupal_alter(array('form_' . $step['form_id'], 'form'), $form, $form_state, $step['form_id']); - return $form; } @@ -336,10 +363,28 @@ function islandora_ingest_form_on_first_step(array &$form_state) { * TRUE if we are currently on the last step, FALSE otherwise. */ function islandora_ingest_form_on_last_step(array &$form_state) { - $step_id = islandora_ingest_form_get_current_step_id($form_state); - $step_ids = array_keys(islandora_ingest_form_get_steps($form_state)); - $count = count($step_ids); - return array_search($step_id, $step_ids) == --$count; + $next_id = islandora_ingest_form_get_next_step_id($form_state); + if (!$next_id) { + return TRUE; + } + else { + $step_ids = array_keys(islandora_ingest_form_get_steps($form_state)); + $next_step_num = array_search($next_id, $step_ids); + $callback_chain = TRUE; + + while ($next_step_num < count($step_ids)) { + $next_step = islandora_ingest_form_get_step($form_state, $step_ids[$next_step_num]); + // Still is a form somewhere down our chain. + if ($next_step['type'] === 'form') { + $callback_chain = FALSE; + break; + } + else { + $next_step_num++; + } + } + return $callback_chain; + } } /** @@ -358,9 +403,35 @@ function islandora_ingest_form_previous_button(array &$form_state) { // to undo whatever its submit handler did. $prev_step_id = islandora_ingest_form_get_previous_step_id($form_state); $prev_step = islandora_ingest_form_get_step($form_state, $prev_step_id); - $form_id = $prev_step['form_id']; - $submit_callback = $form_id . '_undo_submit'; - $submit = function_exists($submit_callback) ? array($submit_callback, 'islandora_ingest_form_previous_submit') : array('islandora_ingest_form_undo_submit'); + + if ($prev_step['type'] === 'form') { + $form_id = $prev_step['form_id']; + $submit_callback = $form_id . '_undo_submit'; + $submit = function_exists($submit_callback) ? array($submit_callback, 'islandora_ingest_form_previous_submit') : array('islandora_ingest_form_undo_submit'); + } + elseif ($prev_step['type'] === 'callback') { + // Need to check if we have one or more callbacks at the start of our steps. + $steps = islandora_ingest_form_get_steps($form_state); + $keys = array_keys($steps); + $form = FALSE; + $current_step = array_search($prev_step_id, $keys); + while ($current_step >= 0 && !$form) { + $step = islandora_ingest_form_get_step($form_state, $keys[$current_step]); + if ($step['type'] === 'form') { + $form = TRUE; + break; + } + $current_step--; + } + // Only render a previous button if there a form somewhere behind us in our + // history chain. + if ($form) { + $submit = array('islandora_ingest_form_callback_previous'); + } + else { + return; + } + } return array( '#type' => 'submit', '#value' => t('Previous'), @@ -377,6 +448,38 @@ function islandora_ingest_form_previous_button(array &$form_state) { ); } +/** + * Handles the execution of "undoing" callbacks until a form type is reached. + * + * @param array $form + * The Drupal form. + * @param array $form_state + * The Drupal form state. + */ +function islandora_ingest_form_callback_previous(array $form, array &$form_state) { + // Arbitrarily move at least 1 back. + islandora_ingest_form_decrement_step($form_state); + $step_id = islandora_ingest_form_get_current_step_id($form_state); + $steps = islandora_ingest_form_get_steps($form_state); + $keys = array_keys($steps); + $current_step = array_search($step_id, $keys); + + $form = FALSE; + + while ($current_step >= 0 && !$form) { + $step = islandora_ingest_form_get_step($form_state, $keys[$current_step]); + islandora_ingest_form_decrement_step($form_state); + if ($step['type'] === 'callback') { + call_user_func_array($step['undo_function']['function'], $step['undo_function']['args']); + } + else { + $form = TRUE; + } + $current_step--; + } + $form_state['rebuild'] = TRUE; +} + /** * The submit handler for the ingest form previous button. * @@ -446,8 +549,10 @@ function islandora_ingest_form_next_submit(array $form, array &$form_state) { */ function islandora_ingest_form_stash_info(array &$form_state) { $storage = &islandora_ingest_form_get_step_storage($form_state); - $storage['values'] = $form_state['values']; - unset($form_state['values']); + if ($storage) { + $storage['values'] = $form_state['values']; + unset($form_state['values']); + } } /** @@ -479,6 +584,15 @@ function islandora_ingest_form_ingest_button(array &$form_state) { $validate = function_exists($validate_callback) ? array($validate_callback) : NULL; $submit_callback = $form_id . '_submit'; $submit = function_exists($submit_callback) ? array($submit_callback, 'islandora_ingest_form_submit') : array('islandora_ingest_form_submit'); + + // Because of callback shananigans we have to check if there are a chain of + // n callbacks that are weighted after the current step. + $next_id = islandora_ingest_form_get_next_step_id($form_state); + + if ($next_id) { + $submit[] = 'islandora_ingest_form_callback_ingest'; + } + return array( '#type' => 'submit', '#name' => 'ingest', @@ -513,6 +627,28 @@ function islandora_ingest_form_submit(array $form, array &$form_state) { } } +/** + * Execute any callbacks that are weighted at end of the ingest steps on ingest. + * + * @param array $form + * The Drupal form. + * @param array $form_state + * The Drupal form state. + */ +function islandora_ingest_form_callback_ingest(array $form, array &$form_state) { + $next_id = islandora_ingest_form_get_next_step_id($form_state); + $steps = islandora_ingest_form_get_steps($form_state); + $keys = array_keys($steps); + $current_step = array_search($next_id, $keys); + + // Execute our n chain of callbacks. + while ($current_step < count($steps)) { + $step = islandora_ingest_form_get_step($form_state, $keys[$current_step]); + call_user_func_array($step['do_function']['function'], $step['do_function']['args']); + $current_step++; + } +} + /** * Gets a reference to the stored NewFedoraObject's. * @@ -635,6 +771,31 @@ function islandora_ingest_form_get_steps(array &$form_state) { foreach (islandora_build_hook_list(ISLANDORA_INGEST_STEP_HOOK, $shared_storage['models']) as $hook) { drupal_alter($hook, $steps, $form_state); } + // Check to see if the callback functions are implemented (existed). Remove + // any implementations from the steps that are incorrectly defined. + foreach ($steps as $key => $step) { + $watchdog = FALSE; + if ($step['type'] === 'callback') { + if (!isset($step['do_function']) || !isset($step['undo_function'])) { + $watchdog = TRUE; + } + elseif (!isset($step['do_function']['function']) || !isset($step['undo_function']['function'])) { + $watchdog = TRUE; + } + + if ($watchdog) { + watchdog('islandora', 'The @module module is incorrectly implementing the + callback functionality of islandora_ingest_steps. The step @step has + not been included in the list of steps.', array( + '@module' => $step['module'], + '@step' => $key, + ), WATCHDOG_ERROR); + dd('errorsaursu'); + unset($steps[$key]); + } + } + } uasort($steps, 'drupal_sort_weight'); + return $steps; } diff --git a/islandora.api.php b/islandora.api.php index d1d58f4f..fbe49be6 100644 --- a/islandora.api.php +++ b/islandora.api.php @@ -386,15 +386,26 @@ function hook_islandora_undeletable_datastreams(array $models) { * @return array * An associative array of associative arrays which define each step in the * ingest process. Each step should consist of a unique name mapped to an - * array of properties (keys) including: - * - type: The type of step. Currently, only "form" is implemented. - * - weight: The "weight" of this step--heavier(/"larger") values sink to the - * end of the process while smaller(/"lighter") values are executed first. + * array of properties (keys) which take different paramaters based upon type: + * - type: Type of step. Only "form" and "callback" are implemented so far. + * Required "form" type specific parameters: * - form_id: The form building function to call to get the form structure * for this step. * - args: An array of arguments to pass to the form building function. - * And may optionally include both: + * Required "callback" type specific parameters: + * - do_function: An associate array including: + * - 'function': The callback function to be called. + * - 'args': An array of arguments to pass to the callback function. + * - undo_function: An associate array including: + * - 'function': The callback function to be called to reverse the + * executed action in the ingest steps. + * - 'args': An array of arguments to pass to the callback function. + * Shared parameters between both types: + * - weight: The "weight" of this step--heavier(/"larger") values sink to the + * end of the process while smaller(/"lighter") values are executed first. + * Both types may optionally include: * - module: A module from which we want to load an include. + * "Form type" may optionally include: * - file: A file to include (relative to the module's path, including the * file's extension). */ @@ -406,6 +417,18 @@ function hook_islandora_ingest_steps(array $form_state) { 'form_id' => 'my_cool_form', 'args' => array('arg_one', 'numero deux'), ), + 'my_cool_step_callback' => array( + 'type' => 'callback', + 'weight' => 2, + 'do_function' => array( + 'function' => 'my_cool_execute_function', + 'args' => array('arg_one', 'numero deux'), + ), + 'undo_function' => array( + 'function' => 'my_cool_undo_function', + 'args' => array('arg_one', 'numero deux'), + ), + ), ); } /** From a462a4448cd50bb4d075ac97f4c146ace5940bab Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Tue, 16 Apr 2013 16:48:37 -0300 Subject: [PATCH 081/172] Ingest functionality of the ingest form is now a callback. --- includes/ingest.form.inc | 22 ++++++++++++++-------- islandora.api.php | 2 +- islandora.module | 18 ++++++++++++++++++ 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/includes/ingest.form.inc b/includes/ingest.form.inc index 9a6c2b9c..53c48639 100644 --- a/includes/ingest.form.inc +++ b/includes/ingest.form.inc @@ -288,7 +288,9 @@ function islandora_ingest_form_execute_step(array $form, array &$form_state, $st break; case 'callback': - call_user_func_array($step['do_function']['function'], $step['do_function']['args']); + $args = array(&$form_state); + $args = isset($step['do_function']['args']) ? array_merge($args, $step['do_function']['args']) : $args; + call_user_func_array($step['do_function']['function'], $args); $next_step = islandora_ingest_form_get_next_step_id($form_state); if ($next_step) { islandora_ingest_form_increment_step($form_state); @@ -470,7 +472,9 @@ function islandora_ingest_form_callback_previous(array $form, array &$form_state $step = islandora_ingest_form_get_step($form_state, $keys[$current_step]); islandora_ingest_form_decrement_step($form_state); if ($step['type'] === 'callback') { - call_user_func_array($step['undo_function']['function'], $step['undo_function']['args']); + $args = array(&$form_state); + $args = isset($step['undo_function']['args']) ? array_merge($args, $step['undo_function']['args']) : $args; + call_user_func_array($step['undo_function']['function'], $args); } else { $form = TRUE; @@ -583,7 +587,10 @@ function islandora_ingest_form_ingest_button(array &$form_state) { $validate_callback = $form_id . '_validate'; $validate = function_exists($validate_callback) ? array($validate_callback) : NULL; $submit_callback = $form_id . '_submit'; - $submit = function_exists($submit_callback) ? array($submit_callback, 'islandora_ingest_form_submit') : array('islandora_ingest_form_submit'); + $submit = array(); + if (function_exists($submit_callback)) { + $submit[] = $submit_callback; + } // Because of callback shananigans we have to check if there are a chain of // n callbacks that are weighted after the current step. @@ -607,12 +614,10 @@ function islandora_ingest_form_ingest_button(array &$form_state) { * * Attempts to ingest every object built by the previous steps. * - * @param array $form - * The Drupal form. * @param array $form_state * The Drupal form state. */ -function islandora_ingest_form_submit(array $form, array &$form_state) { +function islandora_ingest_form_ingest(array &$form_state) { foreach ($form_state['islandora']['objects'] as $object) { try { islandora_add_object($object); @@ -644,7 +649,9 @@ function islandora_ingest_form_callback_ingest(array $form, array &$form_state) // Execute our n chain of callbacks. while ($current_step < count($steps)) { $step = islandora_ingest_form_get_step($form_state, $keys[$current_step]); - call_user_func_array($step['do_function']['function'], $step['do_function']['args']); + $args = array(&$form_state); + $args = isset($step['do_function']['args']) ? array_merge($args, $step['do_function']['args']) : $args; + call_user_func_array($step['do_function']['function'], $args); $current_step++; } } @@ -790,7 +797,6 @@ function islandora_ingest_form_get_steps(array &$form_state) { '@module' => $step['module'], '@step' => $key, ), WATCHDOG_ERROR); - dd('errorsaursu'); unset($steps[$key]); } } diff --git a/islandora.api.php b/islandora.api.php index fbe49be6..f6fd02a7 100644 --- a/islandora.api.php +++ b/islandora.api.php @@ -405,7 +405,7 @@ function hook_islandora_undeletable_datastreams(array $models) { * end of the process while smaller(/"lighter") values are executed first. * Both types may optionally include: * - module: A module from which we want to load an include. - * "Form type" may optionally include: + * "Form" type may optionally include: * - file: A file to include (relative to the module's path, including the * file's extension). */ diff --git a/islandora.module b/islandora.module index ad9e569e..6f1d0144 100644 --- a/islandora.module +++ b/islandora.module @@ -1097,3 +1097,21 @@ function islandora_download_clip(AbstractObject $object) { } exit(); } + +/** + * Implements hook_islandora_ingest_steps(). + */ +function islandora_islandora_ingest_steps(&$form_state) { + return array( + 'islandora_ingest_form_submit' => array( + 'type' => 'callback', + 'weight' => 50, + 'do_function' => array( + 'function' => 'islandora_ingest_form_ingest', + ), + 'undo_function' => array( + 'function' => 'islandora_ingest_form_undo_ingest', + ), + ), + ); +} From 69ce869b818dcd9bfad37bed2879160755541913 Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Wed, 17 Apr 2013 11:01:08 -0300 Subject: [PATCH 082/172] removed unused variable --- includes/utilities.inc | 1 - 1 file changed, 1 deletion(-) diff --git a/includes/utilities.inc b/includes/utilities.inc index df924dce..90676923 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -764,7 +764,6 @@ function islandora_get_content_models($ignore_system_namespace = TRUE) { * Drupal form element allowing content model selection */ function islandora_content_model_select_table_form_element($drupal_variable) { - $connection = islandora_get_tuque_connection(); $defaults = array(); $rows = array(); $content_models = array(); From d11075a1e695f3b424c8331e6a5419b3f6ffb62f Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Thu, 18 Apr 2013 09:30:10 -0300 Subject: [PATCH 083/172] API documentation update, minor revisions to ingest form. --- includes/ingest.form.inc | 11 ++++++----- islandora.api.php | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/includes/ingest.form.inc b/includes/ingest.form.inc index 53c48639..8462deef 100644 --- a/includes/ingest.form.inc +++ b/includes/ingest.form.inc @@ -26,7 +26,8 @@ * be related. * - models: An array of content model PIDs, to which the new object might * subscribe - * + * - parent: The parent of the child to be ingested. This is needed for XACML + * to correctly apply the parent's POLICY to children. * @return array * The form definition of the current step. */ @@ -373,8 +374,8 @@ function islandora_ingest_form_on_last_step(array &$form_state) { $step_ids = array_keys(islandora_ingest_form_get_steps($form_state)); $next_step_num = array_search($next_id, $step_ids); $callback_chain = TRUE; - - while ($next_step_num < count($step_ids)) { + $num_steps = count($step_ids); + while ($next_step_num < $num_steps) { $next_step = islandora_ingest_form_get_step($form_state, $step_ids[$next_step_num]); // Still is a form somewhere down our chain. if ($next_step['type'] === 'form') { @@ -645,9 +646,9 @@ function islandora_ingest_form_callback_ingest(array $form, array &$form_state) $steps = islandora_ingest_form_get_steps($form_state); $keys = array_keys($steps); $current_step = array_search($next_id, $keys); - + $num_steps = count($steps); // Execute our n chain of callbacks. - while ($current_step < count($steps)) { + while ($current_step < $num_steps) { $step = islandora_ingest_form_get_step($form_state, $keys[$current_step]); $args = array(&$form_state); $args = isset($step['do_function']['args']) ? array_merge($args, $step['do_function']['args']) : $args; diff --git a/islandora.api.php b/islandora.api.php index f6fd02a7..17db59ad 100644 --- a/islandora.api.php +++ b/islandora.api.php @@ -304,7 +304,7 @@ function hook_islandora_datastream_modified(FedoraObject $object, FedoraDatastre } /** - * Notify modules that the given datastream was ingested. + * Notify modules that the given datastream was modified. * * @see hook_islandora_datastream_modified() */ From 2d32249ab8e190a210fedfafdfb45205dfe38cd2 Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Thu, 18 Apr 2013 10:28:06 -0300 Subject: [PATCH 084/172] Missing newline, crufty func. --- includes/ingest.form.inc | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/includes/ingest.form.inc b/includes/ingest.form.inc index 8462deef..31cff4e5 100644 --- a/includes/ingest.form.inc +++ b/includes/ingest.form.inc @@ -28,6 +28,7 @@ * subscribe * - parent: The parent of the child to be ingested. This is needed for XACML * to correctly apply the parent's POLICY to children. + * * @return array * The form definition of the current step. */ @@ -301,24 +302,6 @@ function islandora_ingest_form_execute_step(array $form, array &$form_state, $st return array(); } -/** - * Handles occurances where a callback is executed to grab the next form type. - * - * @param array $form_state - * The Drupal form state. - * @param array $step - * Describes the current step. - * - * @return array - * The stepified Drupal form definition for the given step. - */ -function islandora_ingest_callback_stepify(array &$form_state, $step) { - $next_step = islandora_ingest_form_get_step($form_state, $step); - $form = call_user_func_array($next_step['form_id'], $args); - islandora_ingest_form_increment_step($form_state); - return islandora_ingest_form_stepify($form, $form_state, $next_step); -} - /** * Append Prev/Next buttons submit/validation handlers etc. * From 852968fe4b43fe6b0458f203dbff8c725b4c8ffc Mon Sep 17 00:00:00 2001 From: jonathangreen Date: Thu, 18 Apr 2013 15:20:12 -0300 Subject: [PATCH 085/172] Some codesniffer modifications. --- .travis.yml | 2 +- includes/ingest.form.inc | 2 +- includes/utilities.inc | 9 ++++----- islandora.api.php | 24 ++++++++++++------------ tests/scripts/travis_setup.sh | 2 ++ 5 files changed, 20 insertions(+), 19 deletions(-) diff --git a/.travis.yml b/.travis.yml index a7bd2a84..7b537cfc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,6 +14,6 @@ before_install: script: - ant -buildfile sites/all/modules/islandora/build.xml lint - $ISLANDORA_DIR/tests/scripts/line_endings.sh sites/all/modules/islandora - - drush dcs sites/all/modules/islandora + - drush coder-review --reviews=production,security,style,i18n,potx,sniffer sites/all/modules/islandora - phpcpd --names *.module,*.inc,*.test sites/all/modules/islandora - drush test-run --uri=http://localhost:8081 Islandora diff --git a/includes/ingest.form.inc b/includes/ingest.form.inc index db031dc0..62b09381 100644 --- a/includes/ingest.form.inc +++ b/includes/ingest.form.inc @@ -507,7 +507,7 @@ function islandora_ingest_form_submit(array $form, array &$form_state) { catch (Exception $e) { // If post hooks throws it may already exist at this point but may be // invalid, so don't say failed. - watchdog('islandora', $e->getMessage(), NULL, WATCHDOG_ERROR); + watchdog('islandora', 'Exception Message: @exception.', array('@exception' => $e->getMessage()), WATCHDOG_ERROR); drupal_set_message(t('A problem occured while ingesting "@label" (ID: @pid), please notifiy the administrator.', array('@label' => $object->label, '@pid' => $object->id)), 'error'); } } diff --git a/includes/utilities.inc b/includes/utilities.inc index f7363bbe..4c83837a 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -484,11 +484,10 @@ function islandora_prepare_new_object($namespace = NULL, $label = NULL, $datastr // set datastream_file by url for the given scheme. Https (SSL) can // cause this to fail, and trigger an output log in watchdog. $datastream_file = url($ds['datastream_file'], array('absolute' => TRUE)); - watchdog('islandora', 'Attempting to ingest %file in islandora_prepare_new_object(), ' . - ' but it does not appear to be readable. We will pass the path through' . - ' url(), and pass along as such.', - array('%file' => $datastream_file), - WATCHDOG_WARNING); + watchdog('islandora', + 'Attempting to ingest %file in islandora_prepare_new_object(), but it does not appear to be readable. We will pass the path through url(), and pass along as such.', + array('%file' => $datastream_file), + WATCHDOG_WARNING); } } diff --git a/islandora.api.php b/islandora.api.php index d1d58f4f..a0ddde5c 100644 --- a/islandora.api.php +++ b/islandora.api.php @@ -35,7 +35,7 @@ function hook_islandora_view_object($object, $user, $page_number, $page_size) { * @return array * An array whose values are markup. */ -function hook_CMODEL_PID_islandora_view_object($object) { +function hook_cmodel_pid_islandora_view_object($object) { } @@ -60,7 +60,7 @@ function hook_islandora_view_object_alter(&$object, &$rendered) { * @param array $rendered * The array of rendered views. */ -function hook_CMODEL_PID_islandora_view_object_alter(&$object, &$rendered) { +function hook_cmodel_pid_islandora_view_object_alter(&$object, &$rendered) { } /** @@ -87,7 +87,7 @@ function hook_islandora_edit_object($object) { * @return array * An array whose values are markup. */ -function hook_CMODEL_PID_islandora_edit_object($object) { +function hook_cmodel_pid_islandora_edit_object($object) { } /** @@ -138,7 +138,7 @@ function hook_islandora_object_alter(AbstractFedoraObject $object, array &$conte * * @see hook_islandora_object_alter() */ -function hook_CMODEL_PID_islandora_object_alter(AbstractFedoraObject $object, array &$context) { +function hook_cmodel_pid_islandora_object_alter(AbstractFedoraObject $object, array &$context) { } /** @@ -187,7 +187,7 @@ function hook_islandora_datastream_alter(AbstractFedoraObject $object, AbstractF * * @see hook_islandora_datastream_alter() */ -function hook_CMODEL_PID_DSID_islandora_datastream_alter(AbstractFedoraObject $object, AbstractFedoraDatastream $datastream, array &$context) { +function hook_cmodel_pid_DSID_islandora_datastream_alter(AbstractFedoraObject $object, AbstractFedoraDatastream $datastream, array &$context) { } /** @@ -211,7 +211,7 @@ function hook_islandora_object_ingested(FedoraObject $object) { * * @see hook_islandora_object_ingested() */ -function hook_CMODEL_PID_islandora_object_ingested(FedoraObject $object) { +function hook_cmodel_pid_islandora_object_ingested(FedoraObject $object) { } /** @@ -236,7 +236,7 @@ function hook_islandora_object_modified(FedoraObject $object) { * * @see hook_islandora_object_modified() */ -function hook_CMODEL_PID_islandora_object_modified(FedoraObject $object) { +function hook_cmodel_pid_islandora_object_modified(FedoraObject $object) { } /** @@ -256,7 +256,7 @@ function hook_islandora_object_purged($pid) { * * @see hook_islandora_object_purged() */ -function hook_CMODEL_PID_islandora_object_purged($pid) { +function hook_cmodel_pid_islandora_object_purged($pid) { } /** @@ -281,7 +281,7 @@ function hook_islandora_datastream_ingested(FedoraObject $object, FedoraDatastre * * @see hook_islandora_object_ingested() */ -function hook_CMODEL_PID_DSID_islandora_datastream_ingested(FedoraObject $object, FedoraDatastream $datastream) { +function hook_cmodel_pid_DSID_islandora_datastream_ingested(FedoraObject $object, FedoraDatastream $datastream) { } /** @@ -308,7 +308,7 @@ function hook_islandora_datastream_modified(FedoraObject $object, FedoraDatastre * * @see hook_islandora_datastream_modified() */ -function hook_CMODEL_PID_islandora_datastream_modified(FedoraObject $object, FedoraDatastream $datastream) { +function hook_cmodel_pid_islandora_datastream_modified(FedoraObject $object, FedoraDatastream $datastream) { } /** @@ -330,7 +330,7 @@ function hook_islandora_datastream_purged(FedoraObject $object, $dsid) { * * @see hook_islandora_datastream_purged() */ -function hook_CMODEL_PID_islandora_datastream_purged(FedoraObject $object, $dsid) { +function hook_cmodel_pid_islandora_datastream_purged(FedoraObject $object, $dsid) { } /** @@ -418,5 +418,5 @@ function hook_islandora_ingest_steps(array $form_state) { * * @see hook_islandora_ingest_steps() */ -function hook_CMODEL_PID_islandora_ingest_steps(array $form_state) { +function hook_cmodel_pid_islandora_ingest_steps(array $form_state) { } diff --git a/tests/scripts/travis_setup.sh b/tests/scripts/travis_setup.sh index c0a5f0f2..c3515198 100755 --- a/tests/scripts/travis_setup.sh +++ b/tests/scripts/travis_setup.sh @@ -27,8 +27,10 @@ mv sites/all/modules/islandora/tests/travis.test_config.ini sites/all/modules/is mkdir sites/all/libraries ln -s $HOME/tuque sites/all/libraries/tuque drush dl --yes coder +drush dl --yes potx drush en --yes coder_review drush en --yes simpletest +drush en --yes potx drush en --user=1 --yes islandora drush cc all sleep 4 From 49c489a83cfb18d8602556170f33f0eebb35ed7b Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Thu, 18 Apr 2013 20:10:46 +0200 Subject: [PATCH 086/172] Code Review - Refactor and fixes. --- includes/ingest.form.inc | 336 ++++++++++++++++++--------------------- islandora.module | 18 --- 2 files changed, 155 insertions(+), 199 deletions(-) diff --git a/includes/ingest.form.inc b/includes/ingest.form.inc index 31cff4e5..a94aaa30 100644 --- a/includes/ingest.form.inc +++ b/includes/ingest.form.inc @@ -135,6 +135,50 @@ function islandora_ingest_form_get_step(array &$form_state, $step_id = NULL) { return NULL; } +/** + * Gets the next step. + * + * If the current step is not defined, its assumed to be the first step. + * + * @param array $form_state + * The Drupal form state. + * @param string $step + * The step relative to the result, if not provided the current step is used. + * + * @return string + * The next step if found, NULL otherwise. + */ +function islandora_ingest_form_get_next_step(array &$form_state, array $step = NULL) { + $step = isset($step) ? $step : islandora_ingest_form_get_step($form_state); + $next_step_id = islandora_ingest_form_get_next_step_id($form_state, $step['id']); + if ($next_step_id) { + return islandora_ingest_form_get_step($form_state, $next_step_id); + } + return NULL; +} + +/** + * Gets the next step. + * + * If the current step is not defined, its assumed to be the first step. + * + * @param array $form_state + * The Drupal form state. + * @param string $step + * The step relative to the result, if not provided the current step is used. + * + * @return string + * The next step if found, NULL otherwise. + */ +function islandora_ingest_form_get_previous_step(array &$form_state, array $step = NULL) { + $step = isset($step) ? $step : islandora_ingest_form_get_step($form_state); + $next_step_id = islandora_ingest_form_get_previous_step_id($form_state, $step['id']); + if ($next_step_id) { + return islandora_ingest_form_get_step($form_state, $next_step_id); + } + return NULL; +} + /** * Gets the ID of the current step. * @@ -162,12 +206,15 @@ function islandora_ingest_form_get_current_step_id(array &$form_state) { * * @param array $form_state * The Drupal form state. + * @param string $step_id + * The ID of the step relative to the result, if not provided the current + * step_id is used. * * @return string * The next step ID if found, NULL otherwise. */ -function islandora_ingest_form_get_next_step_id(array &$form_state) { - $step_id = islandora_ingest_form_get_current_step_id($form_state); +function islandora_ingest_form_get_next_step_id(array &$form_state, $step_id = NULL) { + $step_id = isset($step_id) ? $step_id : islandora_ingest_form_get_current_step_id($form_state); $step_ids = array_keys(islandora_ingest_form_get_steps($form_state)); $index = array_search($step_id, $step_ids); $count = count($step_ids); @@ -184,14 +231,15 @@ function islandora_ingest_form_get_next_step_id(array &$form_state) { * * @param array $form_state * The Drupal form state. + * @param string $step_id + * The ID of the step relative to the result, if not provided the current + * step_id is used. * * @return string * The previous step ID if found, NULL otherwise. */ -function islandora_ingest_form_get_previous_step_id(array &$form_state) { - $step_id = islandora_ingest_form_get_current_step_id($form_state); - $step = islandora_ingest_form_get_step($form_state, $step_id); - +function islandora_ingest_form_get_previous_step_id(array &$form_state, $step_id = NULL) { + $step_id = isset($step_id) ? $step_id : islandora_ingest_form_get_current_step_id($form_state); $step_ids = array_keys(islandora_ingest_form_get_steps($form_state)); $index = array_search($step_id, $step_ids); if ($index !== FALSE && --$index >= 0) { @@ -237,13 +285,15 @@ function islandora_ingest_form_decrement_step(array &$form_state) { * Build a list of steps given only configuration. * * XXX: This is used to give an indication of whether there are any steps for a - * given list of content models. + * given configuration. * * @param array $configuration * The list of key/value pairs of configuration. */ function islandora_ingest_get_approximate_steps(array $configuration) { try { + // @todo, we need to expand the configuration before we can validate it? + // I think this need some thinking. islandora_ingest_form_validate_configuration($configuration); } catch (InvalidArgumentException $e) { @@ -279,29 +329,72 @@ function islandora_ingest_form_execute_step(array $form, array &$form_state, $st islandora_ingest_form_load_include($form_state); $step = isset($step_id) ? islandora_ingest_form_get_step($form_state) : islandora_ingest_form_get_step($form_state, $step_id); switch ($step['type']) { + case 'callback': + // Execute all the consecutive callbacks, and move then attempt to process + // the next step. + islandora_ingest_form_execute_consecutive_callback_steps($form, $form_state, $step); + return islandora_ingest_form_execute_step($form, $form_state); + case 'form': - $args = array($form, &$form_state); - $args = isset($step['args']) ? array_merge($args, $step['args']) : $args; - $form = call_user_func_array($step['form_id'], $args); - return islandora_ingest_form_stepify($form, $form_state, $step); + return islandora_ingest_form_execute_form_step($form, $form_state, $step); case 'batch': // @todo Implement if possible. break; - - case 'callback': - $args = array(&$form_state); - $args = isset($step['do_function']['args']) ? array_merge($args, $step['do_function']['args']) : $args; - call_user_func_array($step['do_function']['function'], $args); - $next_step = islandora_ingest_form_get_next_step_id($form_state); - if ($next_step) { - islandora_ingest_form_increment_step($form_state); - return islandora_ingest_form_execute_step($form, $form_state, $next_step); - } } return array(); } +/** + * Assumes the given $step is a 'form' step. + */ +function islandora_ingest_form_execute_form_step(array $form, array &$form_state, array $step) { + $args = array($form, &$form_state); + $args = isset($step['args']) ? array_merge($args, $step['args']) : $args; + $form = call_user_func_array($step['form_id'], $args); + return islandora_ingest_form_stepify($form, $form_state, $step); +} + +/** + * Assumes the given $step is a 'callback' step. + */ +function islandora_ingest_form_execute_consecutive_callback_steps(array $form, array &$form_state, array $step) { + do { + islandora_ingest_form_execute_callback_step($form, $form_state, $step); + islandora_ingest_form_increment_step($form_state); + $step = islandora_ingest_form_get_step($form_state); + } while (isset($step) && $step['type'] == 'callback'); +} + +/** + * Assumes the given $step is a 'callback' step. + */ +function islandora_ingest_form_execute_callback_step(array $form, array &$form_state, array $step) { + $args = array(&$form_state); + $args = isset($step['do_function']['args']) ? array_merge($args, $step['do_function']['args']) : $args; + call_user_func_array($step['do_function']['function'], $args); +} + +/** + * Assumes the given $step is a 'callback' step. + */ +function islandora_ingest_form_undo_consecutive_callback_steps(array $form, array &$form_state, array $step) { + do { + islandora_ingest_form_undo_callback_step($form, $form_state, $step); + islandora_ingest_form_decrement_step($form_state); + $step = islandora_ingest_form_get_step($form_state); + } while (isset($step) && $step['type'] == 'callback'); +} + +/** + * Assumes the given $step is a 'callback' step. + */ +function islandora_ingest_form_undo_callback_step(array $form, array &$form_state, array $step) { + $args = array(&$form_state); + $args = isset($step['undo_function']['args']) ? array_merge($args, $step['undo_function']['args']) : $args; + call_user_func_array($step['undo_function']['function'], $args); +} + /** * Append Prev/Next buttons submit/validation handlers etc. * @@ -314,18 +407,17 @@ function islandora_ingest_form_execute_step(array $form, array &$form_state, $st * The stepified Drupal form definition for the given step. */ function islandora_ingest_form_stepify(array $form, array &$form_state, $step) { - $first_step = islandora_ingest_form_on_first_step($form_state); - $last_step = islandora_ingest_form_on_last_step($form_state); - $form['prev'] = $first_step ? NULL : islandora_ingest_form_previous_button($form_state); - $form['next'] = $last_step ? islandora_ingest_form_ingest_button($form_state) : islandora_ingest_form_next_button($form_state); - + $first_form_step = islandora_ingest_form_on_first_form_step($form_state); + $last_form_step = islandora_ingest_form_on_last_form_step($form_state); + $form['prev'] = $first_form_step ? NULL : islandora_ingest_form_previous_button($form_state); + $form['next'] = $last_form_step ? islandora_ingest_form_ingest_button($form_state) : islandora_ingest_form_next_button($form_state); // Allow for a hook_form_FORM_ID_alter(). drupal_alter(array('form_' . $step['form_id'], 'form'), $form, $form_state, $step['form_id']); return $form; } /** - * Checks if we are on the first step. + * Checks if we are on the first form step. * * @param array $form_state * The Drupal form state. @@ -333,14 +425,16 @@ function islandora_ingest_form_stepify(array $form, array &$form_state, $step) { * @return bool * TRUE if we are currently on the first step, FALSE otherwise. */ -function islandora_ingest_form_on_first_step(array &$form_state) { - $step_id = islandora_ingest_form_get_current_step_id($form_state); - $step_ids = array_keys(islandora_ingest_form_get_steps($form_state)); - return array_search($step_id, $step_ids) == 0; +function islandora_ingest_form_on_first_form_step(array &$form_state) { + $step = NULL; + do { + $step = islandora_ingest_form_get_previous_step($form_state, $step); + } while (isset($step) && $step['type'] != 'form'); + return !$step; } /** - * Checks if we are on the last step. + * Checks if we are on the last form step. * * @param array $form_state * The Drupal form state. @@ -348,29 +442,12 @@ function islandora_ingest_form_on_first_step(array &$form_state) { * @return bool * TRUE if we are currently on the last step, FALSE otherwise. */ -function islandora_ingest_form_on_last_step(array &$form_state) { - $next_id = islandora_ingest_form_get_next_step_id($form_state); - if (!$next_id) { - return TRUE; - } - else { - $step_ids = array_keys(islandora_ingest_form_get_steps($form_state)); - $next_step_num = array_search($next_id, $step_ids); - $callback_chain = TRUE; - $num_steps = count($step_ids); - while ($next_step_num < $num_steps) { - $next_step = islandora_ingest_form_get_step($form_state, $step_ids[$next_step_num]); - // Still is a form somewhere down our chain. - if ($next_step['type'] === 'form') { - $callback_chain = FALSE; - break; - } - else { - $next_step_num++; - } - } - return $callback_chain; - } +function islandora_ingest_form_on_last_form_step(array &$form_state) { + $step = NULL; + do { + $step = islandora_ingest_form_get_next_step($form_state, $step); + } while (isset($step) && $step['type'] != 'form'); + return !$step; } /** @@ -387,37 +464,10 @@ function islandora_ingest_form_on_last_step(array &$form_state) { function islandora_ingest_form_previous_button(array &$form_state) { // Before we move back to the previous step we should tell the previous step // to undo whatever its submit handler did. - $prev_step_id = islandora_ingest_form_get_previous_step_id($form_state); - $prev_step = islandora_ingest_form_get_step($form_state, $prev_step_id); - - if ($prev_step['type'] === 'form') { - $form_id = $prev_step['form_id']; - $submit_callback = $form_id . '_undo_submit'; - $submit = function_exists($submit_callback) ? array($submit_callback, 'islandora_ingest_form_previous_submit') : array('islandora_ingest_form_undo_submit'); - } - elseif ($prev_step['type'] === 'callback') { - // Need to check if we have one or more callbacks at the start of our steps. - $steps = islandora_ingest_form_get_steps($form_state); - $keys = array_keys($steps); - $form = FALSE; - $current_step = array_search($prev_step_id, $keys); - while ($current_step >= 0 && !$form) { - $step = islandora_ingest_form_get_step($form_state, $keys[$current_step]); - if ($step['type'] === 'form') { - $form = TRUE; - break; - } - $current_step--; - } - // Only render a previous button if there a form somewhere behind us in our - // history chain. - if ($form) { - $submit = array('islandora_ingest_form_callback_previous'); - } - else { - return; - } - } + $prev_step = islandora_ingest_form_get_previous_step($form_state); + $form_id = $prev_step['form_id']; + $submit_callback = $form_id . '_undo_submit'; + $submit = function_exists($submit_callback) ? array($submit_callback, 'islandora_ingest_form_previous_submit') : array('islandora_ingest_form_previous_submit'); return array( '#type' => 'submit', '#value' => t('Previous'), @@ -434,40 +484,6 @@ function islandora_ingest_form_previous_button(array &$form_state) { ); } -/** - * Handles the execution of "undoing" callbacks until a form type is reached. - * - * @param array $form - * The Drupal form. - * @param array $form_state - * The Drupal form state. - */ -function islandora_ingest_form_callback_previous(array $form, array &$form_state) { - // Arbitrarily move at least 1 back. - islandora_ingest_form_decrement_step($form_state); - $step_id = islandora_ingest_form_get_current_step_id($form_state); - $steps = islandora_ingest_form_get_steps($form_state); - $keys = array_keys($steps); - $current_step = array_search($step_id, $keys); - - $form = FALSE; - - while ($current_step >= 0 && !$form) { - $step = islandora_ingest_form_get_step($form_state, $keys[$current_step]); - islandora_ingest_form_decrement_step($form_state); - if ($step['type'] === 'callback') { - $args = array(&$form_state); - $args = isset($step['undo_function']['args']) ? array_merge($args, $step['undo_function']['args']) : $args; - call_user_func_array($step['undo_function']['function'], $args); - } - else { - $form = TRUE; - } - $current_step--; - } - $form_state['rebuild'] = TRUE; -} - /** * The submit handler for the ingest form previous button. * @@ -482,6 +498,11 @@ function islandora_ingest_form_callback_previous(array $form, array &$form_state */ function islandora_ingest_form_previous_submit(array $form, array &$form_state) { islandora_ingest_form_decrement_step($form_state); + $step = islandora_ingest_form_get_step($form_state); + // Undo all callbacks that occured after the previous step. + if ($step['type'] == 'callback') { + islandora_ingest_form_undo_consecutive_callback_steps($form, $form_state, $step); + } $form_state['rebuild'] = TRUE; } @@ -571,19 +592,7 @@ function islandora_ingest_form_ingest_button(array &$form_state) { $validate_callback = $form_id . '_validate'; $validate = function_exists($validate_callback) ? array($validate_callback) : NULL; $submit_callback = $form_id . '_submit'; - $submit = array(); - if (function_exists($submit_callback)) { - $submit[] = $submit_callback; - } - - // Because of callback shananigans we have to check if there are a chain of - // n callbacks that are weighted after the current step. - $next_id = islandora_ingest_form_get_next_step_id($form_state); - - if ($next_id) { - $submit[] = 'islandora_ingest_form_callback_ingest'; - } - + $submit = function_exists($submit_callback) ? array($submit_callback, 'islandora_ingest_form_submit') : array('islandora_ingest_form_submit'); return array( '#type' => 'submit', '#name' => 'ingest', @@ -601,7 +610,14 @@ function islandora_ingest_form_ingest_button(array &$form_state) { * @param array $form_state * The Drupal form state. */ -function islandora_ingest_form_ingest(array &$form_state) { +function islandora_ingest_form_submit(array $form, array &$form_state) { + // Execute any remainng callbacks. + islandora_ingest_form_increment_step($form_state); + $step = islandora_ingest_form_get_step($form_state); + if (isset($step) && $step['type'] == 'callback') { + islandora_ingest_form_execute_consecutive_callback_steps($form, $form_state, $step); + } + // Ingest the objects. foreach ($form_state['islandora']['objects'] as $object) { try { islandora_add_object($object); @@ -616,30 +632,6 @@ function islandora_ingest_form_ingest(array &$form_state) { } } -/** - * Execute any callbacks that are weighted at end of the ingest steps on ingest. - * - * @param array $form - * The Drupal form. - * @param array $form_state - * The Drupal form state. - */ -function islandora_ingest_form_callback_ingest(array $form, array &$form_state) { - $next_id = islandora_ingest_form_get_next_step_id($form_state); - $steps = islandora_ingest_form_get_steps($form_state); - $keys = array_keys($steps); - $current_step = array_search($next_id, $keys); - $num_steps = count($steps); - // Execute our n chain of callbacks. - while ($current_step < $num_steps) { - $step = islandora_ingest_form_get_step($form_state, $keys[$current_step]); - $args = array(&$form_state); - $args = isset($step['do_function']['args']) ? array_merge($args, $step['do_function']['args']) : $args; - call_user_func_array($step['do_function']['function'], $args); - $current_step++; - } -} - /** * Gets a reference to the stored NewFedoraObject's. * @@ -752,6 +744,8 @@ function islandora_ingest_form_get_steps(array &$form_state) { $shared_storage = &islandora_ingest_form_get_shared_storage($form_state); foreach (islandora_build_hook_list(ISLANDORA_INGEST_STEP_HOOK, $shared_storage['models']) as $hook) { // Required for pass by reference. + // @todo Change this around so that it isn't passed by reference, there + // Is an alter below that can handle that requirement. foreach (module_implements($hook) as $module) { $function = $module . '_' . $hook; $module_steps = (array) $function($form_state); @@ -762,30 +756,10 @@ function islandora_ingest_form_get_steps(array &$form_state) { foreach (islandora_build_hook_list(ISLANDORA_INGEST_STEP_HOOK, $shared_storage['models']) as $hook) { drupal_alter($hook, $steps, $form_state); } - // Check to see if the callback functions are implemented (existed). Remove - // any implementations from the steps that are incorrectly defined. - foreach ($steps as $key => $step) { - $watchdog = FALSE; - if ($step['type'] === 'callback') { - if (!isset($step['do_function']) || !isset($step['undo_function'])) { - $watchdog = TRUE; - } - elseif (!isset($step['do_function']['function']) || !isset($step['undo_function']['function'])) { - $watchdog = TRUE; - } - - if ($watchdog) { - watchdog('islandora', 'The @module module is incorrectly implementing the - callback functionality of islandora_ingest_steps. The step @step has - not been included in the list of steps.', array( - '@module' => $step['module'], - '@step' => $key, - ), WATCHDOG_ERROR); - unset($steps[$key]); - } - } + // Add any defaults. + foreach ($steps as $key => &$step) { + $step['id'] = $key; } uasort($steps, 'drupal_sort_weight'); - return $steps; } diff --git a/islandora.module b/islandora.module index 6f1d0144..ad9e569e 100644 --- a/islandora.module +++ b/islandora.module @@ -1097,21 +1097,3 @@ function islandora_download_clip(AbstractObject $object) { } exit(); } - -/** - * Implements hook_islandora_ingest_steps(). - */ -function islandora_islandora_ingest_steps(&$form_state) { - return array( - 'islandora_ingest_form_submit' => array( - 'type' => 'callback', - 'weight' => 50, - 'do_function' => array( - 'function' => 'islandora_ingest_form_ingest', - ), - 'undo_function' => array( - 'function' => 'islandora_ingest_form_undo_ingest', - ), - ), - ); -} From 44b8b384c9e493960e7ea4aa56dc02fce6b34040 Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Thu, 18 Apr 2013 17:02:21 -0300 Subject: [PATCH 087/172] Notice and comment fix. --- includes/ingest.form.inc | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/includes/ingest.form.inc b/includes/ingest.form.inc index a94aaa30..f39d38ff 100644 --- a/includes/ingest.form.inc +++ b/includes/ingest.form.inc @@ -158,7 +158,7 @@ function islandora_ingest_form_get_next_step(array &$form_state, array $step = N } /** - * Gets the next step. + * Gets the previous step. * * If the current step is not defined, its assumed to be the first step. * @@ -465,9 +465,14 @@ function islandora_ingest_form_previous_button(array &$form_state) { // Before we move back to the previous step we should tell the previous step // to undo whatever its submit handler did. $prev_step = islandora_ingest_form_get_previous_step($form_state); - $form_id = $prev_step['form_id']; - $submit_callback = $form_id . '_undo_submit'; - $submit = function_exists($submit_callback) ? array($submit_callback, 'islandora_ingest_form_previous_submit') : array('islandora_ingest_form_previous_submit'); + if ($prev_step['type'] == 'form') { + $form_id = $prev_step['form_id']; + $submit_callback = $form_id . '_undo_submit'; + $submit = function_exists($submit_callback) ? array($submit_callback, 'islandora_ingest_form_previous_submit') : array('islandora_ingest_form_previous_submit'); + } + else { + $submit = array('islandora_ingest_form_previous_submit'); + } return array( '#type' => 'submit', '#value' => t('Previous'), @@ -611,7 +616,7 @@ function islandora_ingest_form_ingest_button(array &$form_state) { * The Drupal form state. */ function islandora_ingest_form_submit(array $form, array &$form_state) { - // Execute any remainng callbacks. + // Execute any remaining callbacks. islandora_ingest_form_increment_step($form_state); $step = islandora_ingest_form_get_step($form_state); if (isset($step) && $step['type'] == 'callback') { From a3c38b8d4a128d28cadd8808c7e9991e6e89d56f Mon Sep 17 00:00:00 2001 From: jonathangreen Date: Thu, 18 Apr 2013 17:19:28 -0300 Subject: [PATCH 088/172] Code review changes --- .travis.yml | 2 +- islandora.api.php | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7b537cfc..adedf7b1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,6 +14,6 @@ before_install: script: - ant -buildfile sites/all/modules/islandora/build.xml lint - $ISLANDORA_DIR/tests/scripts/line_endings.sh sites/all/modules/islandora - - drush coder-review --reviews=production,security,style,i18n,potx,sniffer sites/all/modules/islandora + - drush coder-review --reviews=production,security,style,i18n,potx,sniffer islandora - phpcpd --names *.module,*.inc,*.test sites/all/modules/islandora - drush test-run --uri=http://localhost:8081 Islandora diff --git a/islandora.api.php b/islandora.api.php index a0ddde5c..d1d58f4f 100644 --- a/islandora.api.php +++ b/islandora.api.php @@ -35,7 +35,7 @@ function hook_islandora_view_object($object, $user, $page_number, $page_size) { * @return array * An array whose values are markup. */ -function hook_cmodel_pid_islandora_view_object($object) { +function hook_CMODEL_PID_islandora_view_object($object) { } @@ -60,7 +60,7 @@ function hook_islandora_view_object_alter(&$object, &$rendered) { * @param array $rendered * The array of rendered views. */ -function hook_cmodel_pid_islandora_view_object_alter(&$object, &$rendered) { +function hook_CMODEL_PID_islandora_view_object_alter(&$object, &$rendered) { } /** @@ -87,7 +87,7 @@ function hook_islandora_edit_object($object) { * @return array * An array whose values are markup. */ -function hook_cmodel_pid_islandora_edit_object($object) { +function hook_CMODEL_PID_islandora_edit_object($object) { } /** @@ -138,7 +138,7 @@ function hook_islandora_object_alter(AbstractFedoraObject $object, array &$conte * * @see hook_islandora_object_alter() */ -function hook_cmodel_pid_islandora_object_alter(AbstractFedoraObject $object, array &$context) { +function hook_CMODEL_PID_islandora_object_alter(AbstractFedoraObject $object, array &$context) { } /** @@ -187,7 +187,7 @@ function hook_islandora_datastream_alter(AbstractFedoraObject $object, AbstractF * * @see hook_islandora_datastream_alter() */ -function hook_cmodel_pid_DSID_islandora_datastream_alter(AbstractFedoraObject $object, AbstractFedoraDatastream $datastream, array &$context) { +function hook_CMODEL_PID_DSID_islandora_datastream_alter(AbstractFedoraObject $object, AbstractFedoraDatastream $datastream, array &$context) { } /** @@ -211,7 +211,7 @@ function hook_islandora_object_ingested(FedoraObject $object) { * * @see hook_islandora_object_ingested() */ -function hook_cmodel_pid_islandora_object_ingested(FedoraObject $object) { +function hook_CMODEL_PID_islandora_object_ingested(FedoraObject $object) { } /** @@ -236,7 +236,7 @@ function hook_islandora_object_modified(FedoraObject $object) { * * @see hook_islandora_object_modified() */ -function hook_cmodel_pid_islandora_object_modified(FedoraObject $object) { +function hook_CMODEL_PID_islandora_object_modified(FedoraObject $object) { } /** @@ -256,7 +256,7 @@ function hook_islandora_object_purged($pid) { * * @see hook_islandora_object_purged() */ -function hook_cmodel_pid_islandora_object_purged($pid) { +function hook_CMODEL_PID_islandora_object_purged($pid) { } /** @@ -281,7 +281,7 @@ function hook_islandora_datastream_ingested(FedoraObject $object, FedoraDatastre * * @see hook_islandora_object_ingested() */ -function hook_cmodel_pid_DSID_islandora_datastream_ingested(FedoraObject $object, FedoraDatastream $datastream) { +function hook_CMODEL_PID_DSID_islandora_datastream_ingested(FedoraObject $object, FedoraDatastream $datastream) { } /** @@ -308,7 +308,7 @@ function hook_islandora_datastream_modified(FedoraObject $object, FedoraDatastre * * @see hook_islandora_datastream_modified() */ -function hook_cmodel_pid_islandora_datastream_modified(FedoraObject $object, FedoraDatastream $datastream) { +function hook_CMODEL_PID_islandora_datastream_modified(FedoraObject $object, FedoraDatastream $datastream) { } /** @@ -330,7 +330,7 @@ function hook_islandora_datastream_purged(FedoraObject $object, $dsid) { * * @see hook_islandora_datastream_purged() */ -function hook_cmodel_pid_islandora_datastream_purged(FedoraObject $object, $dsid) { +function hook_CMODEL_PID_islandora_datastream_purged(FedoraObject $object, $dsid) { } /** @@ -418,5 +418,5 @@ function hook_islandora_ingest_steps(array $form_state) { * * @see hook_islandora_ingest_steps() */ -function hook_cmodel_pid_islandora_ingest_steps(array $form_state) { +function hook_CMODEL_PID_islandora_ingest_steps(array $form_state) { } From 2d0bba2611839a6c1513d12b6ed713edc0c9927d Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Fri, 19 Apr 2013 01:13:28 +0200 Subject: [PATCH 089/172] Prevent inifite loop when a callbacks is the last step to be executed. Fix's an error in my logic. Now instead of having a null step ID mean that it is the first step. The step ID gets initialized when the form is first build and NULL is changed to mean that all steps have been executed. Also added some comments. --- includes/ingest.form.inc | 127 +++++++++++++++++++++++++++++---------- 1 file changed, 96 insertions(+), 31 deletions(-) diff --git a/includes/ingest.form.inc b/includes/ingest.form.inc index 3619808a..435bff7c 100644 --- a/includes/ingest.form.inc +++ b/includes/ingest.form.inc @@ -84,9 +84,42 @@ function islandora_ingest_form_init_form_state_storage(array &$form_state, array 'shared_storage' => $configuration, 'step_storage' => array(), ); + // Must be called after $form_state['islandora'] is initialized, otherwise, the values + // in 'islandora' would not be availible to the step hooks. + $form_state['islandora']['step_id'] = islandora_ingest_form_get_first_step_id($form_state); } } +/** + * Get the first step ID. + * + * @param array $form_state + * The Drupal form state. + * + * @return string + * The 'id' of the very first step. + */ +function islandora_ingest_form_get_first_step_id(array &$form_state) { + $steps = islandora_ingest_form_get_steps($form_state); + $keys = array_keys($steps); + return array_shift($keys); +} + +/** + * Get the last step ID. + * + * @param array $form_state + * The Drupal form state. + * + * @return string + * The 'id' of the very last step. + */ +function islandora_ingest_form_get_last_step_id(array &$form_state) { + $steps = islandora_ingest_form_get_steps($form_state); + $keys = array_keys($steps); + return array_pop($keys); +} + /** * Prepares a new object based on the given configuration. * @@ -115,13 +148,12 @@ function islandora_ingest_form_prepare_new_object(array $configuration) { /** * Gets the given/current step. * - * The current step is returned if no step ID is given. If the current step is - * not defined it's assume to be the first step. + * If the current step is not defined it's assumed that all steps have executed. * * @param array $form_state * The Drupal form state. * @param string $step_id - * The ID of the step. + * The ID of the step. The current step is returned if no step ID is given. * * @return array * The given/current step if found, NULL otherwise. @@ -138,7 +170,7 @@ function islandora_ingest_form_get_step(array &$form_state, $step_id = NULL) { /** * Gets the next step. * - * If the current step is not defined, its assumed to be the first step. + * If the current step is not defined it's assumed that all steps have executed. * * @param array $form_state * The Drupal form state. @@ -151,16 +183,13 @@ function islandora_ingest_form_get_step(array &$form_state, $step_id = NULL) { function islandora_ingest_form_get_next_step(array &$form_state, array $step = NULL) { $step = isset($step) ? $step : islandora_ingest_form_get_step($form_state); $next_step_id = islandora_ingest_form_get_next_step_id($form_state, $step['id']); - if ($next_step_id) { - return islandora_ingest_form_get_step($form_state, $next_step_id); - } - return NULL; + return isset($next_step_id) ? islandora_ingest_form_get_step($form_state, $next_step_id) : NULL; } /** * Gets the previous step. * - * If the current step is not defined, its assumed to be the first step. + * If the current step is not defined it's assumed that all steps have executed. * * @param array $form_state * The Drupal form state. @@ -172,17 +201,14 @@ function islandora_ingest_form_get_next_step(array &$form_state, array $step = N */ function islandora_ingest_form_get_previous_step(array &$form_state, array $step = NULL) { $step = isset($step) ? $step : islandora_ingest_form_get_step($form_state); - $next_step_id = islandora_ingest_form_get_previous_step_id($form_state, $step['id']); - if ($next_step_id) { - return islandora_ingest_form_get_step($form_state, $next_step_id); - } - return NULL; + $previous_step_id = islandora_ingest_form_get_previous_step_id($form_state, $step['id']); + return isset($previous_step_id) ? islandora_ingest_form_get_step($form_state, $previous_step_id) : NULL; } /** * Gets the ID of the current step. * - * If a current step is not defined, its assumed to be the first step. + * If the current step is not defined it's assumed that all steps have executed. * * @param array $form_state * The Drupal form state. @@ -191,18 +217,13 @@ function islandora_ingest_form_get_previous_step(array &$form_state, array $step * The step ID. */ function islandora_ingest_form_get_current_step_id(array &$form_state) { - if (empty($form_state['islandora']['step_id'])) { - $steps = islandora_ingest_form_get_steps($form_state); - $keys = array_keys($steps); - return array_shift($keys); - } return $form_state['islandora']['step_id']; } /** * Gets the ID of the next step. * - * If a current step is not defined, its assumed to be the first step. + * If the current step is not defined it's assumed that all steps have executed. * * @param array $form_state * The Drupal form state. @@ -227,7 +248,8 @@ function islandora_ingest_form_get_next_step_id(array &$form_state, $step_id = N /** * Gets the ID of the previous step. * - * If a current step is not defined, its assumed to be the first step. + * If the current step is not defined it's assumed that all steps have executed. + * In such cases the last step will be returned. * * @param array $form_state * The Drupal form state. @@ -240,6 +262,11 @@ function islandora_ingest_form_get_next_step_id(array &$form_state, $step_id = N */ function islandora_ingest_form_get_previous_step_id(array &$form_state, $step_id = NULL) { $step_id = isset($step_id) ? $step_id : islandora_ingest_form_get_current_step_id($form_state); + // If the current step is not defined it's assumed that all steps have executed. + // so return the very last step. + if ($step_id == NULL) { + return islandora_ingest_form_get_last_step_id($form_state); + } $step_ids = array_keys(islandora_ingest_form_get_steps($form_state)); $index = array_search($step_id, $step_ids); if ($index !== FALSE && --$index >= 0) { @@ -259,11 +286,9 @@ function islandora_ingest_form_increment_step(array &$form_state) { // of the current step could have added/removed a step. drupal_static_reset('islandora_ingest_form_get_steps'); $next_step_id = islandora_ingest_form_get_next_step_id($form_state); - if (isset($next_step_id)) { - islandora_ingest_form_stash_info($form_state); - $form_state['islandora']['step_id'] = $next_step_id; - islandora_ingest_form_grab_info($form_state); - } + islandora_ingest_form_stash_info($form_state); + $form_state['islandora']['step_id'] = $next_step_id; + islandora_ingest_form_grab_info($form_state); } /** @@ -274,6 +299,7 @@ function islandora_ingest_form_increment_step(array &$form_state) { */ function islandora_ingest_form_decrement_step(array &$form_state) { $previous_step_id = islandora_ingest_form_get_previous_step_id($form_state); + // Don't decrement passed the first step. if (isset($previous_step_id)) { islandora_ingest_form_stash_info($form_state); $form_state['islandora']['step_id'] = $previous_step_id; @@ -346,7 +372,17 @@ function islandora_ingest_form_execute_step(array $form, array &$form_state, $st } /** - * Assumes the given $step is a 'form' step. + * Execute the given 'form' step. + * + * Assumes the given step is a 'form' step. + * + * @param array $form + * The Drupal form. + * @param array $form_state + * The Drupal form state. + * + * @return array + * The form definition of the given step. */ function islandora_ingest_form_execute_form_step(array $form, array &$form_state, array $step) { $args = array($form, &$form_state); @@ -356,7 +392,14 @@ function islandora_ingest_form_execute_form_step(array $form, array &$form_state } /** - * Assumes the given $step is a 'callback' step. + * Execute the given 'callback' step and any consecutive 'callback' steps. + * + * Assumes the given step is a 'callback' step. + * + * @param array $form + * The Drupal form. + * @param array $form_state + * The Drupal form state. */ function islandora_ingest_form_execute_consecutive_callback_steps(array $form, array &$form_state, array $step) { do { @@ -367,7 +410,14 @@ function islandora_ingest_form_execute_consecutive_callback_steps(array $form, a } /** - * Assumes the given $step is a 'callback' step. + * Execute the given 'callback' step. + * + * Assumes the given step is a 'callback' step. + * + * @param array $form + * The Drupal form. + * @param array $form_state + * The Drupal form state. */ function islandora_ingest_form_execute_callback_step(array $form, array &$form_state, array $step) { $args = array(&$form_state); @@ -376,7 +426,14 @@ function islandora_ingest_form_execute_callback_step(array $form, array &$form_s } /** + * Undo the given 'callback' step and any consecutive 'callback' steps. + * * Assumes the given $step is a 'callback' step. + * + * @param array $form + * The Drupal form. + * @param array $form_state + * The Drupal form state. */ function islandora_ingest_form_undo_consecutive_callback_steps(array $form, array &$form_state, array $step) { do { @@ -387,7 +444,14 @@ function islandora_ingest_form_undo_consecutive_callback_steps(array $form, arra } /** + * Undo the given 'callback' step. + * * Assumes the given $step is a 'callback' step. + * + * @param array $form + * The Drupal form. + * @param array $form_state + * The Drupal form state. */ function islandora_ingest_form_undo_callback_step(array $form, array &$form_state, array $step) { $args = array(&$form_state); @@ -691,7 +755,8 @@ function &islandora_ingest_form_get_step_storage(array &$form_state, $step_id = } return $form_state['islandora']['step_storage'][$step_id]; } - return NULL; + $undefined_step_storage = array(); + return $undefined_step_storage; } /** From 0791f5d5f4ded8f5d7422d471bd5080f148a1799 Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Fri, 19 Apr 2013 01:50:38 +0200 Subject: [PATCH 090/172] Undo previous form when callbacks steps exist between it and the current step. Added two functions for navigating by 'form' steps rather than steps. --- includes/ingest.form.inc | 53 ++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 16 deletions(-) diff --git a/includes/ingest.form.inc b/includes/ingest.form.inc index 435bff7c..fb26d72a 100644 --- a/includes/ingest.form.inc +++ b/includes/ingest.form.inc @@ -490,11 +490,7 @@ function islandora_ingest_form_stepify(array $form, array &$form_state, $step) { * TRUE if we are currently on the first step, FALSE otherwise. */ function islandora_ingest_form_on_first_form_step(array &$form_state) { - $step = NULL; - do { - $step = islandora_ingest_form_get_previous_step($form_state, $step); - } while (isset($step) && $step['type'] != 'form'); - return !$step; + return !islandora_ingest_form_get_previous_form_step($form_state); } /** @@ -507,11 +503,41 @@ function islandora_ingest_form_on_first_form_step(array &$form_state) { * TRUE if we are currently on the last step, FALSE otherwise. */ function islandora_ingest_form_on_last_form_step(array &$form_state) { + return !islandora_ingest_form_get_next_form_step($form_state); +} + +/** + * Get the previous form step relative to the current step. + * + * @param array $form_state + * The Drupal form state. + * + * @return array + * The previous form step if one exists, NULL otherwise. + */ +function islandora_ingest_form_get_previous_form_step(array &$form_state) { + $step = NULL; + do { + $step = islandora_ingest_form_get_previous_step($form_state, $step); + } while (isset($step) && $step['type'] != 'form'); + return $step; +} + +/** + * Get the next form step relative to the current step. + * + * @param array $form_state + * The Drupal form state. + * + * @return array + * The next form step if one exists, NULL otherwise. + */ +function islandora_ingest_form_get_next_form_step(array &$form_state) { $step = NULL; do { $step = islandora_ingest_form_get_next_step($form_state, $step); } while (isset($step) && $step['type'] != 'form'); - return !$step; + return $step; } /** @@ -526,17 +552,12 @@ function islandora_ingest_form_on_last_form_step(array &$form_state) { * The previous button for the ingest form. */ function islandora_ingest_form_previous_button(array &$form_state) { - // Before we move back to the previous step we should tell the previous step + // Before we move back to the previous step we should tell the previous steps // to undo whatever its submit handler did. - $prev_step = islandora_ingest_form_get_previous_step($form_state); - if ($prev_step['type'] == 'form') { - $form_id = $prev_step['form_id']; - $submit_callback = $form_id . '_undo_submit'; - $submit = function_exists($submit_callback) ? array($submit_callback, 'islandora_ingest_form_previous_submit') : array('islandora_ingest_form_previous_submit'); - } - else { - $submit = array('islandora_ingest_form_previous_submit'); - } + $prev_form_step = islandora_ingest_form_get_previous_form_step(); + $form_id = $prev_form_step['form_id']; + $submit_callback = $form_id . '_undo_submit'; + $submit = function_exists($submit_callback) ? array($submit_callback, 'islandora_ingest_form_previous_submit') : array('islandora_ingest_form_previous_submit'); return array( '#type' => 'submit', '#value' => t('Previous'), From 69fb08dd73bcc139730e150b16205cc7f24cf00c Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Fri, 19 Apr 2013 01:54:43 +0200 Subject: [PATCH 091/172] Coding standards. --- includes/ingest.form.inc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/ingest.form.inc b/includes/ingest.form.inc index fb26d72a..b26fc875 100644 --- a/includes/ingest.form.inc +++ b/includes/ingest.form.inc @@ -84,8 +84,8 @@ function islandora_ingest_form_init_form_state_storage(array &$form_state, array 'shared_storage' => $configuration, 'step_storage' => array(), ); - // Must be called after $form_state['islandora'] is initialized, otherwise, the values - // in 'islandora' would not be availible to the step hooks. + // Must be called after $form_state['islandora'] is initialized, otherwise, + // the values in 'islandora' would not be availible to the step hooks. $form_state['islandora']['step_id'] = islandora_ingest_form_get_first_step_id($form_state); } } @@ -262,8 +262,8 @@ function islandora_ingest_form_get_next_step_id(array &$form_state, $step_id = N */ function islandora_ingest_form_get_previous_step_id(array &$form_state, $step_id = NULL) { $step_id = isset($step_id) ? $step_id : islandora_ingest_form_get_current_step_id($form_state); - // If the current step is not defined it's assumed that all steps have executed. - // so return the very last step. + // If the current step is not defined it's assumed that all steps have + // executed. So return the very last step. if ($step_id == NULL) { return islandora_ingest_form_get_last_step_id($form_state); } From 07c4c35e9a86f5c13fd87e008eb0f49e314909aa Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Fri, 19 Apr 2013 02:30:19 +0200 Subject: [PATCH 092/172] Missing Argument --- includes/ingest.form.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/ingest.form.inc b/includes/ingest.form.inc index b26fc875..5c9e3e55 100644 --- a/includes/ingest.form.inc +++ b/includes/ingest.form.inc @@ -554,7 +554,7 @@ function islandora_ingest_form_get_next_form_step(array &$form_state) { function islandora_ingest_form_previous_button(array &$form_state) { // Before we move back to the previous step we should tell the previous steps // to undo whatever its submit handler did. - $prev_form_step = islandora_ingest_form_get_previous_form_step(); + $prev_form_step = islandora_ingest_form_get_previous_form_step($form_state); $form_id = $prev_form_step['form_id']; $submit_callback = $form_id . '_undo_submit'; $submit = function_exists($submit_callback) ? array($submit_callback, 'islandora_ingest_form_previous_submit') : array('islandora_ingest_form_previous_submit'); From 3da2fdcb9f46dd1ae8ad6485680eb8b610e8e3ae Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Fri, 19 Apr 2013 09:48:45 -0300 Subject: [PATCH 093/172] added default, changed sorting --- includes/utilities.inc | 52 +++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/includes/utilities.inc b/includes/utilities.inc index 90676923..d1b32d4e 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -204,13 +204,13 @@ function islandora_escape_pid_for_function($pid) { // Apparently, case doesn't matter for function calls in PHP, so let's not // really worry about changing the case. return str_replace( - // Any PID characters which are not valid in the name of a PHP function. - array( - ':', - '-', - ), - '_', - $pid + // Any PID characters which are not valid in the name of a PHP function. + array( + ':', + '-', + ), + '_', + $pid ); } @@ -281,16 +281,16 @@ function islandora_namespace_accessible($id) { function islandora_get_parents_from_rels_ext(FedoraObject $object) { try { $collections = array_merge( - $object->relationships->get(FEDORA_RELS_EXT_URI, 'isMemberOfCollection'), - $object->relationships->get(FEDORA_RELS_EXT_URI, 'isMemberOf')); + $object->relationships->get(FEDORA_RELS_EXT_URI, 'isMemberOfCollection'), + $object->relationships->get(FEDORA_RELS_EXT_URI, 'isMemberOf')); } catch (RepositoryException $e) { // @todo some logging would be nice, not sure what this throws. return array(); } $map = function($o) { - return islandora_object_load($o['object']['value']); - }; + return islandora_object_load($o['object']['value']); + }; $collections = array_map($map, $collections); return array_filter($collections); } @@ -505,7 +505,7 @@ function islandora_display_repository_inaccessible_message() { $text = t('Islandora configuration'); $link = l($text, 'admin/islandora/configure', array('attributes' => array('title' => $text))); $message = t('Could not connect to the repository. Please check the settings on the !link page.', - array('!link' => $link)); + array('!link' => $link)); drupal_set_message($message, 'error', FALSE); } @@ -744,7 +744,7 @@ function islandora_get_content_models($ignore_system_namespace = TRUE) { $label = $result['label']['value']; $namespace = islandora_get_namespace($content_model); $ignore = $ignore_system_namespace && $namespace == 'fedora-system'; - $ignore |= !islandora_namespace_accessible($namespace); + $ignore |= ! islandora_namespace_accessible($namespace); if (!$ignore) { $content_models[$content_model] = array('pid' => $content_model, 'label' => $label); } @@ -759,11 +759,12 @@ function islandora_get_content_models($ignore_system_namespace = TRUE) { * the name of the Drupal variable holding selected content models * Content models held in this variable will appear at the top of * the displayed list - * + * @param array $default_values_array + * default values to display if $drupal_variable is unset * @return array * Drupal form element allowing content model selection */ -function islandora_content_model_select_table_form_element($drupal_variable) { +function islandora_content_model_select_table_form_element($drupal_variable, $default_values_array = array('')) { $defaults = array(); $rows = array(); $content_models = array(); @@ -773,19 +774,24 @@ function islandora_content_model_select_table_form_element($drupal_variable) { $content_models[$option['pid']] = $option['label']; } - $selected = array_values(variable_get($drupal_variable, array(''))); - foreach ($selected as $selection) { - if (isset($content_models[$selection])) { - $content_models = array($selection => $content_models[$selection]) + $content_models; - } - } - + $selected = array_values(variable_get($drupal_variable, $default_values_array)); + $comparator = function ($a, $b) use ($selected) { + $a_val = $b_val = 0; + if (in_array($a, $selected)) { + $a_val = 1; + } + if (in_array($b, $selected)) { + $b_val = 1; + } + return $a_val = $b_val; + }; + uksort($content_models, $comparator); foreach ($content_models as $pid => $label) { $rows[$pid] = array( 'pid' => $pid, 'title' => $label, ); - in_array($pid, $selected) ? $defaults[$pid] = TRUE : $defaults[$pid] = FALSE; + $defaults[$pid] = in_array($pid, $selected); } $header = array( 'pid' => array('data' => t('PID')), From b58fd31f9c179c8c83124c797af2eaf384b8d4eb Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Fri, 19 Apr 2013 11:38:40 -0300 Subject: [PATCH 094/172] formatting, made query more efficient --- includes/utilities.inc | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/includes/utilities.inc b/includes/utilities.inc index d1b32d4e..5b60df50 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -204,7 +204,7 @@ function islandora_escape_pid_for_function($pid) { // Apparently, case doesn't matter for function calls in PHP, so let's not // really worry about changing the case. return str_replace( - // Any PID characters which are not valid in the name of a PHP function. + // Any PID characters which are not valid in the name of a PHP function. array( ':', '-', @@ -281,8 +281,8 @@ function islandora_namespace_accessible($id) { function islandora_get_parents_from_rels_ext(FedoraObject $object) { try { $collections = array_merge( - $object->relationships->get(FEDORA_RELS_EXT_URI, 'isMemberOfCollection'), - $object->relationships->get(FEDORA_RELS_EXT_URI, 'isMemberOf')); + $object->relationships->get(FEDORA_RELS_EXT_URI, 'isMemberOfCollection'), + $object->relationships->get(FEDORA_RELS_EXT_URI, 'isMemberOf')); } catch (RepositoryException $e) { // @todo some logging would be nice, not sure what this throws. @@ -724,17 +724,14 @@ function islandora_get_content_models($ignore_system_namespace = TRUE) { FROM <#ri> WHERE { {?object fm:hasModel ; - fm:state - OPTIONAL{ - ?object fm:label ?label + fm:state fm:Active } - } - UNION - {?object fr:isMemberOfCollection ; - fm:state - OPTIONAL{ - ?object fm:label ?label + UNION{ + ?object fr:isMemberOfCollection ; + fm:state fm:Active } + OPTIONAL{ + ?object fm:label ?label } }"; $content_models = array(); @@ -744,7 +741,7 @@ function islandora_get_content_models($ignore_system_namespace = TRUE) { $label = $result['label']['value']; $namespace = islandora_get_namespace($content_model); $ignore = $ignore_system_namespace && $namespace == 'fedora-system'; - $ignore |= ! islandora_namespace_accessible($namespace); + $ignore |= !islandora_namespace_accessible($namespace); if (!$ignore) { $content_models[$content_model] = array('pid' => $content_model, 'label' => $label); } @@ -776,15 +773,15 @@ function islandora_content_model_select_table_form_element($drupal_variable, $de $selected = array_values(variable_get($drupal_variable, $default_values_array)); $comparator = function ($a, $b) use ($selected) { - $a_val = $b_val = 0; - if (in_array($a, $selected)) { - $a_val = 1; - } - if (in_array($b, $selected)) { - $b_val = 1; - } - return $a_val = $b_val; - }; + $a_val = $b_val = 0; + if (in_array($a, $selected)) { + $a_val = 1; + } + if (in_array($b, $selected)) { + $b_val = 1; + } + return $a_val = $b_val; + }; uksort($content_models, $comparator); foreach ($content_models as $pid => $label) { $rows[$pid] = array( From 84aa0c58f4181132b17fecad2108ecbd39e3bfc0 Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Fri, 19 Apr 2013 14:46:11 -0300 Subject: [PATCH 095/172] changed operator --- includes/utilities.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/utilities.inc b/includes/utilities.inc index 5b60df50..ca1867d3 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -778,9 +778,9 @@ function islandora_content_model_select_table_form_element($drupal_variable, $de $a_val = 1; } if (in_array($b, $selected)) { - $b_val = 1; + $b_val - 1; } - return $a_val = $b_val; + return $a_val - $b_val; }; uksort($content_models, $comparator); foreach ($content_models as $pid => $label) { From 553810a133fbb6ed8f05bd78f7ac5d53ac5d9d8e Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Fri, 19 Apr 2013 14:48:29 -0300 Subject: [PATCH 096/172] changed operator --- includes/utilities.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/utilities.inc b/includes/utilities.inc index ca1867d3..d40b044a 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -778,9 +778,9 @@ function islandora_content_model_select_table_form_element($drupal_variable, $de $a_val = 1; } if (in_array($b, $selected)) { - $b_val - 1; + $b_val = 1; } - return $a_val - $b_val; + return $b_val - $a_val; }; uksort($content_models, $comparator); foreach ($content_models as $pid => $label) { From 4512238721b7983273a4a35385b015a3b9bbd7b0 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Fri, 19 Apr 2013 16:48:01 -0300 Subject: [PATCH 097/172] Fix bug due to alternate menu titles. --- includes/breadcrumb.inc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/includes/breadcrumb.inc b/includes/breadcrumb.inc index 6fdf9e4a..9db4824c 100644 --- a/includes/breadcrumb.inc +++ b/includes/breadcrumb.inc @@ -57,9 +57,10 @@ function islandora_get_breadcrumbs_recursive($pid, FedoraRepository $repository, $root = variable_get('islandora_repository_pid', 'islandora:root'); if ($pid == $root) { + $item = menu_get_item('islandora'); return array( l(t('Home'), ''), - l(menu_get_active_title(), 'islandora'), + l($item['title'], 'islandora'), ); } else { From 9496b0e5fda04424717ff201c8921ecedd116607 Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Fri, 19 Apr 2013 17:01:31 -0300 Subject: [PATCH 098/172] formatting --- includes/utilities.inc | 1 - 1 file changed, 1 deletion(-) diff --git a/includes/utilities.inc b/includes/utilities.inc index d40b044a..6d20dff5 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -765,7 +765,6 @@ function islandora_content_model_select_table_form_element($drupal_variable, $de $defaults = array(); $rows = array(); $content_models = array(); - $options = islandora_get_content_models(TRUE); foreach ($options as $option) { $content_models[$option['pid']] = $option['label']; From f9e406471593e71ae36ef872474ffb96de9036c4 Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Fri, 19 Apr 2013 17:16:32 -0300 Subject: [PATCH 099/172] coder standards --- includes/utilities.inc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/includes/utilities.inc b/includes/utilities.inc index b6bb1854..fbc4585a 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -204,7 +204,7 @@ function islandora_escape_pid_for_function($pid) { // Apparently, case doesn't matter for function calls in PHP, so let's not // really worry about changing the case. return str_replace( - // Any PID characters which are not valid in the name of a PHP function. + // Any PID characters which are not valid in the name of a PHP function. array( ':', '-', @@ -289,8 +289,8 @@ function islandora_get_parents_from_rels_ext(FedoraObject $object) { return array(); } $map = function($o) { - return islandora_object_load($o['object']['value']); - }; + return islandora_object_load($o['object']['value']); + }; $collections = array_map($map, $collections); return array_filter($collections); } @@ -770,6 +770,7 @@ function islandora_get_content_models($ignore_system_namespace = TRUE) { * the displayed list * @param array $default_values_array * default values to display if $drupal_variable is unset + * * @return array * Drupal form element allowing content model selection */ From 79c878a6a67de5d7c931b3980cc47f4deaf9c50c Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Thu, 25 Apr 2013 22:24:32 +0200 Subject: [PATCH 100/172] Added link to customizing ingest steps. --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fd2663b7..0515a848 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ should be copied into the Fedora global XACML policies folder. This will allow CONFIGURATION ------------- -The islandora_drupal_filter passes the username of 'anonymous' through to +The islandora_drupal_filter passes the username of 'anonymous' through to Fedora for unauthenticated Drupal Users. A user with the name of 'anonymous' may have XACML policies applied to them that are meant to be applied to Drupal users that are not logged in or vice-versa. This is a potential security issue @@ -47,6 +47,7 @@ Drupal's cron will can be ran to remove expired authentication tokens. CUSTOMIZATION ------------- +[Customize ingest forms](http://github.com/Islandora/islandora/wiki/Multi-paged-Ingest-Forms) TROUBLESHOOTING --------------- From 3bb2646b5e1b1fb570fa177bb4febca5293177c1 Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Tue, 30 Apr 2013 16:51:17 +0200 Subject: [PATCH 101/172] Added a convience function for generated depreciated function messages. The message will only be displayed to the user if Drupal is configured to show these warnings, regardless of the setting though it will be logged to the watchdog. --- includes/utilities.inc | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/includes/utilities.inc b/includes/utilities.inc index fbc4585a..aac770e2 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -817,3 +817,36 @@ function islandora_content_model_select_table_form_element($drupal_variable, $de return $element; } + +/** + * Convience function for generating a E_USER_DEPRECATED message. + * + * To utilitize this function pass the results to trigger_error() like so: + * + * @code + * $message = islandora_deprecated('7.x-1.1', t('Use more cowbell.')); + * trigger_error($message, E_USER_DEPRECATED); + * @endcode + * + * @param string $release + * The release the calling function was depreciated in. + * @param string $solution + * A message describing an alternative solution to the deprecated function. + * It's assumed to be already passed though the t() function. + * + * @return string + * The deprecated message. + */ +function islandora_deprecated($release, $solution = NULL) { + $bt = debug_backtrace(); + assert($bt[0]['function'] == __FUNCTION__); + $function = $bt[1]['function']; + $message = t('@function() has been deprecated. As of @release, please update your code before the next release.', array( + '@function' => $function, + '@release' => $release, + )); + if (isset($solution)) { + $message .= "
\n" . $solution; + } + return $message; +} From 5fac157cfcb08b9a647c6c70c8ec5ae75baa009c Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Tue, 30 Apr 2013 18:37:34 +0200 Subject: [PATCH 102/172] Appease the Travis God! The one true build master! May my code be clean, and follow the law's of "standard". May it support internationalization for Travis includes all! May it not contain copy pasta for it is soggy. Travis be praised! --- includes/utilities.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/utilities.inc b/includes/utilities.inc index aac770e2..57bf03ba 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -825,7 +825,7 @@ function islandora_content_model_select_table_form_element($drupal_variable, $de * * @code * $message = islandora_deprecated('7.x-1.1', t('Use more cowbell.')); - * trigger_error($message, E_USER_DEPRECATED); + * trigger_error(check_plain($message), E_USER_DEPRECATED); * @endcode * * @param string $release From 8b0b3203384e8da583571c0e2ec9bbe2fcc4b76a Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Tue, 30 Apr 2013 21:46:41 +0200 Subject: [PATCH 103/172] Configuration options now accept multiple objects. Configuration no longer requires validation. Added Convience method for determining if the ingest forms can be rendered. --- includes/ingest.form.inc | 121 +++++++++++++++++++++------------------ includes/utilities.inc | 4 +- 2 files changed, 68 insertions(+), 57 deletions(-) diff --git a/includes/ingest.form.inc b/includes/ingest.form.inc index 5c9e3e55..1d19babe 100644 --- a/includes/ingest.form.inc +++ b/includes/ingest.form.inc @@ -5,6 +5,27 @@ * Defines the multi-page ingest form and any relevant hooks and functions. */ +require_once 'utilities.inc'; + +/** + * Checks if the given configuration can be used to display the ingest form. + * + * @param array $configuration + * The list of key/value pairs of configuration. + * + * @return bool + * TRUE if the give configuration defines one or more form steps, FALSE + * otherwise. + */ +function islandora_ingest_can_display_ingest_form(array $configuration) { + $form_state = array(); + islandora_ingest_form_init_form_state_storage($form_state, $configuration); + $form_steps = islandora_ingest_form_get_form_steps($form_state); + // Forget the stubbed steps for the remainder of this request. + drupal_static_reset('islandora_ingest_form_get_steps'); + return count($form_steps) > 0; +} + /** * Ingest form build function. * @@ -44,26 +65,6 @@ function islandora_ingest_form(array $form, array &$form_state, array $configura } } -/** - * Validates the given ingest configuration. - * - * At the moment it only requires that models are present. - * - * @todo Add hook for manipulating/validating the configuration. - * - * @see islandora_ingest_form() - * - * @throws InvalidArgumentException - * - * @param array $configuration - * The key value pairs that are used to build the multi-paged ingest process. - */ -function islandora_ingest_form_validate_configuration(array $configuration) { - if (empty($configuration['models'])) { - throw new InvalidArgumentException('Ingest configuration not vaild, no models were given'); - } -} - /** * Initializes the form_state storage for use in the ingest multi-page forms. * @@ -75,12 +76,15 @@ function islandora_ingest_form_validate_configuration(array $configuration) { */ function islandora_ingest_form_init_form_state_storage(array &$form_state, array $configuration) { if (empty($form_state['islandora'])) { - // Validate the configuration before we use it. - islandora_ingest_form_validate_configuration($configuration); - $object = islandora_ingest_form_prepare_new_object($configuration); + $objects = isset($configuration['objects']) ? $configuration['objects'] : array(); + if (empty($objects)) { + $objects[] = islandora_ingest_form_prepare_new_object($configuration); + } + // No need to persist the 'objects' within the configuration. + unset($configuration['objects']); $form_state['islandora'] = array( 'step_id' => NULL, - 'objects' => array($object), + 'objects' => $objects, 'shared_storage' => $configuration, 'step_storage' => array(), ); @@ -130,8 +134,9 @@ function islandora_ingest_form_get_last_step_id(array &$form_state) { * The new object. */ function islandora_ingest_form_prepare_new_object(array $configuration) { - module_load_include('inc', 'islandora', 'includes/utilities'); if (empty($configuration['object'])) { + $message = islandora_deprecated('Please use "objects" as the default ingest form configuration property.'); + trigger_error(check_plain($message), E_USER_DEPRECATED); // ID is more specific than namespace so it will take precedence. $id = isset($configuration['namespace']) ? $configuration['namespace'] : 'islandora'; $id = isset($configuration['id']) ? $configuration['id'] : $id; @@ -307,35 +312,6 @@ function islandora_ingest_form_decrement_step(array &$form_state) { } } -/** - * Build a list of steps given only configuration. - * - * XXX: This is used to give an indication of whether there are any steps for a - * given configuration. - * - * @param array $configuration - * The list of key/value pairs of configuration. - */ -function islandora_ingest_get_approximate_steps(array $configuration) { - try { - // @todo, we need to expand the configuration before we can validate it? - // I think this need some thinking. - islandora_ingest_form_validate_configuration($configuration); - } - catch (InvalidArgumentException $e) { - // Don't log or display exception. - return array(); - } - $stubbed_form_state = array( - 'islandora' => array( - 'shared_storage' => $configuration, - ), - ); - $steps = islandora_ingest_form_get_steps($stubbed_form_state); - drupal_static_reset('islandora_ingest_form_get_steps'); - return $steps; -} - /** * Executes the current step. * @@ -826,7 +802,6 @@ function islandora_ingest_form_load_include(array &$form_state) { * of ISLANDORA_INGEST_STEP_HOOK. */ function islandora_ingest_form_get_steps(array &$form_state) { - module_load_include('inc', 'islandora', 'includes/utilities'); $steps = &drupal_static(__FUNCTION__); if (isset($steps)) { return $steps; @@ -854,3 +829,39 @@ function islandora_ingest_form_get_steps(array &$form_state) { uasort($steps, 'drupal_sort_weight'); return $steps; } + +/** + * Filter the ingest steps to only steps of type 'form'. + * + * @param array $form_state + * The Drupal form state. + * + * @return array + * The list of sorted ingest form steps as defined by all implementers + * of ISLANDORA_INGEST_STEP_HOOK. + */ +function islandora_ingest_form_get_form_steps(array &$form_state) { + $steps = islandora_ingest_form_get_steps($form_state); + $form_step_filter = function($o) { + return $o['type'] == 'form'; + }; + return array_filter($steps, $form_step_filter); +} + +/** + * Filter the ingest steps to only steps of type 'form'. + * + * @param array $form_state + * The Drupal form state. + * + * @return array + * The list of sorted ingest callback steps as defined by all implementers + * of ISLANDORA_INGEST_STEP_HOOK. + */ +function islandora_ingest_form_get_callback_steps(array &$form_state) { + $steps = islandora_ingest_form_get_steps($form_state); + $callback_step_filter = function($o) { + return $o['type'] == 'callback'; + }; + return array_filter($steps, $callback_step_filter); +} diff --git a/includes/utilities.inc b/includes/utilities.inc index 57bf03ba..751b85cc 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -824,8 +824,8 @@ function islandora_content_model_select_table_form_element($drupal_variable, $de * To utilitize this function pass the results to trigger_error() like so: * * @code - * $message = islandora_deprecated('7.x-1.1', t('Use more cowbell.')); - * trigger_error(check_plain($message), E_USER_DEPRECATED); + * $message = islandora_deprecated('7.x-1.1', t('Use more cowbell.')) + * trigger_error(check_plain($message), E_USER_DEPRECATED) * @endcode * * @param string $release From da9c62003e801f65de93f4706ba57f09437ddc1b Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Wed, 1 May 2013 17:13:02 +0200 Subject: [PATCH 104/172] Coding standards compliance? --- includes/ingest.form.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/ingest.form.inc b/includes/ingest.form.inc index 1d19babe..0a9ce6e6 100644 --- a/includes/ingest.form.inc +++ b/includes/ingest.form.inc @@ -5,8 +5,6 @@ * Defines the multi-page ingest form and any relevant hooks and functions. */ -require_once 'utilities.inc'; - /** * Checks if the given configuration can be used to display the ingest form. * @@ -134,6 +132,7 @@ function islandora_ingest_form_get_last_step_id(array &$form_state) { * The new object. */ function islandora_ingest_form_prepare_new_object(array $configuration) { + module_load_include('inc', 'islandora', 'includes/utilities'); if (empty($configuration['object'])) { $message = islandora_deprecated('Please use "objects" as the default ingest form configuration property.'); trigger_error(check_plain($message), E_USER_DEPRECATED); @@ -802,6 +801,7 @@ function islandora_ingest_form_load_include(array &$form_state) { * of ISLANDORA_INGEST_STEP_HOOK. */ function islandora_ingest_form_get_steps(array &$form_state) { + module_load_include('inc', 'islandora', 'includes/utilities'); $steps = &drupal_static(__FUNCTION__); if (isset($steps)) { return $steps; From c5e6dfcd7a37e0f91e53d16b8008338c39a91daa Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Thu, 2 May 2013 21:53:34 +0200 Subject: [PATCH 105/172] Changed Parameter Type Hinting to only use the top level Abstract class --- includes/add_datastream.form.inc | 8 ++-- includes/breadcrumb.inc | 2 +- includes/datastream.inc | 28 ++++++------ includes/delete_datastream.form.inc | 6 +-- includes/delete_object.form.inc | 4 +- includes/object_properties.form.inc | 4 +- includes/solution_packs.inc | 10 ++--- includes/tuque_wrapper.inc | 4 +- includes/utilities.inc | 16 +++---- islandora.api.php | 70 ++++++++++++++--------------- islandora.drush.inc | 40 +++++++++++++++++ islandora.module | 50 ++++++++++----------- islandora.rules.inc | 6 +-- tests/islandora_hooks_test.module | 14 +++--- 14 files changed, 151 insertions(+), 111 deletions(-) create mode 100644 islandora.drush.inc diff --git a/includes/add_datastream.form.inc b/includes/add_datastream.form.inc index d19d5757..62490c9a 100644 --- a/includes/add_datastream.form.inc +++ b/includes/add_datastream.form.inc @@ -12,13 +12,13 @@ * The Drupal form. * @param array $form_state * The Drupal form state. - * @param FedoraObject $object + * @param AbstractObject $object * The object to be deleted. * * @return array * The drupal form definition. */ -function islandora_add_datastream_form(array $form, array &$form_state, FedoraObject $object) { +function islandora_add_datastream_form(array $form, array &$form_state, AbstractObject $object) { module_load_include('inc', 'islandora', 'includes/content_model'); module_load_include('inc', 'islandora', 'includes/utilities'); form_load_include($form_state, 'inc', 'islandora', 'includes/add_datastream.form'); @@ -206,13 +206,13 @@ function islandora_add_datastream_form_submit(array $form, array &$form_state) { * * It lists the missing required (may be optional) datastreams. * - * @param FedoraObject $object + * @param AbstractObject $object * The object used to check for missing required datastreams used to populate * the options in this callback. * @param string $query * vThe user query to match against the missing required datastreams. */ -function islandora_add_datastream_form_autocomplete_callback(FedoraObject $object, $query = '') { +function islandora_add_datastream_form_autocomplete_callback(AbstractObject $object, $query = '') { module_load_include('inc', 'islandora', 'includes/content_model'); module_load_include('inc', 'islandora', 'includes/utilities'); $dsids = array_keys(islandora_get_missing_datastreams_requirements($object)); diff --git a/includes/breadcrumb.inc b/includes/breadcrumb.inc index 9db4824c..f27d0e5d 100644 --- a/includes/breadcrumb.inc +++ b/includes/breadcrumb.inc @@ -14,7 +14,7 @@ * ancestry which is identified by any of the following RELS-EXT terms * (isMemberOf,isMemberOfCollection,isPartOf). * - * @param FedoraObject $object + * @param AbstractObject $object * An object whose ancestry will be mapped to bread-crumbs. * * @see drupal_set_breadcrumb() diff --git a/includes/datastream.inc b/includes/datastream.inc index b817b70d..23eb44f9 100644 --- a/includes/datastream.inc +++ b/includes/datastream.inc @@ -8,10 +8,10 @@ /** * Callback to download the given datastream to the users computer. * - * @param FedoraDatastream $datastream + * @param AbstractDatastream $datastream * The datastream to download. */ -function islandora_download_datastream(FedoraDatastream $datastream) { +function islandora_download_datastream(AbstractDatastream $datastream) { islandora_view_datastream($datastream, TRUE); } @@ -21,13 +21,13 @@ function islandora_download_datastream(FedoraDatastream $datastream) { * @note * This function calls exit(). * - * @param FedoraDatastream $datastream + * @param AbstractDatastream $datastream * The datastream to view/download. * @param bool $download * If TRUE the file is download to the user computer for viewing otherwise it * will attempt to display in the browser natively. */ -function islandora_view_datastream(FedoraDatastream $datastream, $download = FALSE) { +function islandora_view_datastream(AbstractDatastream $datastream, $download = FALSE) { header_remove('Cache-Control'); header_remove('Expires'); header('Content-type: ' . $datastream->mimetype); @@ -51,14 +51,14 @@ function islandora_view_datastream(FedoraDatastream $datastream, $download = FAL /** * Get the human readable size of the given datastream. * - * @param FedoraDatastream $datastream + * @param AbstractDatastream $datastream * The datastream to check. * * @return string * A human readable size of the given datastream, or '-' if the size could not * be determined. */ -function islandora_datastream_get_human_readable_size(FedoraDatastream $datastream) { +function islandora_datastream_get_human_readable_size(AbstractDatastream $datastream) { module_load_include('inc', 'islandora', 'includes/utilities'); $size_is_calculatable = $datastream->controlGroup == 'M' || $datastream->controlGroup == 'X'; return $size_is_calculatable ? islandora_convert_bytes_to_human_readable($datastream->size) : '-'; @@ -67,23 +67,23 @@ function islandora_datastream_get_human_readable_size(FedoraDatastream $datastre /** * Get either the 'view' or 'download' url for the given datastream if possible. * - * @param FedoraDatastream $datastream + * @param AbstractDatastream $datastream * The datastream to generated the url to. * * @return string * either the 'view' or 'download' url for the given datastream. */ -function islandora_datastream_get_url(FedoraDatastream $datastream, $type = 'download') { +function islandora_datastream_get_url(AbstractDatastream $datastream, $type = 'download') { return $datastream->controlGroup == 'R' ? $datastream->url : "islandora/object/{$datastream->parent->id}/datastream/{$datastream->id}/$type"; } /** * Gets the delete link. * - * @param FedoraDatastream $datastream + * @param AbstractDatastream $datastream * The datastream to generated the url to. */ -function islandora_datastream_get_delete_link(FedoraDatastream $datastream) { +function islandora_datastream_get_delete_link(AbstractDatastream $datastream) { $datastreams = module_invoke_all('islandora_undeletable_datastreams', $datastream->parent->models); $can_delete = !in_array($datastream->id, $datastreams); return $can_delete ? l(t('delete'), "islandora/object/{$datastream->parent->id}/datastream/{$datastream->id}/delete") : ''; @@ -92,10 +92,10 @@ function islandora_datastream_get_delete_link(FedoraDatastream $datastream) { /** * Gets the edit link. * - * @param FedoraDatastream $datastream + * @param AbstractDatastream $datastream * The datastream to generated the url to. */ -function islandora_datastream_edit_get_link(FedoraDatastream $datastream) { +function islandora_datastream_edit_get_link(AbstractDatastream $datastream) { $edit_registry = module_invoke_all('islandora_edit_datastream_registry', $datastream->parent, $datastream); $can_edit = count($edit_registry) > 0 && user_access(FEDORA_METADATA_EDIT); return $can_edit ? l(t('edit'), "islandora/object/{$datastream->parent->id}/datastream/{$datastream->id}/edit") : ''; @@ -104,10 +104,10 @@ function islandora_datastream_edit_get_link(FedoraDatastream $datastream) { /** * Display the edit datastream page. * - * @param FedoraDatastream $datastream + * @param AbstractDatastream $datastream * The datastream to edit. */ -function islandora_edit_datastream(FedoraDatastream $datastream) { +function islandora_edit_datastream(AbstractDatastream $datastream) { $edit_registry = module_invoke_all('islandora_edit_datastream_registry', $datastream->parent, $datastream); $edit_count = count($edit_registry); switch ($edit_count) { diff --git a/includes/delete_datastream.form.inc b/includes/delete_datastream.form.inc index faf92a18..b94e0141 100644 --- a/includes/delete_datastream.form.inc +++ b/includes/delete_datastream.form.inc @@ -12,13 +12,13 @@ * The Drupal form. * @param array $form_state * The Drupal form state. - * @param FedoraDatastream $datastream + * @param AbstractDatastream $datastream * The datastream to be deleted. * * @return array * The drupal form definition. */ -function islandora_delete_datastream_form(array $form, array &$form_state, FedoraDatastream $datastream) { +function islandora_delete_datastream_form(array $form, array &$form_state, AbstractDatastream $datastream) { $form_state['datastream'] = $datastream; return confirm_form($form, t('Are you sure you want to delete the %dsid datastream?', array('%dsid' => $datastream->id)), @@ -32,7 +32,7 @@ function islandora_delete_datastream_form(array $form, array &$form_state, Fedor /** * Submit handler for the delete datastream form. * - * Purges/Delete's the given FedoraDatastream if possible. + * Purges/Delete's the given AbstractDatastream if possible. * * The ISLANDORA_PRE_PURGE_DATASTREAM_HOOK will query other modules as to * whether the given FedoraDatastream diff --git a/includes/delete_object.form.inc b/includes/delete_object.form.inc index 46210e3c..4b893074 100644 --- a/includes/delete_object.form.inc +++ b/includes/delete_object.form.inc @@ -12,13 +12,13 @@ * The Drupal form. * @param array $form_state * The Drupal form state. - * @param FedoraObject $object + * @param AbstractObject $object * The object to be deleted. * * @return array * The drupal form definition. */ -function islandora_delete_object_form(array $form, array &$form_state, FedoraObject $object) { +function islandora_delete_object_form(array $form, array &$form_state, AbstractObject $object) { $form_state['object'] = $object; return confirm_form($form, t('Are you sure you want to delete %title?', array('%title' => $object->label)), diff --git a/includes/object_properties.form.inc b/includes/object_properties.form.inc index c9de5e8f..543fa6dd 100644 --- a/includes/object_properties.form.inc +++ b/includes/object_properties.form.inc @@ -12,13 +12,13 @@ * The Drupal form. * @param array $form_state * The Drupal form state. - * @param FedoraObject $object + * @param AbstractObject $object * The object whose properties this form will modify. * * @return array * The drupal form definition. */ -function islandora_object_properties_form(array $form, array &$form_state, FedoraObject $object) { +function islandora_object_properties_form(array $form, array &$form_state, AbstractObject $object) { drupal_set_title($object->label); $form_state['object'] = $object; return array( diff --git a/includes/solution_packs.inc b/includes/solution_packs.inc index aa09c8a4..26bd77b5 100644 --- a/includes/solution_packs.inc +++ b/includes/solution_packs.inc @@ -180,12 +180,12 @@ function islandora_solution_pack_form_submit(array $form, array &$form_state) { /** * Batch operation to ingest/reingest required object(s). * - * @param NewFedoraObject $object + * @param AbstractObject $object * The object to ingest/reingest. * @param array $context * The context of this batch operation. */ -function islandora_solution_pack_batch_operation_reingest_object(NewFedoraObject $object, array &$context) { +function islandora_solution_pack_batch_operation_reingest_object(AbstractObject $object, array &$context) { $existing_object = islandora_object_load($object->id); $deleted = FALSE; if ($existing_object) { @@ -367,7 +367,7 @@ function islandora_uninstall_solution_pack($module) { /** * Function to check the status of an object against an object model array. * - * @param NewFedoraObject $object_definition + * @param AbstractObject $object_definition * A new fedora object that defines what the object should contain. * * @return string @@ -378,7 +378,7 @@ function islandora_uninstall_solution_pack($module) { * @see islandora_solution_pack_form() * @see islandora_install_solution_pack() */ -function islandora_check_object_status(NewFedoraObject $object_definition) { +function islandora_check_object_status(AbstractObject $object_definition) { $existing_object = islandora_object_load($object_definition->id); if (!$existing_object) { return array('status' => 'missing', 'status_friendly' => t('Missing')); @@ -627,7 +627,7 @@ function theme_islandora_viewers_table($variables) { * Array or string with data the module needs in order to render a full viewer * @param string $variable_id * The id of the Drupal variable the viewer settings are saved in - * @param FedoraObject $fedora_object + * @param AbstractObject $fedora_object * The tuque object representing the fedora object being displayed * * @return string diff --git a/includes/tuque_wrapper.inc b/includes/tuque_wrapper.inc index 14a770e2..8563070f 100644 --- a/includes/tuque_wrapper.inc +++ b/includes/tuque_wrapper.inc @@ -34,7 +34,7 @@ $islandora_module_path = drupal_get_path('module', 'islandora'); /** * Allow modules to alter an object before a mutable event occurs. */ -function islandora_alter_object(AbstractFedoraObject $object, array &$context) { +function islandora_alter_object(AbstractObject $object, array &$context) { module_load_include('inc', 'islandora', 'includes/utilities'); drupal_alter(islandora_build_hook_list('islandora_object', $object->models), $object, $context); } @@ -42,7 +42,7 @@ function islandora_alter_object(AbstractFedoraObject $object, array &$context) { /** * Allow modules to alter a datastream before a mutable event occurs. */ -function islandora_alter_datastream(AbstractFedoraObject $object, AbstractDatastream $datastream, array &$context) { +function islandora_alter_datastream(AbstractObject $object, AbstractDatastream $datastream, array &$context) { module_load_include('inc', 'islandora', 'includes/utilities'); $types = array(); foreach ($object->models as $model) { diff --git a/includes/utilities.inc b/includes/utilities.inc index fbc4585a..15f9b339 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -271,14 +271,14 @@ function islandora_namespace_accessible($id) { * This function gets its info from the RELS-EXT directly rather than through an * risearch. * - * @param FedoraObject $object + * @param AbstractObject $object * The object whose parents will be returned. * * @return array * An array of FedoraObject's that the given object has a * (isMemberOf, isMemberOfCollection) relationship with. */ -function islandora_get_parents_from_rels_ext(FedoraObject $object) { +function islandora_get_parents_from_rels_ext(AbstractObject $object) { try { $collections = array_merge( $object->relationships->get(FEDORA_RELS_EXT_URI, 'isMemberOfCollection'), @@ -298,7 +298,7 @@ function islandora_get_parents_from_rels_ext(FedoraObject $object) { /** * Gets the datastreams requirments that are missing. * - * @param FedoraObject $object + * @param AbstractObject $object * The object which models will be used to determine what datastreams it * should have. * @@ -306,7 +306,7 @@ function islandora_get_parents_from_rels_ext(FedoraObject $object) { * The DS-COMPOSITE-MODEL defined datastreams that are required for the given * object, but not already present. */ -function islandora_get_missing_datastreams_requirements(FedoraObject $object) { +function islandora_get_missing_datastreams_requirements(AbstractObject $object) { module_load_include('inc', 'islandora', 'includes/utilities'); $datastreams = islandora_get_datastreams_requirements($object); foreach ($datastreams as $dsid => $requirements) { @@ -331,7 +331,7 @@ function islandora_get_missing_datastreams_requirements(FedoraObject $object) { * * @see islandora_get_required_datastreams_from_content_model() * - * @param FedoraObject $object + * @param AbstractObject $object * The object which models will be used to determine what datastreams it * should have. * @@ -339,7 +339,7 @@ function islandora_get_missing_datastreams_requirements(FedoraObject $object) { * The DS-COMPOSITE-MODEL defined datastreams that are required for the given * object. */ -function islandora_get_datastreams_requirements(FedoraObject $object) { +function islandora_get_datastreams_requirements(AbstractObject $object) { return islandora_get_datastreams_requirements_from_models($object->models); } @@ -375,7 +375,7 @@ function islandora_get_datastreams_requirements_from_models(array $models) { * * @todo Add support for fetching the schema information. * - * @param FedoraObject $object + * @param AbstractObject $object * The content model whose DS-COMPOSITE-MODEL datastream will be used to * determine what datastreams are required. * @@ -388,7 +388,7 @@ function islandora_get_datastreams_requirements_from_models(array $models) { * - "mime": A array containing MIME-types the stream may have. * - "optional": A boolean indicating if the given stream is optional. */ -function islandora_get_datastreams_requirements_from_content_model(FedoraObject $object) { +function islandora_get_datastreams_requirements_from_content_model(AbstractObject $object) { if (empty($object[DS_COMP_STREAM])) { return array(); } diff --git a/islandora.api.php b/islandora.api.php index 17db59ad..89e1e048 100644 --- a/islandora.api.php +++ b/islandora.api.php @@ -8,7 +8,7 @@ /** * Generate a repository objects view. * - * @param FedoraObject $object + * @param AbstractObject $object * The object to display * @param object $user * The user accessing the object. @@ -29,7 +29,7 @@ function hook_islandora_view_object($object, $user, $page_number, $page_size) { * Content models PIDs have colons and hyphens changed to underscores, to * create the hook name. * - * @param FedoraObject $object + * @param AbstractObject $object * A Tuque FedoraObject * * @return array @@ -42,8 +42,8 @@ function hook_CMODEL_PID_islandora_view_object($object) { /** * Alter display output after it has been generated. * - * @param FedoraObject $object - * A Tuque FedoraObject being operated on. + * @param AbstractObject $object + * A Tuque AbstractObject being operated on. * @param array $rendered * The array of rendered views. */ @@ -55,8 +55,8 @@ function hook_islandora_view_object_alter(&$object, &$rendered) { * * @see hook_islandora_view_object_alter() * - * @param FedoraObject $object - * A Tuque FedoraObject being operated on. + * @param AbstractObject $object + * A Tuque AbstractObject being operated on. * @param array $rendered * The array of rendered views. */ @@ -66,7 +66,7 @@ function hook_CMODEL_PID_islandora_view_object_alter(&$object, &$rendered) { /** * Generate an object's management display. * - * @param FedoraObject $object + * @param AbstractObject $object * A Tuque FedoraObject * * @return array @@ -81,7 +81,7 @@ function hook_islandora_edit_object($object) { * Content models PIDs have colons and hyphens changed to underscores, to * create the hook name. * - * @param FedoraObject $object + * @param AbstractObject $object * A Tuque FedoraObject * * @return array @@ -93,7 +93,7 @@ function hook_CMODEL_PID_islandora_edit_object($object) { /** * Allow management display output to be altered. * - * @param FedoraObject $object + * @param AbstractObject $object * A Tuque FedoraObject * @param array $rendered * an arr of rendered views @@ -110,7 +110,7 @@ function hook_islandora_edit_object_alter(&$object, &$rendered) { * Changing object properties such as "label", or "state", are considered * modifications, where as manipulating an object's datstreams are not. * - * @param AbstractFedoraObject $object + * @param AbstractObject $object * The object to alter. * @param array $context * An associative array containing: @@ -130,7 +130,7 @@ function hook_islandora_edit_object_alter(&$object, &$rendered) { * * @see FedoraApiM::modifyObject() */ -function hook_islandora_object_alter(AbstractFedoraObject $object, array &$context) { +function hook_islandora_object_alter(AbstractObject $object, array &$context) { } /** @@ -138,7 +138,7 @@ function hook_islandora_object_alter(AbstractFedoraObject $object, array &$conte * * @see hook_islandora_object_alter() */ -function hook_CMODEL_PID_islandora_object_alter(AbstractFedoraObject $object, array &$context) { +function hook_CMODEL_PID_islandora_object_alter(AbstractObject $object, array &$context) { } /** @@ -151,15 +151,15 @@ function hook_CMODEL_PID_islandora_object_alter(AbstractFedoraObject $object, ar * immediately, instead it will be triggered for all datastreams at the time * of the NewFedoraObject's ingest. * - * Purging datastreams from a NewFedoraObject will not trigger this alter hook + * Purging datastreams from a AbstractObject will not trigger this alter hook * at all. * * Changing datastream's properties such as "label", or "state", are considered * modifications, as well as changing the datastreams content. * - * @param AbstractFedoraObject $object + * @param AbstractObject $object * The object to the datastream belong to. - * @param AbstractFedoraDatastream $datastream + * @param AbstractDatastream $datastream * The datastream to alter. * @param array $context * An associative array containing: @@ -179,7 +179,7 @@ function hook_CMODEL_PID_islandora_object_alter(AbstractFedoraObject $object, ar * * @see FedoraApiM::modifyDatastream() */ -function hook_islandora_datastream_alter(AbstractFedoraObject $object, AbstractFedoraDatastream $datastream, array &$context) { +function hook_islandora_datastream_alter(AbstractObject $object, AbstractDatastream $datastream, array &$context) { } /** @@ -187,7 +187,7 @@ function hook_islandora_datastream_alter(AbstractFedoraObject $object, AbstractF * * @see hook_islandora_datastream_alter() */ -function hook_CMODEL_PID_DSID_islandora_datastream_alter(AbstractFedoraObject $object, AbstractFedoraDatastream $datastream, array &$context) { +function hook_CMODEL_PID_DSID_islandora_datastream_alter(AbstractObject $object, AbstractDatastream $datastream, array &$context) { } /** @@ -200,10 +200,10 @@ function hook_CMODEL_PID_DSID_islandora_datastream_alter(AbstractFedoraObject $o * If ingested directly via the FedoraApiM object this will not be called as we * don't have access to the ingested object at that time. * - * @param FedoraObject $object + * @param AbstractObject $object * The object that was ingested. */ -function hook_islandora_object_ingested(FedoraObject $object) { +function hook_islandora_object_ingested(AbstractObject $object) { } /** @@ -211,7 +211,7 @@ function hook_islandora_object_ingested(FedoraObject $object) { * * @see hook_islandora_object_ingested() */ -function hook_CMODEL_PID_islandora_object_ingested(FedoraObject $object) { +function hook_CMODEL_PID_islandora_object_ingested(AbstractObject $object) { } /** @@ -222,13 +222,13 @@ function hook_CMODEL_PID_islandora_object_ingested(FedoraObject $object) { * Changing object properties such as "label", or "state", are considered * modifications, where as manipulating an object's datstreams are not. * - * @param FedoraObject $object + * @param AbstractObject $object * The object that was ingested. * * @todo We should also include what changes were made in a additional * parameter. */ -function hook_islandora_object_modified(FedoraObject $object) { +function hook_islandora_object_modified(AbstractObject $object) { } /** @@ -236,7 +236,7 @@ function hook_islandora_object_modified(FedoraObject $object) { * * @see hook_islandora_object_modified() */ -function hook_CMODEL_PID_islandora_object_modified(FedoraObject $object) { +function hook_CMODEL_PID_islandora_object_modified(AbstractObject $object) { } /** @@ -268,12 +268,12 @@ function hook_CMODEL_PID_islandora_object_purged($pid) { * If ingested directly via the FedoraApiM object this will not be called as we * don't have access to the ingested datastream at that time. * - * @param FedoraObject $object + * @param AbstractObject $object * The object the datastream belongs to. - * @param FedoraDatastream $datastream + * @param AbstractDatastream $datastream * The ingested datastream. */ -function hook_islandora_datastream_ingested(FedoraObject $object, FedoraDatastream $datastream) { +function hook_islandora_datastream_ingested(AbstractObject $object, AbstractDatastream $datastream) { } /** @@ -281,7 +281,7 @@ function hook_islandora_datastream_ingested(FedoraObject $object, FedoraDatastre * * @see hook_islandora_object_ingested() */ -function hook_CMODEL_PID_DSID_islandora_datastream_ingested(FedoraObject $object, FedoraDatastream $datastream) { +function hook_CMODEL_PID_DSID_islandora_datastream_ingested(AbstractObject $object, AbstractDatastream $datastream) { } /** @@ -292,15 +292,15 @@ function hook_CMODEL_PID_DSID_islandora_datastream_ingested(FedoraObject $object * Changing datastream properties such as "label", or "state", are considered * modifications, as well as the datastreams content. * - * @param FedoraObject $object + * @param AbstractObject $object * The object the datastream belongs to. - * @param FedoraDatastream $datastream + * @param AbstractDatastream $datastream * The datastream that was ingested. * * @todo We should also include what changes were made in a additional * parameter. */ -function hook_islandora_datastream_modified(FedoraObject $object, FedoraDatastream $datastream) { +function hook_islandora_datastream_modified(AbstractObject $object, AbstractDatastream $datastream) { } /** @@ -308,7 +308,7 @@ function hook_islandora_datastream_modified(FedoraObject $object, FedoraDatastre * * @see hook_islandora_datastream_modified() */ -function hook_CMODEL_PID_islandora_datastream_modified(FedoraObject $object, FedoraDatastream $datastream) { +function hook_CMODEL_PID_islandora_datastream_modified(AbstractObject $object, AbstractDatastream $datastream) { } /** @@ -317,12 +317,12 @@ function hook_CMODEL_PID_islandora_datastream_modified(FedoraObject $object, Fed * This hook is called after an datastream has been successfully purged, or * when its state has been changed to "Deleted". * - * @param FedoraObject $object + * @param AbstractObject $object * The object the datastream belonged to. * @param string $dsid * The ID of the datastream that was purged/deleted. */ -function hook_islandora_datastream_purged(FedoraObject $object, $dsid) { +function hook_islandora_datastream_purged(AbstractObject $object, $dsid) { } /** @@ -330,13 +330,13 @@ function hook_islandora_datastream_purged(FedoraObject $object, $dsid) { * * @see hook_islandora_datastream_purged() */ -function hook_CMODEL_PID_islandora_datastream_purged(FedoraObject $object, $dsid) { +function hook_CMODEL_PID_islandora_datastream_purged(AbstractObject $object, $dsid) { } /** * Register a datastream edit route/form. * - * @param FedoraObject $object + * @param AbstractObject $object * The object to check. * @param string $dsid * todo diff --git a/islandora.drush.inc b/islandora.drush.inc new file mode 100644 index 00000000..e83ba046 --- /dev/null +++ b/islandora.drush.inc @@ -0,0 +1,40 @@ + array( + 'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_ROOT, + 'description' => dt('Corrects the type hinting for function parameters that reference non-abstract Tuque objects. Converts to a more generic form of AbstractObject. Be warned this will modify the source code in your site!'), + ), + ); +} + +/** + * Drush command callback. + * + * Corrects the type hinting in parameters such that they only use AbstractObject. + */ +function drush_islandora_correct_type_hinting() { + drush_print(dt('This will modify source code within your Drupal site. This can not be reversed.')); + if (!drush_confirm(dt('Do you really want to continue?'))) { + return drush_user_abort(); + } + // Only change files within modules directories and only modify php files. + $ret = -1; + passthru('find . -regex ".*\.\(php\|inc\|test\|module\|install\)" -path "*/modules/*" | xargs perl -pi -e "s/(\(.*)(AbstractFedoraObject|FedoraObject|NewFedoraObject|IslandoraFedoraObject|IslandoraNewFedoraObject)( .*\))/\1AbstractObject\3/g"', $ret); + passthru('find . -regex ".*\.\(php\|inc\|test\|module\|install\)" -path "*/modules/*" | xargs perl -pi -e "s/(\(.*)(AbstractFedoraDatastream|AbstractExistingFedoraDatastream|FedoraDatastream|NewFedoraDatastream|FedoraDatastreamVersion|IslandoraNewFedoraDatastream|IslandoraFedoraDatastream|IslandoraFedoraDatastreamVersion)( .*\))/\1AbstractDatastream\3/g"', $ret); +} + +function drush_islandora_correct_type_hinting_validate() { + if (drush_is_windows()) { + drush_set_error(dt("Sorry but this hasn't been implemented for Windows, it only works on unix systems.")); + } +} diff --git a/islandora.module b/islandora.module index ad9e569e..79672625 100644 --- a/islandora.module +++ b/islandora.module @@ -370,7 +370,7 @@ function islandora_forms($form_id) { * @global $user * * @param mixed $object - * The FedoraObject or FedoraDatastream to test for accessibility, if NULL + * The AbstractObject or AbstractDatastream to test for accessibility, if NULL * is given the object is assumed to not exist or be inaccessible. * @param array $permissions * The required user permissions. @@ -448,7 +448,7 @@ function islandora_user_access($object, array $permissions, $content_models = ar * * @param string $perm * User permission to test for. - * @param FedoraObject $object + * @param AbstractObject $object * The object to test, if NULL given the object doesn't exist or is * inaccessible. * @@ -474,10 +474,10 @@ function islandora_object_access_callback($perm, $object = NULL) { * * @param string $perm * The user permission to test for. - * @param FedoraObject $object + * @param AbstractObject $object * The object to test, if NULL given the object doesn't exist or is * inaccessible. - * @param FedoraDatastream $datastream + * @param AbstractDatastream $datastream * The datastream to test, if NULL given the datastream doesn't exist * or is inaccessible. * @param StdObject $account @@ -525,7 +525,7 @@ function islandora_object_datastream_tokened_access_callback($perm, $object = NU * * @param array $perms * Array of user permission to test for. - * @param FedoraObject $object + * @param AbstractObject $object * The object to test, if NULL given the object doesn't exist or is * inaccessible. * @@ -551,13 +551,13 @@ function islandora_object_manage_access_callback($perms, $object = NULL) { /** * Renders the given objects manage overview page. * - * @param FedoraObject $object + * @param AbstractObject $object * The object to manage. * * @return string * The HTML repersentation of the manage object page. */ -function islandora_manage_overview_object(FedoraObject $object) { +function islandora_manage_overview_object(AbstractObject $object) { module_load_include('inc', 'islandora', 'includes/utilities'); $output = array(); foreach (islandora_build_hook_list(ISLANDORA_OVERVIEW_HOOK, $object->models) as $hook) { @@ -578,14 +578,14 @@ function islandora_manage_overview_object(FedoraObject $object) { /** * Renders the default manage object page for the given object. * - * @param FedoraObject $object + * @param AbstractObject $object * The object used to render the manage object page. * * @return array * The default rendering of the object manage page, indexed at * 'Default Edit output'. */ -function islandora_default_islandora_manage_overview_object(FedoraObject $object) { +function islandora_default_islandora_manage_overview_object(AbstractObject $object) { $output = theme('islandora_default_overview', array('islandora_object' => $object)); return array('Default overview output' => $output); } @@ -599,13 +599,13 @@ function islandora_default_islandora_manage_overview_object(FedoraObject $object * If no modules implement 'ISLANDORA_EDIT_HOOK' then this function returns the * default manage view. * - * @param FedoraObject $object + * @param AbstractObject $object * The object to manage. * * @return string * The HTML repersentation of the manage object page. */ -function islandora_edit_object(FedoraObject $object) { +function islandora_edit_object(AbstractObject $object) { module_load_include('inc', 'islandora', 'includes/breadcrumb'); module_load_include('inc', 'islandora', 'includes/utilities'); drupal_set_title($object->label); @@ -629,14 +629,14 @@ function islandora_edit_object(FedoraObject $object) { /** * Renders the default manage object page for the given object. * - * @param FedoraObject $object + * @param AbstractObject $object * The object used to render the manage object page. * * @return array * The default rendering of the object manage page, indexed at * 'Default Edit output'. */ -function islandora_default_islandora_edit_object(FedoraObject $object) { +function islandora_default_islandora_edit_object(AbstractObject $object) { $output = theme('islandora_default_edit', array('islandora_object' => $object)); return array('Default Edit output' => $output); } @@ -661,13 +661,13 @@ function islandora_view_default_object() { * If no modules implement the hook then the default view object page * will be rendered. * - * @param FedoraObject $object + * @param AbstractObject $object * The object to view. * * @return string * The html repersentation of this object. */ -function islandora_view_object(FedoraObject $object) { +function islandora_view_object(AbstractObject $object) { module_load_include('inc', 'islandora', 'includes/breadcrumb'); module_load_include('inc', 'islandora', 'includes/utilities'); drupal_set_title($object->label); @@ -697,7 +697,7 @@ function islandora_view_object(FedoraObject $object) { /** * Renders the default view object page for the given object. * - * @param FedoraObject $object + * @param AbstractObject $object * The object used to render the view object page. * * @return array @@ -849,7 +849,7 @@ function islandora_tokened_datastream_load($datastream_id, $map) { * * @param mixed $object_id * The object to load the datastream from. This can be a Fedora PID or - * an instantiated IslandoraFedoraObject as it implements __toString() + * an instantiated IslandoraAbstractObject as it implements __toString() * returning the PID. * * @return FedoraDatastream @@ -872,7 +872,7 @@ function islandora_datastream_load($datastream_id, $object_id) { * attribute, as in: * repository->ingestObject($object); } /** * Delete's or purges the given object. * - * @param FedoraObject $object + * @param AbstractObject $object * An object to delete. * * @return bool * TRUE if successful, FALSE otherwise. */ -function islandora_delete_object(FedoraObject &$object) { +function islandora_delete_object(AbstractObject &$object) { try { $object->repository->purgeObject($object->id); $object = NULL; @@ -979,13 +979,13 @@ function islandora_delete_object(FedoraObject &$object) { * Which types are undefined, but more than likely because of the hooks * there will be several kinds. * - * @param FedoraDatastream $datastream + * @param AbstractDatastream $datastream * The datastream to delete. * * @return bool * TRUE if successful, FALSE otherwise. */ -function islandora_delete_datastream(FedoraDatastream &$datastream) { +function islandora_delete_datastream(AbstractDatastream &$datastream) { $object = $datastream->parent; return $object->purgeDatastream($datastream->id); } @@ -1065,7 +1065,7 @@ function islandora_entity_property_info() { * Modules can either implement preprocess functions to append content onto the * 'content' variable, or override the display by providing a theme suggestion. * - * @param FedoraObject $object + * @param AbstractObject $object * The object. * * @return array diff --git a/islandora.rules.inc b/islandora.rules.inc index 7a97e44a..4045b1b9 100644 --- a/islandora.rules.inc +++ b/islandora.rules.inc @@ -80,7 +80,7 @@ function islandora_rules_action_info() { /** * Checks that there is a relationship match on the given object. * - * Takes a subject (either a FedoraObject or a FedoraDatastream), as well as + * Takes a subject (either a AbstractObject or a FedoraDatastream), as well as * the parameters for FedoraRelsExt::get() or FedoraRelsInt::get(), to try to * find a match. * @@ -94,7 +94,7 @@ function islandora_object_has_relationship($sub, $pred_uri, $pred, $object, $typ /** * Remove a relationship from the given object. * - * Takes a subject (either a FedoraObject or a FedoraDatastream), as well as + * Takes a subject (either a AbstractObject or a FedoraDatastream), as well as * the parameters for FedoraRelsExt::remove() or FedoraRelsInt::remove(), to * try to find a match. * @@ -107,7 +107,7 @@ function islandora_object_remove_relationship($sub, $pred_uri, $pred, $object, $ /** * Add a relationship to the given object. * - * Takes a subject (either a FedoraObject or a FedoraDatastream), as well as + * Takes a subject (either a AbstractObject or a FedoraDatastream), as well as * the parameters for FedoraRelsExt::add() or FedoraRelsInt::add(), and adds * the represented relationship. * diff --git a/tests/islandora_hooks_test.module b/tests/islandora_hooks_test.module index 315b88ee..a6b8a5b6 100644 --- a/tests/islandora_hooks_test.module +++ b/tests/islandora_hooks_test.module @@ -8,7 +8,7 @@ /** * Implements hook_islandora_object_alter(). */ -function islandora_hooks_test_islandora_object_alter(AbstractFedoraObject $object, array &$context) { +function islandora_hooks_test_islandora_object_alter(AbstractObject $object, array &$context) { switch ($context['action']) { case 'ingest': if ($object->id == 'test:testIngestedObjectHook') { @@ -54,7 +54,7 @@ function islandora_hooks_test_islandora_object_alter(AbstractFedoraObject $objec /** * Implements hook_islandora_object_alter(). */ -function islandora_hooks_test_islandora_datastream_alter(AbstractFedoraObject $object, AbstractFedoraDatastream $datastream, array &$context) { +function islandora_hooks_test_islandora_datastream_alter(AbstractObject $object, AbstractDatastream $datastream, array &$context) { switch ($context['action']) { case 'ingest': if ($object->id == 'test:testIngestedDatastreamHook') { @@ -100,7 +100,7 @@ function islandora_hooks_test_islandora_datastream_alter(AbstractFedoraObject $o /** * Implements hook_islandora_object_ingested(). */ -function islandora_hooks_test_islandora_object_ingested(FedoraObject $object) { +function islandora_hooks_test_islandora_object_ingested(AbstractObject $object) { if ($object->id == 'test:testIngestedObjectHook') { $_SESSION['islandora_hooks']['hook'][ISLANDORA_OBJECT_INGESTED_HOOK] = TRUE; } @@ -109,7 +109,7 @@ function islandora_hooks_test_islandora_object_ingested(FedoraObject $object) { /** * Implements hook_islandora_object_modified(). */ -function islandora_hooks_test_islandora_object_modified(FedoraObject $object) { +function islandora_hooks_test_islandora_object_modified(AbstractObject $object) { if ($object->id == 'test:testModifiedObjectHook') { $_SESSION['islandora_hooks']['hook'][ISLANDORA_OBJECT_MODIFIED_HOOK] = TRUE; } @@ -127,7 +127,7 @@ function islandora_hooks_test_islandora_object_purged($pid) { /** * Implements hook_islandora_datastream_ingested(). */ -function islandora_hooks_test_islandora_datastream_ingested(FedoraObject $object, FedoraDatastream $datastream) { +function islandora_hooks_test_islandora_datastream_ingested(AbstractObject $object, AbstractDatastream $datastream) { if ($object->id == 'test:testIngestedDatastreamHook' && $datastream->id == "TEST") { $_SESSION['islandora_hooks']['hook'][ISLANDORA_DATASTREAM_INGESTED_HOOK] = TRUE; } @@ -136,7 +136,7 @@ function islandora_hooks_test_islandora_datastream_ingested(FedoraObject $object /** * Implements hook_islandora_datastream_modified(). */ -function islandora_hooks_test_islandora_datastream_modified(FedoraObject $object, FedoraDatastream $datastream) { +function islandora_hooks_test_islandora_datastream_modified(AbstractObject $object, AbstractDatastream $datastream) { if ($object->id == 'test:testModifiedDatastreamHook' && $datastream->id == "TEST") { $_SESSION['islandora_hooks']['hook'][ISLANDORA_DATASTREAM_MODIFIED_HOOK] = TRUE; } @@ -145,7 +145,7 @@ function islandora_hooks_test_islandora_datastream_modified(FedoraObject $object /** * Implements hook_islandora_datastream_purged(). */ -function islandora_hooks_test_islandora_datastream_purged(FedoraObject $object, $dsid) { +function islandora_hooks_test_islandora_datastream_purged(AbstractObject $object, $dsid) { if ($object->id == 'test:testPurgedDatastreamHook' && $dsid == "TEST") { $_SESSION['islandora_hooks']['hook'][ISLANDORA_DATASTREAM_PURGED_HOOK] = TRUE; } From fc6f6b0f1d1b05528c20ac3967e3af774fe76e04 Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Wed, 8 May 2013 18:25:21 +0200 Subject: [PATCH 106/172] Ensure shared variable 'models' is always available in the ingest form. --- includes/ingest.form.inc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/includes/ingest.form.inc b/includes/ingest.form.inc index 0a9ce6e6..d82ccec4 100644 --- a/includes/ingest.form.inc +++ b/includes/ingest.form.inc @@ -80,6 +80,8 @@ function islandora_ingest_form_init_form_state_storage(array &$form_state, array } // No need to persist the 'objects' within the configuration. unset($configuration['objects']); + // Required for step hooks. + $configuration['models'] = isset($configuration['models']) ? $configuration['models'] : array(); $form_state['islandora'] = array( 'step_id' => NULL, 'objects' => $objects, From d6f3647421971ce92896372215f4446d33ce0e6b Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Thu, 9 May 2013 10:28:51 -0300 Subject: [PATCH 107/172] Minor bug fix. --- includes/ingest.form.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/ingest.form.inc b/includes/ingest.form.inc index d82ccec4..a2d5a833 100644 --- a/includes/ingest.form.inc +++ b/includes/ingest.form.inc @@ -625,7 +625,7 @@ function islandora_ingest_form_next_submit(array $form, array &$form_state) { */ function islandora_ingest_form_stash_info(array &$form_state) { $storage = &islandora_ingest_form_get_step_storage($form_state); - if ($storage) { + if ($storage && isset($form_state['values'])) { $storage['values'] = $form_state['values']; unset($form_state['values']); } From b561b0238b20c7ba49b6d49fbbf6fa13de3cd3da Mon Sep 17 00:00:00 2001 From: jonathangreen Date: Fri, 10 May 2013 18:06:02 -0300 Subject: [PATCH 108/172] Give fedora more time to startup --- tests/scripts/travis_setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/scripts/travis_setup.sh b/tests/scripts/travis_setup.sh index c3515198..7939215b 100755 --- a/tests/scripts/travis_setup.sh +++ b/tests/scripts/travis_setup.sh @@ -33,4 +33,4 @@ drush en --yes simpletest drush en --yes potx drush en --user=1 --yes islandora drush cc all -sleep 4 +sleep 20 From 12b705db8b37dcfa9dfca97710f28d7eb334e025 Mon Sep 17 00:00:00 2001 From: jonathangreen Date: Mon, 13 May 2013 11:07:21 -0300 Subject: [PATCH 109/172] Added some test functions. --- islandora.info | 2 +- ...t_case.inc => islandora_web_test_case.inc} | 76 +++++++++++++++++++ 2 files changed, 77 insertions(+), 1 deletion(-) rename tests/{web_test_case.inc => islandora_web_test_case.inc} (67%) diff --git a/islandora.info b/islandora.info index e44ec721..54f62c05 100644 --- a/islandora.info +++ b/islandora.info @@ -11,7 +11,7 @@ files[] = includes/dublin_core.inc files[] = includes/tuque.inc files[] = includes/tuque_wrapper.inc files[] = includes/object.entity_controller.inc -files[] = tests/web_test_case.inc +files[] = tests/islandora_web_test_case.inc files[] = tests/authtokens.test files[] = tests/hooks.test files[] = tests/islandora_manage_permissions.test diff --git a/tests/web_test_case.inc b/tests/islandora_web_test_case.inc similarity index 67% rename from tests/web_test_case.inc rename to tests/islandora_web_test_case.inc index 8a5b9a00..4571ad6c 100644 --- a/tests/web_test_case.inc +++ b/tests/islandora_web_test_case.inc @@ -126,4 +126,80 @@ class IslandoraWebTestCase extends DrupalWebTestCase { unset($this->configuration); parent::tearDown(); } + + /** + * Asserts that the given datastreams exist on the object. + * + * @param AbstractObject $objectpid + * The PID of the object + * @param array $datastreams + * An array of strings containing datastream names + */ + public function assertDatastreams($object, array $datastreams) { + if (!is_object($object)) { + $this->fail("Failed. Object passed in is invalid."); + return; + } + + foreach($datastreams as $datastream) { + if (isset($object[$datastream])) { + $this->pass("Loaded datastream {$datastream} from PID {$object->id}"); + } + else { + $this->fail("Failed to load datastream {$datastream} from PID {$object->id}"); + } + } + } + + /** + * Gets a tuque object from a path. + * + * @param string $path + * A full or partial path to an islandora object. + * + * @return AbstractObject + * The pid of the object or FALSE if a PID is not found. + */ + public function getPidFromPath($path) { + $path_parts = explode('/', $path); + $array_length = count($path_parts); + for ($i = 0; $i < $array_length; $i++) { + if ($path_parts[$i] == 'islandora' && isset($path_parts[$i+1]) && $path_parts[$i+1] == 'object') { + if (isset($path_parts[$i+2])) { + return islandora_object_load(urldecode($path_parts[$i+2])); + } + } + } + $this->fail("Failed to parse path : $path."); + return FALSE; + } + + /** + * Deletes an object using the PID. This does the deletion using the UI. + * + * @param string $pid + * The PID of the collection to be deleted + */ + public function deleteObject($pid) { + $current_user = $this->loggedInUser; + $user = $this->drupalCreateUser(array('manage object properties', 'delete fedora objects and datastreams', 'view fedora repository objects')); + + $this->drupalLogin($user); + + $path = 'islandora/object/' . $pid . '/manage/properties'; + $edit = array(); + $this->drupalPost($path, $edit, t('Delete')); + $this->drupalPost($this->url, $edit, t('Delete')); + $object = islandora_object_load($pid); + + $this->drupalGet("islandora/object/$pid"); + $this->assertResponse(404, "Object $pid successfully deleted."); + + if ($current_user) { + $this->drupalLogin($current_user); + } + else { + $this->drupalLogout(); + } + } } From aac7a738f961e0eb86fe9ba6f7b63386641ed269 Mon Sep 17 00:00:00 2001 From: jonathangreen Date: Mon, 13 May 2013 11:22:27 -0300 Subject: [PATCH 110/172] Fix some coding standards. --- tests/islandora_web_test_case.inc | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/islandora_web_test_case.inc b/tests/islandora_web_test_case.inc index 4571ad6c..8e3c8b83 100644 --- a/tests/islandora_web_test_case.inc +++ b/tests/islandora_web_test_case.inc @@ -130,7 +130,7 @@ class IslandoraWebTestCase extends DrupalWebTestCase { /** * Asserts that the given datastreams exist on the object. * - * @param AbstractObject $objectpid + * @param AbstractObject $object * The PID of the object * @param array $datastreams * An array of strings containing datastream names @@ -141,7 +141,7 @@ class IslandoraWebTestCase extends DrupalWebTestCase { return; } - foreach($datastreams as $datastream) { + foreach ($datastreams as $datastream) { if (isset($object[$datastream])) { $this->pass("Loaded datastream {$datastream} from PID {$object->id}"); } @@ -164,9 +164,9 @@ class IslandoraWebTestCase extends DrupalWebTestCase { $path_parts = explode('/', $path); $array_length = count($path_parts); for ($i = 0; $i < $array_length; $i++) { - if ($path_parts[$i] == 'islandora' && isset($path_parts[$i+1]) && $path_parts[$i+1] == 'object') { - if (isset($path_parts[$i+2])) { - return islandora_object_load(urldecode($path_parts[$i+2])); + if ($path_parts[$i] == 'islandora' && isset($path_parts[$i + 1]) && $path_parts[$i + 1] == 'object') { + if (isset($path_parts[$i + 2])) { + return islandora_object_load(urldecode($path_parts[$i + 2])); } } } @@ -182,7 +182,11 @@ class IslandoraWebTestCase extends DrupalWebTestCase { */ public function deleteObject($pid) { $current_user = $this->loggedInUser; - $user = $this->drupalCreateUser(array('manage object properties', 'delete fedora objects and datastreams', 'view fedora repository objects')); + $user = $this->drupalCreateUser(array( + 'manage object properties', + 'delete fedora objects and datastreams', + 'view fedora repository objects', + )); $this->drupalLogin($user); From a825b0dedd6a427bab8663fdba4b143b6e93adfa Mon Sep 17 00:00:00 2001 From: jonathangreen Date: Tue, 14 May 2013 10:39:53 -0300 Subject: [PATCH 111/172] Renamed test case function --- tests/islandora_web_test_case.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/islandora_web_test_case.inc b/tests/islandora_web_test_case.inc index 8e3c8b83..a5117695 100644 --- a/tests/islandora_web_test_case.inc +++ b/tests/islandora_web_test_case.inc @@ -160,7 +160,7 @@ class IslandoraWebTestCase extends DrupalWebTestCase { * @return AbstractObject * The pid of the object or FALSE if a PID is not found. */ - public function getPidFromPath($path) { + public function getObjectFromPath($path) { $path_parts = explode('/', $path); $array_length = count($path_parts); for ($i = 0; $i < $array_length; $i++) { From 7f8e9ff0a3932f8439b33c7f94cbdfa56dd6fa70 Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Wed, 15 May 2013 14:49:37 +0200 Subject: [PATCH 112/172] Moving backwards though the form now brings the user to the expected step. There was a mistake where a step was reverting its global changes before it was actually selected as the previous step. Innocuous enough but it had strange side effects on the global storage, since the step list would be rebuild with this information, steps could insert themselves as previous steps even if they weren't used by the user. --- includes/ingest.form.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/ingest.form.inc b/includes/ingest.form.inc index a2d5a833..2312273b 100644 --- a/includes/ingest.form.inc +++ b/includes/ingest.form.inc @@ -534,7 +534,7 @@ function islandora_ingest_form_previous_button(array &$form_state) { $prev_form_step = islandora_ingest_form_get_previous_form_step($form_state); $form_id = $prev_form_step['form_id']; $submit_callback = $form_id . '_undo_submit'; - $submit = function_exists($submit_callback) ? array($submit_callback, 'islandora_ingest_form_previous_submit') : array('islandora_ingest_form_previous_submit'); + $submit = function_exists($submit_callback) ? array('islandora_ingest_form_previous_submit', $submit_callback) : array('islandora_ingest_form_previous_submit'); return array( '#type' => 'submit', '#value' => t('Previous'), @@ -731,7 +731,7 @@ function &islandora_ingest_form_get_objects(array &$form_state) { */ function islandora_ingest_form_get_object(array &$form_state) { $objects = &islandora_ingest_form_get_objects($form_state); - return current($objects); + return reset($objects); } /** From 2f41b947cd1a0c23c5a4c029f7ec418bca5f53df Mon Sep 17 00:00:00 2001 From: Jonathan Green Date: Wed, 15 May 2013 12:16:42 -0300 Subject: [PATCH 113/172] Update README.md --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0515a848..69059953 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,11 @@ https://jira.duraspace.org/browse/ISLANDORA REQUIREMENTS ------------ - +The Tuque library must be installed to use Islandora. It can be found here: +http://github.com/Islandora/tuque +It is expected to be in one of two paths: +sites/all/libraries/tuque (libraries directory may need to be created) +islandora_folder/libraries/tuque INSTALLATION ------------ From d3f503c0ed1ee05e430275f04ccbc8cb5f49eae0 Mon Sep 17 00:00:00 2001 From: Jonathan Green Date: Wed, 15 May 2013 12:17:53 -0300 Subject: [PATCH 114/172] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 69059953..798e6b33 100644 --- a/README.md +++ b/README.md @@ -26,8 +26,8 @@ REQUIREMENTS The Tuque library must be installed to use Islandora. It can be found here: http://github.com/Islandora/tuque It is expected to be in one of two paths: -sites/all/libraries/tuque (libraries directory may need to be created) -islandora_folder/libraries/tuque + - sites/all/libraries/tuque (libraries directory may need to be created) + - islandora_folder/libraries/tuque INSTALLATION ------------ From 2a5210278fe392887277ab82fc68817217a4e38e Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Wed, 15 May 2013 13:15:54 -0300 Subject: [PATCH 115/172] Fix the "TIFF" mimetype. Was causing issues in the batch importer. --- includes/mime_detect.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/mime_detect.inc b/includes/mime_detect.inc index 0914f62b..386bbf94 100644 --- a/includes/mime_detect.inc +++ b/includes/mime_detect.inc @@ -148,7 +148,7 @@ class MimeDetect { "jp2" => "image/jp2", "png" => "image/png", "tiff" => "image/tiff", - "tif" => "image/tif", + "tif" => "image/tiff", "djvu" => "image/vnd.djvu", "djv" => "image/vnd.djvu", "wbmp" => "image/vnd.wap.wbmp", From c4f97e2632dc88dab08f4e799eb78dcd88ff9877 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Wed, 15 May 2013 14:33:58 -0300 Subject: [PATCH 116/172] Add handling of deprecated 'image/tif' mimetype when determining an extension. --- includes/mime_detect.inc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/includes/mime_detect.inc b/includes/mime_detect.inc index 386bbf94..d6998008 100644 --- a/includes/mime_detect.inc +++ b/includes/mime_detect.inc @@ -194,6 +194,11 @@ class MimeDetect { 'bin' => 'application/octet-stream', ); protected $protectedFileExtensions; + protected $extensionExceptions = array( + // XXX: Deprecated... Only here due to old 'tif' => 'image/tif' mapping... + // The correct MIMEtype is 'image/tiff'. + 'image/tif' => 'tif', + ); protected $systemTypes; protected $systemExts; protected $etcMimeTypes = '/etc/mime.types'; @@ -205,6 +210,7 @@ class MimeDetect { // Populate the reverse shortlist: $this->protectedFileExtensions = array_flip($this->protectedMimeTypes); + $this->protectedFileExtensions += $this->extensionExceptions; // Pick up a local mime.types file if it is available. if (is_readable('mime.types')) { From 740720124d2899f8f9eca45bca330ac5d38b656a Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Wed, 15 May 2013 20:47:28 +0200 Subject: [PATCH 117/172] Make sure the provided models actually exist. --- includes/ingest.form.inc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/includes/ingest.form.inc b/includes/ingest.form.inc index 2312273b..62658acd 100644 --- a/includes/ingest.form.inc +++ b/includes/ingest.form.inc @@ -78,6 +78,12 @@ function islandora_ingest_form_init_form_state_storage(array &$form_state, array if (empty($objects)) { $objects[] = islandora_ingest_form_prepare_new_object($configuration); } + // Make sure the models actually exist + foreach ($configuration['models'] as $key => $model) { + if (!islandora_object_load($model)) { + unset($configuration['models'][$key]); + } + } // No need to persist the 'objects' within the configuration. unset($configuration['objects']); // Required for step hooks. From 334221feaa1cb774e4a161f48307408642ed0ee5 Mon Sep 17 00:00:00 2001 From: jonathangreen Date: Wed, 15 May 2013 15:56:59 -0300 Subject: [PATCH 118/172] Removed drush script. --- islandora.drush.inc | 40 ---------------------------------------- 1 file changed, 40 deletions(-) delete mode 100644 islandora.drush.inc diff --git a/islandora.drush.inc b/islandora.drush.inc deleted file mode 100644 index e83ba046..00000000 --- a/islandora.drush.inc +++ /dev/null @@ -1,40 +0,0 @@ - array( - 'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_ROOT, - 'description' => dt('Corrects the type hinting for function parameters that reference non-abstract Tuque objects. Converts to a more generic form of AbstractObject. Be warned this will modify the source code in your site!'), - ), - ); -} - -/** - * Drush command callback. - * - * Corrects the type hinting in parameters such that they only use AbstractObject. - */ -function drush_islandora_correct_type_hinting() { - drush_print(dt('This will modify source code within your Drupal site. This can not be reversed.')); - if (!drush_confirm(dt('Do you really want to continue?'))) { - return drush_user_abort(); - } - // Only change files within modules directories and only modify php files. - $ret = -1; - passthru('find . -regex ".*\.\(php\|inc\|test\|module\|install\)" -path "*/modules/*" | xargs perl -pi -e "s/(\(.*)(AbstractFedoraObject|FedoraObject|NewFedoraObject|IslandoraFedoraObject|IslandoraNewFedoraObject)( .*\))/\1AbstractObject\3/g"', $ret); - passthru('find . -regex ".*\.\(php\|inc\|test\|module\|install\)" -path "*/modules/*" | xargs perl -pi -e "s/(\(.*)(AbstractFedoraDatastream|AbstractExistingFedoraDatastream|FedoraDatastream|NewFedoraDatastream|FedoraDatastreamVersion|IslandoraNewFedoraDatastream|IslandoraFedoraDatastream|IslandoraFedoraDatastreamVersion)( .*\))/\1AbstractDatastream\3/g"', $ret); -} - -function drush_islandora_correct_type_hinting_validate() { - if (drush_is_windows()) { - drush_set_error(dt("Sorry but this hasn't been implemented for Windows, it only works on unix systems.")); - } -} From 33d8911b69ae5e4227e22504cbceb6fe9afd4f90 Mon Sep 17 00:00:00 2001 From: Jonathan Green Date: Wed, 15 May 2013 19:35:05 +0000 Subject: [PATCH 119/172] Attempt to fix travis --- includes/ingest.form.inc | 2 +- tests/scripts/travis_setup.sh | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/includes/ingest.form.inc b/includes/ingest.form.inc index a2d5a833..c9a615ce 100644 --- a/includes/ingest.form.inc +++ b/includes/ingest.form.inc @@ -78,7 +78,7 @@ function islandora_ingest_form_init_form_state_storage(array &$form_state, array if (empty($objects)) { $objects[] = islandora_ingest_form_prepare_new_object($configuration); } - // No need to persist the 'objects' within the configuration. + // No need to persist the objects within the configuration. unset($configuration['objects']); // Required for step hooks. $configuration['models'] = isset($configuration['models']) ? $configuration['models'] : array(); diff --git a/tests/scripts/travis_setup.sh b/tests/scripts/travis_setup.sh index 7939215b..354e4d6b 100755 --- a/tests/scripts/travis_setup.sh +++ b/tests/scripts/travis_setup.sh @@ -11,12 +11,11 @@ cd islandora_tomcat export CATALINA_HOME='.' ./bin/startup.sh cd $HOME -pyrus channel-discover pear.drush.org -pyrus channel-discover pear.phpqatools.org -pyrus channel-discover pear.netpirates.net -pyrus install drush/drush -pyrus install pear/PHP_CodeSniffer -pyrus install pear.phpunit.de/phpcpd +pear channel-discover pear.phpqatools.org +pear channel-discover pear.netpirates.net +pear install pear/PHP_CodeSniffer +pear install pear.phpunit.de/phpcpd +sudo apt-get install -qq drush phpenv rehash drush dl --yes drupal cd drupal-* From 522cac6e7172097c6359361f7901b0a067d2bacd Mon Sep 17 00:00:00 2001 From: jonathangreen Date: Wed, 15 May 2013 21:48:34 -0300 Subject: [PATCH 120/172] Another attempt to appease the travis gods. --- tests/scripts/travis_setup.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/scripts/travis_setup.sh b/tests/scripts/travis_setup.sh index 354e4d6b..dab4508f 100755 --- a/tests/scripts/travis_setup.sh +++ b/tests/scripts/travis_setup.sh @@ -11,11 +11,12 @@ cd islandora_tomcat export CATALINA_HOME='.' ./bin/startup.sh cd $HOME +pear update pear pear channel-discover pear.phpqatools.org pear channel-discover pear.netpirates.net pear install pear/PHP_CodeSniffer pear install pear.phpunit.de/phpcpd -sudo apt-get install -qq drush +pear install drush/drush phpenv rehash drush dl --yes drupal cd drupal-* From 1533de776e6c3d1e40d2a7120baa671730bc0dc8 Mon Sep 17 00:00:00 2001 From: jonathangreen Date: Wed, 15 May 2013 21:59:32 -0300 Subject: [PATCH 121/172] Yet another attempt to appease the travis gods. --- includes/ingest.form.inc | 2 +- tests/scripts/travis_setup.sh | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/includes/ingest.form.inc b/includes/ingest.form.inc index 62658acd..3ef3f847 100644 --- a/includes/ingest.form.inc +++ b/includes/ingest.form.inc @@ -78,7 +78,7 @@ function islandora_ingest_form_init_form_state_storage(array &$form_state, array if (empty($objects)) { $objects[] = islandora_ingest_form_prepare_new_object($configuration); } - // Make sure the models actually exist + // Make sure the models actually exist. foreach ($configuration['models'] as $key => $model) { if (!islandora_object_load($model)) { unset($configuration['models'][$key]); diff --git a/tests/scripts/travis_setup.sh b/tests/scripts/travis_setup.sh index dab4508f..45dc3ab9 100755 --- a/tests/scripts/travis_setup.sh +++ b/tests/scripts/travis_setup.sh @@ -11,7 +11,11 @@ cd islandora_tomcat export CATALINA_HOME='.' ./bin/startup.sh cd $HOME -pear update pear +pear upgrade –force Console_Getopt +pear upgrade –force pear +pear upgrade-all +pear channel-discover pear.drush.org +pear channel-discover pear.drush.org pear channel-discover pear.phpqatools.org pear channel-discover pear.netpirates.net pear install pear/PHP_CodeSniffer From 59f8744a4317dbe4f7ce7cdecd209ea0f720e1f2 Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Thu, 23 May 2013 05:03:23 +0200 Subject: [PATCH 122/172] Added new function islandora_copy_object() can copy existing/new fedora objects. It's a bit leaky in that it makes assumptions about the members that will exist on AbstractObjects, but we can't make cloning work at the moment as it doesn't really work well with inheritance, every decendent would have to define __clone functions properly and I figured a wrapper function like this would be easier to support in the long term, until we make the movement to decorated objects. --- islandora.module | 57 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/islandora.module b/islandora.module index 79672625..df17e65f 100644 --- a/islandora.module +++ b/islandora.module @@ -951,6 +951,63 @@ function islandora_add_object(AbstractObject &$object) { return $object->repository->ingestObject($object); } +/** + * Creates a new object with the same properties as the old. + * + * @todo Make Tuque objects support cloneing. + * + * @param AbstractObject $object + * An existing or new Fedora Object. + * + * @return AbstractObject + * The new Fedora Object with properties identical to the object given. This + * returned object is not automatically ingested. + */ +function islandora_copy_object(AbstractObject $object) { + $clone = $object->repository->constructObject($object->id); + $object_properties = array( + 'state', + 'createdDate', + 'lastModifiedDate', + 'label', + 'owner', + 'logMessage', + ); + // Copy Properties. + foreach ($object_properties as $property) { + if (isset($object->$property)) { + $clone->$property = $object->$property; + } + } + $datastream_properties = array( + 'label', + 'versionable', + 'state', + 'mimetype', + 'format', + 'size', + 'checksum', + 'checksumType', + 'createdDate', + 'content', + 'url', + 'location', + ); + // Copy Datastreams. + foreach ($object as $dsid => $datastream) { + if (empty($clone[$dsid])) { + $ds = $clone->constructDatastream($dsid, $datastream->controlGroup); + $clone->ingestDatastream($ds); + } + foreach ($datastream_properties as $property) { + if (isset($object[$dsid]->$property)) { + $clone[$dsid]->$property = $object[$dsid]->$property; + } + } + } + return $clone; +} + /** * Delete's or purges the given object. * From 7c72ee10a2605c3d275d96e135c1c56ca6ab9863 Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Mon, 27 May 2013 14:42:54 -0300 Subject: [PATCH 123/172] Include an autocomplete path for content models that used to live in islandora_xml_forms. --- includes/content_model.autocomplete.inc | 73 +++++++++++++++++++++++++ islandora.module | 12 ++++ 2 files changed, 85 insertions(+) create mode 100644 includes/content_model.autocomplete.inc diff --git a/includes/content_model.autocomplete.inc b/includes/content_model.autocomplete.inc new file mode 100644 index 00000000..2392ab2e --- /dev/null +++ b/includes/content_model.autocomplete.inc @@ -0,0 +1,73 @@ + $label) { + if (preg_match("/{$string}/i", $label) !== 0) { + $output[$model] = $label; + } + } + return drupal_json_output($output); +} + +/** + * Gets a map of form names suitable for use as select #options. + */ +function islandora_get_content_model_names() { + $results = islandora_query_content_models(); + $ret = array(); + foreach ($results as $result) { + $ret[$result['model']['value']] = "{$result['label']['value']} ({$result['model']['value']})"; + } + return $ret; +} + +/** + * Perform a resource index query to determine get a list of content models. + * + * Only returns content models with at least one subscribing object. + * + * @return array + * An array of RI results, as given by the Tuque RI query interface. + */ +function islandora_query_content_models() { + $connection = islandora_get_tuque_connection(); + if ($connection) { + $query = 'select $model $label from <#ri> where + $model and $model $label + minus $model + minus $model + minus $model + minus $model '; + $results = $connection->repository->ri->itqlQuery($query); + return $results; + } + return array(); +} + +/** + * Minor array transformation. + * + * @param array $content + * The array of results as returned from Tuque's RI query interface. + * @return array + * An array of results in a more usable format. + */ +function islandora_parse_query($content) { + $content_models = array(); + foreach ($content as $model) { + $content_models[] = $model['object']['value']; + } + $content_models = array_unique($content_models); + $content_models = array_values($content_models); + return $content_models; +} diff --git a/islandora.module b/islandora.module index 79672625..974d526e 100644 --- a/islandora.module +++ b/islandora.module @@ -52,6 +52,9 @@ define('ISLANDORA_DATASTREAM_MODIFIED_HOOK', 'islandora_datastream_modified'); define('ISLANDORA_DATASTREAM_PURGED_HOOK', 'islandora_datastream_purged'); define('ISLANDORA_INGEST_STEP_HOOK', 'islandora_ingest_steps'); +// Autocomplete paths. +define('ISLANDORA_CONTENT_MODELS_AUTOCOMPLETE', 'islandora/autocomplete/content-models'); + /** * Implements hook_menu(). * @@ -246,6 +249,15 @@ function islandora_menu() { 'access arguments' => array(FEDORA_VIEW_OBJECTS, 2), 'load arguments' => array(2), ); + $items[ISLANDORA_CONTENT_MODELS_AUTOCOMPLETE] = array( + 'title' => 'Autocomplete callback', + 'description' => 'Autocomplete a Fedora content model PID.', + 'file' => 'includes/content_model.autocomplete.inc', + 'page callback' => 'islandora_content_model_autocomplete', + 'page arguments' => array(3), + 'access arguments' => array('administer site configuration'), + 'type' => MENU_CALLBACK, + ); return $items; } From 95e5994770c6ca51d2a3cf2e55ae66ddf39a9995 Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Mon, 27 May 2013 14:54:49 -0300 Subject: [PATCH 124/172] Copypasta standards fail. --- includes/content_model.autocomplete.inc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/includes/content_model.autocomplete.inc b/includes/content_model.autocomplete.inc index 2392ab2e..c6fd34df 100644 --- a/includes/content_model.autocomplete.inc +++ b/includes/content_model.autocomplete.inc @@ -1,10 +1,15 @@ Date: Wed, 29 May 2013 13:07:21 -0300 Subject: [PATCH 125/172] Fix the deprecation message. --- includes/ingest.form.inc | 4 ++-- includes/utilities.inc | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/ingest.form.inc b/includes/ingest.form.inc index 3ef3f847..b03e7aca 100644 --- a/includes/ingest.form.inc +++ b/includes/ingest.form.inc @@ -142,8 +142,8 @@ function islandora_ingest_form_get_last_step_id(array &$form_state) { function islandora_ingest_form_prepare_new_object(array $configuration) { module_load_include('inc', 'islandora', 'includes/utilities'); if (empty($configuration['object'])) { - $message = islandora_deprecated('Please use "objects" as the default ingest form configuration property.'); - trigger_error(check_plain($message), E_USER_DEPRECATED); + $message = islandora_deprecated('7.x-1.2', t('Please use "objects" as the default ingest form configuration property.')); + trigger_error(filter_xss($message), E_USER_DEPRECATED); // ID is more specific than namespace so it will take precedence. $id = isset($configuration['namespace']) ? $configuration['namespace'] : 'islandora'; $id = isset($configuration['id']) ? $configuration['id'] : $id; diff --git a/includes/utilities.inc b/includes/utilities.inc index 3cbe2a06..424e7d07 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -825,7 +825,7 @@ function islandora_content_model_select_table_form_element($drupal_variable, $de * * @code * $message = islandora_deprecated('7.x-1.1', t('Use more cowbell.')) - * trigger_error(check_plain($message), E_USER_DEPRECATED) + * trigger_error(filter_xss($message), E_USER_DEPRECATED) * @endcode * * @param string $release From 992c42b96f1faed5fc48eb1dd8680537b1f05831 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Wed, 29 May 2013 13:09:33 -0300 Subject: [PATCH 126/172] Add semi-colons, so the code's actual code... --- includes/utilities.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/utilities.inc b/includes/utilities.inc index 424e7d07..5184ca21 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -824,8 +824,8 @@ function islandora_content_model_select_table_form_element($drupal_variable, $de * To utilitize this function pass the results to trigger_error() like so: * * @code - * $message = islandora_deprecated('7.x-1.1', t('Use more cowbell.')) - * trigger_error(filter_xss($message), E_USER_DEPRECATED) + * $message = islandora_deprecated('7.x-1.1', t('Use more cowbell.')); + * trigger_error(filter_xss($message), E_USER_DEPRECATED); * @endcode * * @param string $release From 2ce695a9f033eb56b10f994fd2b6338bf6cdcd08 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Wed, 29 May 2013 13:10:10 -0300 Subject: [PATCH 127/172] Add deprecation message to the superfluous DS-COMPOSITE-MODEL parser. --- includes/utilities.inc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/includes/utilities.inc b/includes/utilities.inc index 5184ca21..6a8fb584 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -636,6 +636,9 @@ function islandora_system_settings_form_default_value($name, $default_value, arr * is optional. */ function islandora_get_comp_ds_mappings($pid) { + $message = islandora_deprecated('7.x-1.2', t('Refactor to use the more flexible islandora_get_datastreams_requirements_from_content_model().')); + trigger_error(filter_xss($message), E_USER_DEPRECATED); + $cm_object = islandora_object_load($pid); if (!isset($cm_object) || !isset($cm_object['DS-COMPOSITE-MODEL'])) { return FALSE; From 80a187bab9e405c22c9c9bc8df7fccb0347b0285 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Wed, 29 May 2013 14:04:49 -0300 Subject: [PATCH 128/172] Revert "Add semi-colons, so the code's actual code..." This reverts commit 992c42b96f1faed5fc48eb1dd8680537b1f05831... ... Apparently, the "production" code review has a bit of a bug in it, where it doesn't parse @code/@endcode sections properly: http://drupal.org/node/1991382 --- includes/utilities.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/utilities.inc b/includes/utilities.inc index 6a8fb584..cdbf8daa 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -827,8 +827,8 @@ function islandora_content_model_select_table_form_element($drupal_variable, $de * To utilitize this function pass the results to trigger_error() like so: * * @code - * $message = islandora_deprecated('7.x-1.1', t('Use more cowbell.')); - * trigger_error(filter_xss($message), E_USER_DEPRECATED); + * $message = islandora_deprecated('7.x-1.1', t('Use more cowbell.')) + * trigger_error(filter_xss($message), E_USER_DEPRECATED) * @endcode * * @param string $release From 722e4f1cad3cddf8b1db444f32c120f68e34b935 Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Thu, 30 May 2013 01:41:45 +0200 Subject: [PATCH 129/172] Integration tests for ingest steps plus some fixes. Tests ingest forms by using a shared variable 'models'. Additional stuff: 'models' is no longer a required config for ingest steps, now its set from the given objects. No longer need to rebuild steps from within a form step when the shared_storage gets changed, we now detect if changes have been made then we rebuild if necessary. Fixed POST requests in WebTestCases previously the user was always anonymous so interactions with fedora would fail via post requests. --- includes/ingest.form.inc | 14 ++- islandora.info | 1 + tests/ingest.test | 117 ++++++++++++++++++++ tests/islandora_ingest_test.info | 7 ++ tests/islandora_ingest_test.module | 166 +++++++++++++++++++++++++++++ tests/islandora_web_test_case.inc | 21 ++-- 6 files changed, 317 insertions(+), 9 deletions(-) create mode 100644 tests/ingest.test create mode 100644 tests/islandora_ingest_test.info create mode 100644 tests/islandora_ingest_test.module diff --git a/includes/ingest.form.inc b/includes/ingest.form.inc index 3ef3f847..943202ce 100644 --- a/includes/ingest.form.inc +++ b/includes/ingest.form.inc @@ -78,6 +78,7 @@ function islandora_ingest_form_init_form_state_storage(array &$form_state, array if (empty($objects)) { $objects[] = islandora_ingest_form_prepare_new_object($configuration); } + $configuration['models'] = isset($configuration['models']) ? $configuration['models'] : array(); // Make sure the models actually exist. foreach ($configuration['models'] as $key => $model) { if (!islandora_object_load($model)) { @@ -87,7 +88,6 @@ function islandora_ingest_form_init_form_state_storage(array &$form_state, array // No need to persist the 'objects' within the configuration. unset($configuration['objects']); // Required for step hooks. - $configuration['models'] = isset($configuration['models']) ? $configuration['models'] : array(); $form_state['islandora'] = array( 'step_id' => NULL, 'objects' => $objects, @@ -370,7 +370,15 @@ function islandora_ingest_form_execute_step(array $form, array &$form_state, $st function islandora_ingest_form_execute_form_step(array $form, array &$form_state, array $step) { $args = array($form, &$form_state); $args = isset($step['args']) ? array_merge($args, $step['args']) : $args; + $shared_storage = islandora_ingest_form_get_shared_storage($form_state); + // Build the form step. $form = call_user_func_array($step['form_id'], $args); + // Since the list of steps depends on the shared storage we will rebuild the + // list of steps if the shared storage has changed. This must be done before + // stepifying, so the prev/next buttons get updated. + if ($shared_storage != islandora_ingest_form_get_shared_storage($form_state)) { + drupal_static_reset('islandora_ingest_form_get_steps'); + } return islandora_ingest_form_stepify($form, $form_state, $step); } @@ -456,6 +464,10 @@ function islandora_ingest_form_undo_callback_step(array $form, array &$form_stat function islandora_ingest_form_stepify(array $form, array &$form_state, $step) { $first_form_step = islandora_ingest_form_on_first_form_step($form_state); $last_form_step = islandora_ingest_form_on_last_form_step($form_state); + $form['form_step_id'] = array( + '#type' => 'hidden', + '#value' => islandora_ingest_form_get_current_step_id($form_state), + ); $form['prev'] = $first_form_step ? NULL : islandora_ingest_form_previous_button($form_state); $form['next'] = $last_form_step ? islandora_ingest_form_ingest_button($form_state) : islandora_ingest_form_next_button($form_state); // Allow for a hook_form_FORM_ID_alter(). diff --git a/islandora.info b/islandora.info index 54f62c05..4f6a5858 100644 --- a/islandora.info +++ b/islandora.info @@ -14,5 +14,6 @@ files[] = includes/object.entity_controller.inc files[] = tests/islandora_web_test_case.inc files[] = tests/authtokens.test files[] = tests/hooks.test +files[] = tests/ingest.test files[] = tests/islandora_manage_permissions.test php = 5.3 diff --git a/tests/ingest.test b/tests/ingest.test new file mode 100644 index 00000000..0878076b --- /dev/null +++ b/tests/ingest.test @@ -0,0 +1,117 @@ + 'Islandora Ingestion', + 'description' => 'Ensure that the ingest forms function correctly.', + 'group' => 'Islandora', + ); + } + + /** + * Creates an admin user and a connection to a fedora repository. + * + * @see IslandoraWebTestCase::setUp() + */ + public function setUp() { + parent::setUp('islandora_ingest_test'); + $this->repository = $this->admin->repository; + $this->purgeTestObjects(); + + } + + /** + * Free any objects/resources created for this test. + * + * @see IslandoraWebTestCase::tearDown() + */ + public function tearDown() { + $this->purgeTestObjects(); + unset($this->repository); + parent::tearDown(); + } + + /** + * Purge any objects created by the test's in this class. + */ + public function purgeTestObjects() { + $objects = array( + 'test:test', + ); + foreach ($objects as $object) { + try { + $object = $this->repository->getObject($object); + $this->repository->purgeObject($object->id); + } + catch (Exception $e) { + // Meh... Either it didn't exist or the purge failed. + } + } + } + + /** + * Test Ingest Steps. + */ + public function testIngest() { + global $user; + // First step in form. + $this->drupalGet('test/ingest'); + // Default model selected, has no additional steps. + $this->assertFieldByName('ingest', 'Ingest'); + // Select a model with additional steps. + $edit = array( + 'model' => 'test:testcmodel', + ); + $this->drupalPostAJAX(NULL, $edit, 'model'); + // Form now reflexts multiple steps. + $this->assertFieldByName('label', ''); + $this->assertFieldByName('next', 'Next'); + // Move to next step. + $edit = array( + 'label' => 'foobar', + 'model' => 'test:testcmodel', + ); + $this->drupalPost(NULL, $edit, t('Next')); + $this->assertFieldByName('form_step_id', 'islandora_ingest_test_testcmodel'); + $this->assertFieldByName('ingest', 'Ingest'); + // Move back to first step. + $this->drupalPost(NULL, array(), t('Previous')); + // Try a different model that has an additional step. + $edit = array( + 'model' => 'test:testcmodel2', + ); + $this->drupalPostAJAX(NULL, $edit, 'model'); + $edit = array( + 'label' => 'foobar', + 'model' => 'test:testcmodel2', + ); + $this->drupalPost(NULL, $edit, t('Next')); + $this->assertFieldByName('form_step_id', 'islandora_ingest_test_testcmodel2'); + $this->assertFieldByName('ingest', 'Ingest'); + // Ingest the thing. + $this->drupalPost(NULL, array(), t('Ingest')); + // Test that the thing got made. + $object = islandora_object_load('test:test'); + $this->assertEqual($object->label, 'foobar', 'Ingest Object matches submitted form values.'); + $this->assertEqual($object->models, array('test:testcmodel2', 'fedora-system:FedoraObject-3.0'), 'Ingest Object matches submitted form values.'); + } + +} diff --git a/tests/islandora_ingest_test.info b/tests/islandora_ingest_test.info new file mode 100644 index 00000000..974a60f2 --- /dev/null +++ b/tests/islandora_ingest_test.info @@ -0,0 +1,7 @@ +name = Islandora Testing +description = Required for testing islandora web-test case. +core = 7.x +package = Testing +hidden = TRUE +dependencies[] = islandora +files[] = islandora_test.module diff --git a/tests/islandora_ingest_test.module b/tests/islandora_ingest_test.module new file mode 100644 index 00000000..d414c717 --- /dev/null +++ b/tests/islandora_ingest_test.module @@ -0,0 +1,166 @@ + array( + 'title' => 'Ingest Form', + 'page callback' => 'islandora_ingest_test_ingest', + 'type' => MENU_LOCAL_ACTION, + 'access callback' => TRUE, + ), + ); +} + +/** + * Render the ingest form. + */ +function islandora_ingest_test_ingest() { + $connection = islandora_get_tuque_connection(); + $object = $connection->repository->constructObject('test:test'); + $object->label = 'New Object'; + $configuration = array( + 'objects' => array($object), + ); + module_load_include('inc', 'islandora', 'includes/ingest.form'); + return drupal_get_form('islandora_ingest_form', $configuration); +} + +/** + * Implements hook_islandora_ingest_steps(). + */ +function islandora_ingest_test_islandora_ingest_steps(array &$form_state) { + return array( + 'islandora_ingest_test' => array( + 'type' => 'form', + 'form_id' => 'islandora_ingest_test_set_label_form', + 'weight' => -50, + 'module' => 'islandora_ingest_test', + ), + ); +} + +/** + * Implements hook_MODEL_PID_islandora_ingest_steps(). + */ +function islandora_ingest_test_test_testcmodel_islandora_ingest_steps(array &$form_state) { + return array( + 'islandora_ingest_test_testcmodel' => array( + 'type' => 'form', + 'form_id' => 'islandora_ingest_test_testcmodel_form', + 'weight' => -30, + 'module' => 'islandora_ingest_test', + ), + ); +} + +/** + * Implements hook_MODEL_PID_islandora_ingest_steps(). + */ +function islandora_ingest_test_test_testcmodel2_islandora_ingest_steps(array &$form_state) { + return array( + 'islandora_ingest_test_testcmodel2' => array( + 'type' => 'form', + 'form_id' => 'islandora_ingest_test_testcmodel2_form', + 'weight' => -40, + 'module' => 'islandora_ingest_test', + ), + ); +} + +/** + * Sets the label of the ingestable object. + * + * @param array $form + * The Drupal form. + * @param array $form_state + * The Drupal form state. + * + * @return array + * The Drupal form definition. + */ +function islandora_ingest_test_set_label_form(array $form, array &$form_state) { + $models = array('test:nomorestepscmodel', 'test:testcmodel', 'test:testcmodel2'); + $model = isset($form_state['values']['model']) ? $form_state['values']['model'] : reset($models); + $shared_storage = &islandora_ingest_form_get_shared_storage($form_state); + $shared_storage['models'] = array($model); + return array( + '#prefix' => '
', + '#suffix' => '
', + 'label' => array( + '#type' => 'textfield', + '#title' => t('Label'), + ), + 'model' => array( + '#type' => 'select', + '#title' => t('Select a Content Model to Ingest'), + '#options' => array_combine($models, $models), + '#default' => $model, + '#ajax' => array( + 'callback' => 'islandora_ingest_test_model_ajax_callback', + 'wrapper' => 'islandora-select-content-model-wrapper', + 'method' => 'replace', + 'effect' => 'fade', + ), + ), + ); +} + +/** + * Updates the model field. + */ +function islandora_ingest_test_model_ajax_callback(array $form, array &$form_state) { + return $form; +} + +/** + * Sets the label of the ingestable object. + * + * @param array $form + * The Drupal form. + * @param array $form_state + * The Drupal form state. + */ +function islandora_ingest_test_set_label_form_submit(array $form, array &$form_state) { + $object = islandora_ingest_form_get_object($form_state); + $object->label = $form_state['values']['label']; + unset($object->models); + $object->models = array($form_state['values']['model']); +} + +/** + * Test the First content model. + */ +function islandora_ingest_test_testcmodel_form(array $form, array &$form_state) { + return array( + ); +} + +/** + * Test the CModel submit. + */ +function islandora_ingest_test_testcmodel_form_submit(array $form, array &$form_state) { + +} + +/** + * Test the second content model. + */ +function islandora_ingest_test_testcmodel2_form(array $form, array &$form_state) { + return array( + ); +} + +/** + * Test the CModel submit. + */ +function islandora_ingest_test_testcmodel2_form_submit(array $form, array &$form_state) { + +} diff --git a/tests/islandora_web_test_case.inc b/tests/islandora_web_test_case.inc index a5117695..2967280d 100644 --- a/tests/islandora_web_test_case.inc +++ b/tests/islandora_web_test_case.inc @@ -28,7 +28,7 @@ class IslandoraWebTestCase extends DrupalWebTestCase { $this->backUpDrupalFilter(); $this->setUpDrupalFilter(); } - $this->createAdminUser(); + $this->admin = $this->createAdminUser(); } /** @@ -90,15 +90,20 @@ class IslandoraWebTestCase extends DrupalWebTestCase { * Creates the a full fedora admin user with a repository connection. */ protected function createAdminUser() { - $this->admin = new stdClass(); - $this->admin->uid = 1; - $this->admin->name = $this->configuration['admin_user']; - $this->admin->pass = $this->configuration['admin_pass']; + $roles = user_roles(); + $index = array_search('administrator', $roles); + $user = $this->drupalCreateUser(); + $this->drupalLogin($user); + $user->roles[$index] = 'administrator'; + $user->name = $this->configuration['admin_user']; + $user->pass = $this->configuration['admin_pass']; + $user = user_save($user); $url = variable_get('islandora_base_url', $this->configuration['fedora_url']); - $connection = islandora_get_tuque_connection($this->admin, $url); - $this->admin->repository = $connection->repository; - return $this->admin; + $connection = islandora_get_tuque_connection($user, $url); + $user->repository = $connection->repository; + return $user; } + /** * Stores the content of the Drupal Filter for later restoration. */ From 6424a97495323e120811c29c61dc432becafd7bd Mon Sep 17 00:00:00 2001 From: Nelson Hart Date: Fri, 31 May 2013 15:11:56 -0300 Subject: [PATCH 130/172] include islandora mimetypes in drupal mimetype mappings --- includes/mime_detect.inc | 11 +++++++++++ islandora.module | 23 +++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/includes/mime_detect.inc b/includes/mime_detect.inc index 0914f62b..c92b5a15 100644 --- a/includes/mime_detect.inc +++ b/includes/mime_detect.inc @@ -366,4 +366,15 @@ class MimeDetect { return $out; } + /** + * Gets MIME type array. + * + * @return array + * returns associative array with exts and mimetypes + */ + public function getMimeTypes() { + return $this->protectedMimeTypes; + } + } + diff --git a/islandora.module b/islandora.module index ad9e569e..db5147b3 100644 --- a/islandora.module +++ b/islandora.module @@ -1097,3 +1097,26 @@ function islandora_download_clip(AbstractObject $object) { } exit(); } + +/** + * Implements hook_file_mimetype_mapping_alter(). + * + * Grab custom islandora mime type list and add any missing ext/mimes to the drupal mapping + * + * @param array $mapping + * The Drupal mimetype mapping. + */ +function islandora_file_mimetype_mapping_alter(&$mapping) { + $mime_detect = new MimeDetect(); + $types = $mime_detect->getMimeTypes(); + $diff = array_diff_key($types, $mapping['extensions']); + foreach ($diff as $ext => $mime) { + if (!isset($mapping['extensions'][$ext])) { + $mapping['mimetypes'][] = $mime; + $last = end($mapping['mimetypes']); + reset($mapping['mimetypes']); + $key = array_search($mime, $mapping['mimetypes']); + $mapping['extensions'][$ext] = $key; + } + } +} \ No newline at end of file From 27f97e74cb28bb3b69adc373c9d7f2b0591ce0a1 Mon Sep 17 00:00:00 2001 From: Nelson Hart Date: Fri, 31 May 2013 15:16:29 -0300 Subject: [PATCH 131/172] coder review --- includes/mime_detect.inc | 1 - islandora.module | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/includes/mime_detect.inc b/includes/mime_detect.inc index c92b5a15..d1fb058b 100644 --- a/includes/mime_detect.inc +++ b/includes/mime_detect.inc @@ -377,4 +377,3 @@ class MimeDetect { } } - diff --git a/islandora.module b/islandora.module index db5147b3..e7527a70 100644 --- a/islandora.module +++ b/islandora.module @@ -1119,4 +1119,4 @@ function islandora_file_mimetype_mapping_alter(&$mapping) { $mapping['extensions'][$ext] = $key; } } -} \ No newline at end of file +} From 054278bc8507bab875ad16853441612468a8706a Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Sun, 2 Jun 2013 21:51:23 +0200 Subject: [PATCH 132/172] No longer auto login the admin user breaks other tests that expect the anon user to be logged in. --- tests/{README.txt => README.md} | 4 ++-- tests/ingest.test | 3 ++- tests/islandora_web_test_case.inc | 26 +++++++++++++++++++++++++- 3 files changed, 29 insertions(+), 4 deletions(-) rename tests/{README.txt => README.md} (54%) diff --git a/tests/README.txt b/tests/README.md similarity index 54% rename from tests/README.txt rename to tests/README.md index c03004ae..c4a0ae1a 100644 --- a/tests/README.txt +++ b/tests/README.md @@ -1,4 +1,4 @@ You can define your own configurations specific to your enviroment by copying default.test_config.ini to test_config.ini, making your changes in the copied -file. These test need write access to the system's $FEDORA_HOME/server/config -directory as well as the filter-drupal.xml file. \ No newline at end of file +file. These test need write access to the system's $FEDORA_HOME/server/config +directory as well as the filter-drupal.xml file. diff --git a/tests/ingest.test b/tests/ingest.test index 0878076b..173b926f 100644 --- a/tests/ingest.test +++ b/tests/ingest.test @@ -71,7 +71,8 @@ class IslandoraIngestsTestCase extends IslandoraWebTestCase { * Test Ingest Steps. */ public function testIngest() { - global $user; + // Login the Admin user. + $this->drupalLogin($this->admin); // First step in form. $this->drupalGet('test/ingest'); // Default model selected, has no additional steps. diff --git a/tests/islandora_web_test_case.inc b/tests/islandora_web_test_case.inc index 2967280d..a39e9a45 100644 --- a/tests/islandora_web_test_case.inc +++ b/tests/islandora_web_test_case.inc @@ -93,7 +93,6 @@ class IslandoraWebTestCase extends DrupalWebTestCase { $roles = user_roles(); $index = array_search('administrator', $roles); $user = $this->drupalCreateUser(); - $this->drupalLogin($user); $user->roles[$index] = 'administrator'; $user->name = $this->configuration['admin_user']; $user->pass = $this->configuration['admin_pass']; @@ -104,6 +103,31 @@ class IslandoraWebTestCase extends DrupalWebTestCase { return $user; } + /** + * Logs in the given user, handles the special case where the user is admin. + * + * @see DrupalWebTestCase::drupalLogin() + */ + protected function drupalLogin(stdClass &$account) { + if ($account->uid == $this->admin->uid) { + // Create password for Drupal. + $edit = array('pass' => user_password()); + $account = user_save($account, $edit); + // Raw password is used to login. + $account->pass_raw = $edit['pass']; + // We must login before changing the password for fedora. + parent::drupalLogin($account); + $account->name = $this->configuration['admin_user']; + $account->pass = $this->configuration['admin_pass']; + // Save the fedora admin credentials for later GET/POST requests. + $account = user_save($account); + } + else { + parent::drupalLogin($account); + } + } + + /** * Stores the content of the Drupal Filter for later restoration. */ From ca7d099144696065d455bd8f078f8bcdfd30234e Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Mon, 3 Jun 2013 14:45:03 +0200 Subject: [PATCH 133/172] Fix strict warning. --- tests/islandora_web_test_case.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/islandora_web_test_case.inc b/tests/islandora_web_test_case.inc index a39e9a45..de414c17 100644 --- a/tests/islandora_web_test_case.inc +++ b/tests/islandora_web_test_case.inc @@ -108,7 +108,7 @@ class IslandoraWebTestCase extends DrupalWebTestCase { * * @see DrupalWebTestCase::drupalLogin() */ - protected function drupalLogin(stdClass &$account) { + protected function drupalLogin(stdClass $account) { if ($account->uid == $this->admin->uid) { // Create password for Drupal. $edit = array('pass' => user_password()); From 4c90c17e5acca701ff7bf711bf5abb4892409435 Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Mon, 3 Jun 2013 16:01:56 +0200 Subject: [PATCH 134/172] Adam's recommendations. --- islandora.module | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/islandora.module b/islandora.module index df17e65f..5bf67aba 100644 --- a/islandora.module +++ b/islandora.module @@ -979,30 +979,17 @@ function islandora_copy_object(AbstractObject $object) { $clone->$property = $object->$property; } } - $datastream_properties = array( - 'label', - 'versionable', - 'state', - 'mimetype', - 'format', - 'size', - 'checksum', - 'checksumType', - 'createdDate', - 'content', - 'url', - 'location', - ); // Copy Datastreams. foreach ($object as $dsid => $datastream) { if (empty($clone[$dsid])) { - $ds = $clone->constructDatastream($dsid, $datastream->controlGroup); - $clone->ingestDatastream($ds); + $clone->ingestDatastream($datastream); } - foreach ($datastream_properties as $property) { - if (isset($object[$dsid]->$property)) { - $clone[$dsid]->$property = $object[$dsid]->$property; - } + else { + // Get the content into a file, and add the file. + $temp_file = drupal_tempnam('temporary://', 'datastream'); + $datastream->getContent($temp_file); + $clone[$dsid]->setContentFromFile($temp_file); + drupal_unlink($temp_file); } } return $clone; From 1c39358457e49f682844987f5b203254f2a0bf52 Mon Sep 17 00:00:00 2001 From: Nelson Hart Date: Tue, 4 Jun 2013 09:33:46 -0300 Subject: [PATCH 135/172] code review changes --- includes/mime_detect.inc | 2 +- islandora.module | 16 +++++----------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/includes/mime_detect.inc b/includes/mime_detect.inc index 3c3741dd..13b66cc8 100644 --- a/includes/mime_detect.inc +++ b/includes/mime_detect.inc @@ -376,7 +376,7 @@ class MimeDetect { * Gets MIME type array. * * @return array - * returns associative array with exts and mimetypes + * Returns associative array with exts and mimetypes. */ public function getMimeTypes() { return $this->protectedMimeTypes; diff --git a/islandora.module b/islandora.module index 3899ddb9..d6c89e99 100644 --- a/islandora.module +++ b/islandora.module @@ -1113,22 +1113,16 @@ function islandora_download_clip(AbstractObject $object) { /** * Implements hook_file_mimetype_mapping_alter(). * - * Grab custom islandora mime type list and add any missing ext/mimes to the drupal mapping - * - * @param array $mapping - * The Drupal mimetype mapping. + * Grab custom islandora mime type list + * and add any missing ext/mimes to the drupal mapping */ function islandora_file_mimetype_mapping_alter(&$mapping) { $mime_detect = new MimeDetect(); $types = $mime_detect->getMimeTypes(); $diff = array_diff_key($types, $mapping['extensions']); foreach ($diff as $ext => $mime) { - if (!isset($mapping['extensions'][$ext])) { - $mapping['mimetypes'][] = $mime; - $last = end($mapping['mimetypes']); - reset($mapping['mimetypes']); - $key = array_search($mime, $mapping['mimetypes']); - $mapping['extensions'][$ext] = $key; - } + $mapping['mimetypes'][] = $mime; + end($mapping['mimetypes']); + $mapping['extensions'][$ext] = key($mapping['mimetypes']); } } From 467f29786e36021c10b964b5ca622cdaaeeebdef Mon Sep 17 00:00:00 2001 From: Nelson Hart Date: Tue, 4 Jun 2013 12:00:36 -0300 Subject: [PATCH 136/172] display top level collection name as repo link. Also updates breadcrumb with top level collection name --- islandora.module | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/islandora.module b/islandora.module index d6c89e99..4298f128 100644 --- a/islandora.module +++ b/islandora.module @@ -88,7 +88,7 @@ function islandora_menu() { 'type' => MENU_NORMAL_ITEM, ); $items['islandora'] = array( - 'title' => 'Islandora Repository', + 'title callback' => 'islandora_repository_root_label', 'page callback' => 'islandora_view_default_object', 'type' => MENU_NORMAL_ITEM, 'access arguments' => array(FEDORA_VIEW_OBJECTS), @@ -1126,3 +1126,17 @@ function islandora_file_mimetype_mapping_alter(&$mapping) { $mapping['extensions'][$ext] = key($mapping['mimetypes']); } } + +/** + * A callback to get the root collection label. + * + * + * @return text + * The object label of the root collection or the fallback + */ +function islandora_repository_root_label() { + $root = variable_get('islandora_repository_pid', 'islandora:root'); + $object = islandora_object_load($root); + $title = ($object ? $object->label : 'Islandora Repository'); + return $title; +} From e34e4614ddf4a314eb707cc59cc0c2444f203d1c Mon Sep 17 00:00:00 2001 From: Nelson Hart Date: Tue, 4 Jun 2013 12:23:35 -0300 Subject: [PATCH 137/172] clean up --- islandora.module | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/islandora.module b/islandora.module index 4298f128..8e504f2e 100644 --- a/islandora.module +++ b/islandora.module @@ -1129,10 +1129,8 @@ function islandora_file_mimetype_mapping_alter(&$mapping) { /** * A callback to get the root collection label. - * - * * @return text - * The object label of the root collection or the fallback + * The object label of the root collection or the fallback. */ function islandora_repository_root_label() { $root = variable_get('islandora_repository_pid', 'islandora:root'); From 2ddfa7b53c1a6335080797c03c55d41a3df822ad Mon Sep 17 00:00:00 2001 From: Nelson Hart Date: Tue, 4 Jun 2013 12:27:30 -0300 Subject: [PATCH 138/172] clean up vars --- islandora.module | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/islandora.module b/islandora.module index 8e504f2e..7ad7c5c7 100644 --- a/islandora.module +++ b/islandora.module @@ -1129,12 +1129,12 @@ function islandora_file_mimetype_mapping_alter(&$mapping) { /** * A callback to get the root collection label. - * @return text + * @return text $label * The object label of the root collection or the fallback. */ function islandora_repository_root_label() { $root = variable_get('islandora_repository_pid', 'islandora:root'); $object = islandora_object_load($root); - $title = ($object ? $object->label : 'Islandora Repository'); - return $title; + $label = ($object ? $object->label : 'Islandora Repository'); + return $label; } From 8e4a277040c47f1a3e9b38bb4486ffa725b437c4 Mon Sep 17 00:00:00 2001 From: Nelson Hart Date: Tue, 4 Jun 2013 13:11:27 -0300 Subject: [PATCH 139/172] code sniffer cleanup --- islandora.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/islandora.module b/islandora.module index 7ad7c5c7..f31f3585 100644 --- a/islandora.module +++ b/islandora.module @@ -1129,7 +1129,7 @@ function islandora_file_mimetype_mapping_alter(&$mapping) { /** * A callback to get the root collection label. - * @return text $label + * @return text * The object label of the root collection or the fallback. */ function islandora_repository_root_label() { From 44792a0b09887293080858a12c4455d6d7268bf5 Mon Sep 17 00:00:00 2001 From: Nelson Hart Date: Tue, 4 Jun 2013 15:11:14 -0300 Subject: [PATCH 140/172] another approach to getting the breadcrumb to display the link title --- includes/breadcrumb.inc | 11 +++++++++-- islandora.module | 14 +------------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/includes/breadcrumb.inc b/includes/breadcrumb.inc index f27d0e5d..9c587442 100644 --- a/includes/breadcrumb.inc +++ b/includes/breadcrumb.inc @@ -57,10 +57,17 @@ function islandora_get_breadcrumbs_recursive($pid, FedoraRepository $repository, $root = variable_get('islandora_repository_pid', 'islandora:root'); if ($pid == $root) { - $item = menu_get_item('islandora'); + $title = 'Islandora Repository'; + $trail = menu_get_active_trail(); + foreach ($trail as $key => $item) { + if ($item['link_path'] == 'islandora') { + $title = $item['link_title']; + break; + } + } return array( l(t('Home'), ''), - l($item['title'], 'islandora'), + l($title, 'islandora'), ); } else { diff --git a/islandora.module b/islandora.module index f31f3585..d6c89e99 100644 --- a/islandora.module +++ b/islandora.module @@ -88,7 +88,7 @@ function islandora_menu() { 'type' => MENU_NORMAL_ITEM, ); $items['islandora'] = array( - 'title callback' => 'islandora_repository_root_label', + 'title' => 'Islandora Repository', 'page callback' => 'islandora_view_default_object', 'type' => MENU_NORMAL_ITEM, 'access arguments' => array(FEDORA_VIEW_OBJECTS), @@ -1126,15 +1126,3 @@ function islandora_file_mimetype_mapping_alter(&$mapping) { $mapping['extensions'][$ext] = key($mapping['mimetypes']); } } - -/** - * A callback to get the root collection label. - * @return text - * The object label of the root collection or the fallback. - */ -function islandora_repository_root_label() { - $root = variable_get('islandora_repository_pid', 'islandora:root'); - $object = islandora_object_load($root); - $label = ($object ? $object->label : 'Islandora Repository'); - return $label; -} From f0a52f2bdaa05fbf7dfa09eebfe9627a847fcadb Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Tue, 4 Jun 2013 15:14:00 -0300 Subject: [PATCH 141/172] Initial implementation of the hooked access callback... ... Now have to make it get used everywhere. --- islandora.api.php | 39 +++++++++++++++++++++++++ islandora.module | 73 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+) diff --git a/islandora.api.php b/islandora.api.php index 89e1e048..603525ec 100644 --- a/islandora.api.php +++ b/islandora.api.php @@ -443,3 +443,42 @@ function hook_islandora_ingest_steps(array $form_state) { */ function hook_CMODEL_PID_islandora_ingest_steps(array $form_state) { } + +/** + * Hookable access hook. + * + * @param string $op + * A string define an operation to check. Should be defined via + * hook_permission(). + * @param AbstractObject $object + * An object to check the operation on. + * @param object $user + * A loaded user object, as the global $user variable might contain. + * + * @return bool|NULL + * Either boolean TRUE or FALSE to explicitly allow or deny the operation on + * the given object, or NULL to indicate that we are making no assertion + * about the outcome. + */ +function hook_islandora_access($op, $object, $user) { + switch ($op) { + case 'create stuff': + return TRUE; + + case 'break stuff': + return FALSE; + + case 'do a barrel roll!': + return NULL; + + } +} + +/** + * Content model specific version of hook_islandora_access(). + * + * @see hook_islandora_access + */ +function hook_CMODEL_PID_islandora_access($op, $object, $user) { + +} diff --git a/islandora.module b/islandora.module index d6c89e99..dbec912d 100644 --- a/islandora.module +++ b/islandora.module @@ -1126,3 +1126,76 @@ function islandora_file_mimetype_mapping_alter(&$mapping) { $mapping['extensions'][$ext] = key($mapping['mimetypes']); } } + +/** + * Hookable access callback. + * + * @param string $op + * String identifying an operation to check. Should correspond to a + * permission declared via hook_permission(). + * @param AbstractObject $object + * An object to check for permissions. + * @param object $user + * An optional loaded user object. Defaults to the global $user. + * + * @return bool + * TRUE if at least one implementation of hook_islandora_access() returned + * TRUE, and no implementation return FALSE; FALSE otherwise. + */ +function islandora_access($op, $object = NULL, $user = NULL) { + $cache = &drupal_static(__FUNCTION__); + + if (empty($object)) { + $pid = variable_get('islandora_repository_pid', 'islandora:root'); + $object = islandora_object_load($pid); + } + if (!$object) { + // The object could not be loaded... Presumably, we don't have + // permission. + return FALSE; + } + if ($user === NULL) { + global $user; + } + + // Populate the cache on a miss. + if (!isset($cache[$op][$object->id][$user->uid])) { + module_load_include('inc', 'islandora', 'includes/utilities'); + + $results = islandora_invoke_hook_list('islandora_access', $object->models, array( + $op, + $object, + $user, + )); + + // Nothing returned FALSE, and something returned TRUE. + $cache[$op][$object->id][$user->uid] = (!in_array(FALSE, $results, TRUE) && in_array(TRUE, $results, TRUE)); + } + + return $cache[$op][$object->id][$user->uid]; +} + +/** + * Implements hook_islandora_access(). + * + * Denies according to PID namespace restrictions, passes according to + * user_access(), and makes no indication if namespace restrictions passed but + * user_access() returned a fail, to allow other modules to allow an operation. + */ +function islandora_islandora_access($op, $object, $user) { + module_load_include('inc', 'islandora', 'includes/utilities'); + $to_return = islandora_namespace_accessible($object->id); + + if ($to_return && user_access($op, $user)) { + // Straight Drupal permissions, let's allow it. + return TRUE; + } + elseif ($to_return === FALSE) { + // PID namespace is outside of those allowed. Forbid! + return FALSE; + } + else { + // Neither allowing of forbidding, to allow other modules to override. + return NULL; + } +} From 9459899105efaf841e7c71647ae6c1dc1575cf8d Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Tue, 4 Jun 2013 16:43:28 -0300 Subject: [PATCH 142/172] Add hook_islandora_datastream_access()... ... Also, start using our new access functions in a few places. --- includes/datastream.inc | 4 +-- islandora.api.php | 45 +++++++++++++++++++++++--- islandora.module | 72 ++++++++++++++++++++++++++++++++--------- 3 files changed, 99 insertions(+), 22 deletions(-) diff --git a/includes/datastream.inc b/includes/datastream.inc index 23eb44f9..a0fd7669 100644 --- a/includes/datastream.inc +++ b/includes/datastream.inc @@ -85,7 +85,7 @@ function islandora_datastream_get_url(AbstractDatastream $datastream, $type = 'd */ function islandora_datastream_get_delete_link(AbstractDatastream $datastream) { $datastreams = module_invoke_all('islandora_undeletable_datastreams', $datastream->parent->models); - $can_delete = !in_array($datastream->id, $datastreams); + $can_delete = !in_array($datastream->id, $datastreams) && islandora_datastream_access(FEDORA_PURGE, $datastream); return $can_delete ? l(t('delete'), "islandora/object/{$datastream->parent->id}/datastream/{$datastream->id}/delete") : ''; } @@ -97,7 +97,7 @@ function islandora_datastream_get_delete_link(AbstractDatastream $datastream) { */ function islandora_datastream_edit_get_link(AbstractDatastream $datastream) { $edit_registry = module_invoke_all('islandora_edit_datastream_registry', $datastream->parent, $datastream); - $can_edit = count($edit_registry) > 0 && user_access(FEDORA_METADATA_EDIT); + $can_edit = count($edit_registry) > 0 && islandora_datastream_access(FEDORA_METADATA_EDIT, $datastream); return $can_edit ? l(t('edit'), "islandora/object/{$datastream->parent->id}/datastream/{$datastream->id}/edit") : ''; } diff --git a/islandora.api.php b/islandora.api.php index 603525ec..aa6df5b6 100644 --- a/islandora.api.php +++ b/islandora.api.php @@ -460,7 +460,7 @@ function hook_CMODEL_PID_islandora_ingest_steps(array $form_state) { * the given object, or NULL to indicate that we are making no assertion * about the outcome. */ -function hook_islandora_access($op, $object, $user) { +function hook_islandora_object_access($op, $object, $user) { switch ($op) { case 'create stuff': return TRUE; @@ -475,10 +475,47 @@ function hook_islandora_access($op, $object, $user) { } /** - * Content model specific version of hook_islandora_access(). + * Content model specific version of hook_islandora_object_access(). * - * @see hook_islandora_access + * @see hook_islandora_object_access() */ -function hook_CMODEL_PID_islandora_access($op, $object, $user) { +function hook_CMODEL_PID_islandora_object_access($op, $object, $user) { +} + +/** + * Hookable access hook. + * + * @param string $op + * A string define an operation to check. Should be defined via + * hook_permission(). + * @param AbstractDatastream $object + * An object to check the operation on. + * @param object $user + * A loaded user object, as the global $user variable might contain. + * + * @return bool|NULL + * Either boolean TRUE or FALSE to explicitly allow or deny the operation on + * the given object, or NULL to indicate that we are making no assertion + * about the outcome. + */ +function hook_islandora_datastream_access($op, $object, $user) { + switch ($op) { + case 'create stuff': + return TRUE; + + case 'break stuff': + return FALSE; + + case 'do a barrel roll!': + return NULL; + + } +} +/** + * Content model specific version of hook_islandora_datastream_access(). + * + * @see hook_islandora_datastream_access() + */ +function hook_CMODEL_PID_islandora_datastream_access($op, $object, $user) { } diff --git a/islandora.module b/islandora.module index dbec912d..5f156ee3 100644 --- a/islandora.module +++ b/islandora.module @@ -475,7 +475,7 @@ function islandora_object_access_callback($perm, $object = NULL) { return FALSE; } - return user_access($perm) && is_object($object) && islandora_namespace_accessible($object->id); + return islandora_object_access($perm); } /** @@ -499,8 +499,7 @@ function islandora_object_access_callback($perm, $object = NULL) { * TRUE if the user is allowed to access this object, FALSE otherwise. */ function islandora_object_datastream_access_callback($perm, $object = NULL, $datastream = NULL, $account = NULL) { - module_load_include('inc', 'islandora', 'includes/utilities'); - return user_access($perm, $account) && is_object($object) && islandora_namespace_accessible($object->id) && is_object($datastream); + return islandora_datastream_access($perm, $datastream, $account); } /** @@ -554,10 +553,10 @@ function islandora_object_manage_access_callback($perms, $object = NULL) { $has_access = FALSE; for ($i = 0; $i < count($perms) && !$has_access; $i++) { - $has_access = $has_access || user_access($perms[$i]); + $has_access = $has_access || islandora_object_access($perms[$i], $object); } - return $has_access && is_object($object) && islandora_namespace_accessible($object->id); + return $has_access; } /** @@ -1128,7 +1127,7 @@ function islandora_file_mimetype_mapping_alter(&$mapping) { } /** - * Hookable access callback. + * Hookable object access callback. * * @param string $op * String identifying an operation to check. Should correspond to a @@ -1139,17 +1138,13 @@ function islandora_file_mimetype_mapping_alter(&$mapping) { * An optional loaded user object. Defaults to the global $user. * * @return bool - * TRUE if at least one implementation of hook_islandora_access() returned + * TRUE if at least one implementation of hook_islandora_object_access() returned * TRUE, and no implementation return FALSE; FALSE otherwise. */ -function islandora_access($op, $object = NULL, $user = NULL) { +function islandora_object_access($op, $object, $user = NULL) { $cache = &drupal_static(__FUNCTION__); - if (empty($object)) { - $pid = variable_get('islandora_repository_pid', 'islandora:root'); - $object = islandora_object_load($pid); - } - if (!$object) { + if (!is_object($object)) { // The object could not be loaded... Presumably, we don't have // permission. return FALSE; @@ -1162,7 +1157,7 @@ function islandora_access($op, $object = NULL, $user = NULL) { if (!isset($cache[$op][$object->id][$user->uid])) { module_load_include('inc', 'islandora', 'includes/utilities'); - $results = islandora_invoke_hook_list('islandora_access', $object->models, array( + $results = islandora_invoke_hook_list('islandora_object_access', $object->models, array( $op, $object, $user, @@ -1176,13 +1171,13 @@ function islandora_access($op, $object = NULL, $user = NULL) { } /** - * Implements hook_islandora_access(). + * Implements hook_islandora_object_access(). * * Denies according to PID namespace restrictions, passes according to * user_access(), and makes no indication if namespace restrictions passed but * user_access() returned a fail, to allow other modules to allow an operation. */ -function islandora_islandora_access($op, $object, $user) { +function islandora_islandora_object_access($op, $object, $user) { module_load_include('inc', 'islandora', 'includes/utilities'); $to_return = islandora_namespace_accessible($object->id); @@ -1199,3 +1194,48 @@ function islandora_islandora_access($op, $object, $user) { return NULL; } } + +/** + * Hookable access callback for datastreams. + * + * Requires the equivalent permissions on the object. + */ +function islandora_datastream_access($op, $datastream, $user = NULL) { + $cache = &drupal_static(__FUNCTION__); + + if (!$datastream) { + // The object could not be loaded... Presumably, we don't have + // permission. + return NULL; + } + if ($user === NULL) { + global $user; + } + + // Populate the cache on a miss. + if (!isset($cache[$op][$object->id][$user->uid])) { + if ($cache[$op][$datastream->parent->id][$datastream->id][$user->uid]) { + module_load_include('inc', 'islandora', 'includes/utilities'); + $object_results = islandora_invoke_hook_list('islandora_object_access', $datastream->parent->models, array( + $op, + $datastream->parent, + $user, + )); + + $datastream_results = islandora_invoke_hook_list('islandora_datastream_access', $datastream->parent->models, array( + $op, + $datastream, + $user, + )); + + // Neither the object nor the datastream check returned FALSE, and one in + // the object or datastream checks returned TRUE. + $cache[$op][$datastream->parent->id][$datastream->id][$user->uid] = + !in_array(FALSE, $object_results, TRUE) && + !in_array(FALSE, $datastream_results, TRUE) && + (in_array(TRUE, $object_results, TRUE) || in_array(TRUE, $datastream_results, TRUE)); + } + } + + return $cache[$op][$datastream->parent->id][$datastream->id][$user->uid]; +} From 368492a54e23f9d5dcd583fae2a157257e105641 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Wed, 5 Jun 2013 10:21:00 -0300 Subject: [PATCH 143/172] Add access checks to view/download links. --- theme/theme.inc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/theme/theme.inc b/theme/theme.inc index 7c43deef..d03370d5 100644 --- a/theme/theme.inc +++ b/theme/theme.inc @@ -29,7 +29,9 @@ function islandora_preprocess_islandora_default_edit(array &$variables) { $rows[] = array( array( 'class' => 'datastream-id', - 'data' => l($ds->id, islandora_datastream_get_url($ds, 'view')), + 'data' => (islandora_datastream_access(FEDORA_VIEW_OBJECTS, $ds) ? + l($ds->id, islandora_datastream_get_url($ds, 'view')) : + ''), ), array( 'class' => 'datastream-label', @@ -49,7 +51,9 @@ function islandora_preprocess_islandora_default_edit(array &$variables) { ), array( 'class' => 'datastream-download', - 'data' => l(t('download'), islandora_datastream_get_url($ds, 'download')), + 'data' => (islandora_datastream_access(FEDORA_VIEW_OBJECTS, $ds) ? + l(t('download'), islandora_datastream_get_url($ds, 'download')) : + ''), ), array( 'class' => 'datstream-edit', From 277a109ebc31c2869b6d8700564feeac7d1ec11f Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Wed, 5 Jun 2013 12:23:46 -0300 Subject: [PATCH 144/172] Force islandora to be present in the allowed namespaces at all times. --- includes/utilities.inc | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/includes/utilities.inc b/includes/utilities.inc index cdbf8daa..32b05158 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -256,8 +256,8 @@ function islandora_get_namespace($id) { */ function islandora_namespace_accessible($id) { if (variable_get('islandora_namespace_restriction_enforced', FALSE)) { - $namespace = islandora_get_namespace($id) . ':'; - $allowed_namespaces = explode(" ", variable_get('islandora_pids_allowed', 'default: demo: changeme: islandora: ilives: islandora-book: books: newspapers: ')); + $namespace = islandora_get_namespace($id); + $allowed_namespaces = islandora_get_allowed_namespaces(); return in_array($namespace, $allowed_namespaces); } return TRUE; @@ -712,7 +712,13 @@ function islandora_get_allowed_namespaces() { $matches = array(); $allowed_namespaces = variable_get('islandora_pids_allowed', 'default: demo: changeme: islandora:'); preg_match_all('/([A-Za-z0-9-\.]+):/', $allowed_namespaces, $matches); - return $matches[1]; + $accessible_namespaces = $matches[1]; + // Ensure that the "islandora" namespace is explicitly allowed + // no matter what happens. + if (!in_array('islandora', $accessible_namespaces)) { + $accessible_namespaces[] = 'islandora'; + } + return $accessible_namespaces; } /** From a8f13b0a46155c3f3dad8c9ea11ac5072e44e401 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Wed, 5 Jun 2013 16:27:10 -0300 Subject: [PATCH 145/172] Add access checks. --- includes/datastream.inc | 34 +++++++++++++++++++ includes/object_properties.form.inc | 1 + islandora.module | 51 ++++++++++++++--------------- theme/theme.inc | 30 +++++++++-------- 4 files changed, 76 insertions(+), 40 deletions(-) diff --git a/includes/datastream.inc b/includes/datastream.inc index a0fd7669..902d5670 100644 --- a/includes/datastream.inc +++ b/includes/datastream.inc @@ -144,3 +144,37 @@ function islandora_edit_datastream_registry_render(array $edit_registry) { '#markup' => $markup, ); } + +/** + * Get markup for a download link. + * + * @param AbstractDatastream $datastream + * The datastream for which to generate a link. + * + * @return string + * Either the link markup if the user has access or an empty string if the + * user is not allowed to see the given datastream. + */ +function islandora_datastream_get_download_link(AbstractDatastream $datastream) { + $label = t('download'); + return islandora_datastream_access(FEDORA_VIEW_OBJECTS, $datastream) ? + l($label, islandora_datastream_get_url($datastream, 'download')) : + ''; +} + +/** + * Get markup for a view link. + * + * @param AbstractDatastream $datastream + * The datastream for which to generate a link. + * + * @return string + * Either the link markup if the user has access or a string containing the + * datastream ID if the user is not allowed to see the given datastream. + */ +function islandora_datastream_get_view_link(AbstractDatastream $datastream) { + $label = check_plain($datastream->id); + return islandora_datastream_access(FEDORA_VIEW_OBJECTS, $datastream) ? + l($label, islandora_datastream_get_url($datastream, 'view')) : + $label; +} diff --git a/includes/object_properties.form.inc b/includes/object_properties.form.inc index 543fa6dd..44d016b7 100644 --- a/includes/object_properties.form.inc +++ b/includes/object_properties.form.inc @@ -60,6 +60,7 @@ function islandora_object_properties_form(array $form, array &$form_state, Abstr ), 'delete' => array( '#type' => 'submit', + '#access' => islandora_object_access(FEDORA_PURGE, $object), '#value' => t('Delete'), '#submit' => array('islandora_object_properties_form_delete'), '#limit_validation_errors' => array(array('pid')), diff --git a/islandora.module b/islandora.module index 5f156ee3..daa612a9 100644 --- a/islandora.module +++ b/islandora.module @@ -475,7 +475,7 @@ function islandora_object_access_callback($perm, $object = NULL) { return FALSE; } - return islandora_object_access($perm); + return islandora_object_access($perm, $object); } /** @@ -1138,8 +1138,8 @@ function islandora_file_mimetype_mapping_alter(&$mapping) { * An optional loaded user object. Defaults to the global $user. * * @return bool - * TRUE if at least one implementation of hook_islandora_object_access() returned - * TRUE, and no implementation return FALSE; FALSE otherwise. + * TRUE if at least one implementation of hook_islandora_object_access() + * returned TRUE, and no implementation return FALSE; FALSE otherwise. */ function islandora_object_access($op, $object, $user = NULL) { $cache = &drupal_static(__FUNCTION__); @@ -1203,7 +1203,7 @@ function islandora_islandora_object_access($op, $object, $user) { function islandora_datastream_access($op, $datastream, $user = NULL) { $cache = &drupal_static(__FUNCTION__); - if (!$datastream) { + if (!is_object($datastream)) { // The object could not be loaded... Presumably, we don't have // permission. return NULL; @@ -1213,28 +1213,27 @@ function islandora_datastream_access($op, $datastream, $user = NULL) { } // Populate the cache on a miss. - if (!isset($cache[$op][$object->id][$user->uid])) { - if ($cache[$op][$datastream->parent->id][$datastream->id][$user->uid]) { - module_load_include('inc', 'islandora', 'includes/utilities'); - $object_results = islandora_invoke_hook_list('islandora_object_access', $datastream->parent->models, array( - $op, - $datastream->parent, - $user, - )); - - $datastream_results = islandora_invoke_hook_list('islandora_datastream_access', $datastream->parent->models, array( - $op, - $datastream, - $user, - )); - - // Neither the object nor the datastream check returned FALSE, and one in - // the object or datastream checks returned TRUE. - $cache[$op][$datastream->parent->id][$datastream->id][$user->uid] = - !in_array(FALSE, $object_results, TRUE) && - !in_array(FALSE, $datastream_results, TRUE) && - (in_array(TRUE, $object_results, TRUE) || in_array(TRUE, $datastream_results, TRUE)); - } + if (!isset($cache[$op][$datastream->parent->id][$datastream->id][$user->uid])) { + module_load_include('inc', 'islandora', 'includes/utilities'); + $object_results = islandora_invoke_hook_list('islandora_object_access', $datastream->parent->models, array( + $op, + $datastream->parent, + $user, + )); + + $datastream_results = islandora_invoke_hook_list('islandora_datastream_access', $datastream->parent->models, array( + $op, + $datastream, + $user, + )); + + // Neither the object nor the datastream check returned FALSE, and one in + // the object or datastream checks returned TRUE. + $cache[$op][$datastream->parent->id][$datastream->id][$user->uid] = ( + !in_array(FALSE, $object_results, TRUE) && + !in_array(FALSE, $datastream_results, TRUE) && + (in_array(TRUE, $object_results, TRUE) || in_array(TRUE, $datastream_results, TRUE)) + ); } return $cache[$op][$datastream->parent->id][$datastream->id][$user->uid]; diff --git a/theme/theme.inc b/theme/theme.inc index d03370d5..e9db9f3e 100644 --- a/theme/theme.inc +++ b/theme/theme.inc @@ -29,9 +29,7 @@ function islandora_preprocess_islandora_default_edit(array &$variables) { $rows[] = array( array( 'class' => 'datastream-id', - 'data' => (islandora_datastream_access(FEDORA_VIEW_OBJECTS, $ds) ? - l($ds->id, islandora_datastream_get_url($ds, 'view')) : - ''), + 'data' => islandora_datastream_get_view_link($ds), ), array( 'class' => 'datastream-label', @@ -51,9 +49,7 @@ function islandora_preprocess_islandora_default_edit(array &$variables) { ), array( 'class' => 'datastream-download', - 'data' => (islandora_datastream_access(FEDORA_VIEW_OBJECTS, $ds) ? - l(t('download'), islandora_datastream_get_url($ds, 'download')) : - ''), + 'data' => islandora_datastream_get_download_link($ds), ), array( 'class' => 'datstream-edit', @@ -99,7 +95,9 @@ function islandora_preprocess_islandora_default(&$variables) { $download_path = islandora_datastream_get_url($ds, 'download'); $datastreams[$id]['id'] = $id; $datastreams[$id]['label'] = $label; - $datastreams[$id]['label_link'] = l($label, $download_path); + $datastreams[$id]['label_link'] = islandora_datastream_access(FEDORA_VIEW_OBJECTS, $ds) ? + l($label, $download_path) : + $label; $datastreams[$id]['download_url'] = $download_path; $datastreams[$id]['mimetype'] = $ds->mimetype; $datastreams[$id]['size'] = islandora_datastream_get_human_readable_size($ds); @@ -112,14 +110,14 @@ function islandora_preprocess_islandora_default(&$variables) { } $variables['datastreams'] = $datastreams; // Objects in fcrepo4 don't always contain a DC datastream. - if (isset($islandora_object['DC'])) { + if (isset($islandora_object['DC']) && islandora_datastream_access(FEDORA_VIEW_OBJECTS, $islandora_object['DC'])) { $dc_object = DublinCore::importFromXMLString($islandora_object['DC']->content); $dc_array = $dc_object->asArray(); } $variables['dc_array'] = isset($dc_array) ? $dc_array : array(); $variables['islandora_dublin_core'] = isset($dc_object) ? $dc_object : NULL; $variables['islandora_object_label'] = $islandora_object->label; - if (isset($islandora_object['TN'])) { + if (isset($islandora_object['TN']) && islandora_datastream_access(FEDORA_VIEW_OBJECTS, $islandora_object['TN'])) { $variables['islandora_thumbnail_url'] = url("islandora/object/{$islandora_object->id}/datastream/TN/view"); } } @@ -201,12 +199,16 @@ function islandora_preprocess_islandora_objects(array &$variables) { $o = islandora_object_load($o); $url = "islandora/object/{$o->id}"; $link_options = array('html' => TRUE, 'attributes' => array('title' => $o->label)); - $img = theme_image(array('path' => url("$url/datastream/TN/view"), 'attributes' => array())); + $img = islandora_datastream_access(FEDORA_VIEW_OBJECTS, $o['TN']) ? + theme('image', array('path' => url("$url/datastream/TN/view"), 'attributes' => array())) : + ''; $description = NULL; - $dc = DublinCore::importFromXMLString($o['DC']->content); - if ($dc) { - $dc = $dc->asArray(); - $description = $dc['dc:description']['value']; + if (islandora_datastream_access($o['DC'])) { + $dc = DublinCore::importFromXMLString($o['DC']->content); + if ($dc) { + $dc = $dc->asArray(); + $description = $dc['dc:description']['value']; + } } return array( 'label' => $o->label, From d04c00fd50a17deff314de48ac1fd23ecfde1c16 Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Fri, 7 Jun 2013 10:29:07 -0300 Subject: [PATCH 146/172] Use the utility function as opposed to re-defining a query. --- includes/content_model.autocomplete.inc | 28 +++---------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/includes/content_model.autocomplete.inc b/includes/content_model.autocomplete.inc index c6fd34df..67923e9e 100644 --- a/includes/content_model.autocomplete.inc +++ b/includes/content_model.autocomplete.inc @@ -28,37 +28,15 @@ function islandora_content_model_autocomplete($string) { * Gets a map of form names suitable for use as select #options. */ function islandora_get_content_model_names() { - $results = islandora_query_content_models(); + module_load_include('inc', 'islandora', 'includes/utilities'); + $results = islandora_get_content_models(); $ret = array(); foreach ($results as $result) { - $ret[$result['model']['value']] = "{$result['label']['value']} ({$result['model']['value']})"; + $ret[$result['pid']] = "{$result['label']} ({$result['pid']})"; } return $ret; } -/** - * Perform a resource index query to determine get a list of content models. - * - * Only returns content models with at least one subscribing object. - * - * @return array - * An array of RI results, as given by the Tuque RI query interface. - */ -function islandora_query_content_models() { - $connection = islandora_get_tuque_connection(); - if ($connection) { - $query = 'select $model $label from <#ri> where - $model and $model $label - minus $model - minus $model - minus $model - minus $model '; - $results = $connection->repository->ri->itqlQuery($query); - return $results; - } - return array(); -} - /** * Minor array transformation. * From bc8492a7879b6599da54a064717905f002d66383 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Fri, 7 Jun 2013 10:46:59 -0300 Subject: [PATCH 147/172] Add a couple more access checks. --- includes/utilities.inc | 2 +- theme/theme.inc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/utilities.inc b/includes/utilities.inc index cdbf8daa..4d69155d 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -389,7 +389,7 @@ function islandora_get_datastreams_requirements_from_models(array $models) { * - "optional": A boolean indicating if the given stream is optional. */ function islandora_get_datastreams_requirements_from_content_model(AbstractObject $object) { - if (empty($object[DS_COMP_STREAM])) { + if (empty($object[DS_COMP_STREAM]) || !islandora_datastream_access(FEDORA_VIEW_OBJECTS, $object[DS_COMP_STREAM])) { return array(); } $xml = new SimpleXMLElement($object[DS_COMP_STREAM]->content); diff --git a/theme/theme.inc b/theme/theme.inc index e9db9f3e..ce6f2659 100644 --- a/theme/theme.inc +++ b/theme/theme.inc @@ -203,7 +203,7 @@ function islandora_preprocess_islandora_objects(array &$variables) { theme('image', array('path' => url("$url/datastream/TN/view"), 'attributes' => array())) : ''; $description = NULL; - if (islandora_datastream_access($o['DC'])) { + if (isset($o['DC']) && islandora_datastream_access(FEDORA_VIEW_OBJECTS, $o['DC'])) { $dc = DublinCore::importFromXMLString($o['DC']->content); if ($dc) { $dc = $dc->asArray(); From 70333d8783e33de80c5b28c7eb4a8b77b7beb959 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Fri, 7 Jun 2013 13:32:42 -0300 Subject: [PATCH 148/172] Add the strict access flag. --- includes/admin.form.inc | 7 +++++++ islandora.module | 6 ++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/includes/admin.form.inc b/includes/admin.form.inc index a1f22652..f4db785b 100644 --- a/includes/admin.form.inc +++ b/includes/admin.form.inc @@ -108,6 +108,13 @@ function islandora_repository_admin(array $form, array &$form_state) { '#required' => TRUE, ); + $form['islandora_tabs']['islandora_general']['islandora_strict_user_access_enforcement'] = array( + '#type' => 'checkbox', + '#title' => t('Strict User Access Enforcement'), + '#description' => t('Restrict permissions to the result of user_access(); other modules will be able to deny things, but other modules will not be able to allow operations not allowed via Drupal permissions.'), + '#default_value' => variable_get('islandora_strict_user_access_enforcement', TRUE), + ); + $form['islandora_tabs']['islandora_namespace'] = array( '#type' => 'fieldset', '#title' => t('Namespaces'), diff --git a/islandora.module b/islandora.module index daa612a9..b5319122 100644 --- a/islandora.module +++ b/islandora.module @@ -1181,11 +1181,13 @@ function islandora_islandora_object_access($op, $object, $user) { module_load_include('inc', 'islandora', 'includes/utilities'); $to_return = islandora_namespace_accessible($object->id); - if ($to_return && user_access($op, $user)) { + $user_access_result = user_access($op, $user); + + if ($to_return && $user_access_result) { // Straight Drupal permissions, let's allow it. return TRUE; } - elseif ($to_return === FALSE) { + elseif ($to_return === FALSE || variable_get('islandora_strict_user_access_enforcement', TRUE) && !$user_access_result) { // PID namespace is outside of those allowed. Forbid! return FALSE; } From ef4a0fe021850f4f3acd3bd44b98d745132079ca Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Mon, 10 Jun 2013 15:13:50 -0300 Subject: [PATCH 149/172] Use the hooked access callback in place of the any/all cases. Leaving the functions called in place, in the case that they're called elsewhere. --- islandora.module | 45 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/islandora.module b/islandora.module index b5319122..96836f4c 100644 --- a/islandora.module +++ b/islandora.module @@ -432,24 +432,55 @@ function islandora_user_access($object, array $permissions, $content_models = ar } } // Determine what has been passed as $object. - if (is_subclass_of($object, 'FedoraObject')) { - $object = $object; + if (is_subclass_of($object, 'AbstractObject')) { + $datastream = NULL; + // $object stays $object... } - elseif (is_subclass_of($object, 'FedoraDatastream')) { + elseif (is_subclass_of($object, 'AbstractDatastream')) { $datastream = $object; $object = $datastream->parent; } + // Check for access. $accessible_namespace = islandora_namespace_accessible($object->id); if ($access_any) { - $has_required_permissions = islandora_user_access_any($permissions, $account); + $has_required_permissions = function ($permissions, $datastream, $object) { + foreach ($permissions as $p) { + if ($datastream !== NULL) { + $check = islandora_datastream_access($p, $datastream); + } + else { + $check = islandora_object_access($p, $object); + } + + if ($check) { + return TRUE; + } + } + }; $has_required_content_models = empty($content_models) ? TRUE : count(array_intersect($object->models, $content_models)) > 0; } else { - $has_required_permissions = islandora_user_access_all($permissions, $account); + $has_required_permissions = function ($permissions, $datastream, $object) { + foreach ($permissions as $p) { + if ($datastream !== NULL) { + $check = islandora_datastream_access($p, $datastream); + } + else { + $check = islandora_object_access($p, $object); + } + + if (!$check) { + return FALSE; + } + } + }; $has_required_content_models = count(array_diff($content_models, $object->models)) == 0; } - return $accessible_namespace && $has_required_permissions && $has_required_content_models; + + return $accessible_namespace && + $has_required_permissions($permissions, $datastream, $object) && + $has_required_content_models; } /** @@ -1187,7 +1218,7 @@ function islandora_islandora_object_access($op, $object, $user) { // Straight Drupal permissions, let's allow it. return TRUE; } - elseif ($to_return === FALSE || variable_get('islandora_strict_user_access_enforcement', TRUE) && !$user_access_result) { + elseif ($to_return === FALSE || (variable_get('islandora_strict_user_access_enforcement', TRUE) && !$user_access_result)) { // PID namespace is outside of those allowed. Forbid! return FALSE; } From 594adab668bea5a0c2ff62978bc9edde1c59fa1b Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Tue, 11 Jun 2013 11:52:54 -0300 Subject: [PATCH 150/172] Pass the user along as we should. --- islandora.module | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/islandora.module b/islandora.module index 96836f4c..9b81a388 100644 --- a/islandora.module +++ b/islandora.module @@ -444,13 +444,13 @@ function islandora_user_access($object, array $permissions, $content_models = ar // Check for access. $accessible_namespace = islandora_namespace_accessible($object->id); if ($access_any) { - $has_required_permissions = function ($permissions, $datastream, $object) { + $has_required_permissions = function ($permissions, $datastream, $object, $user) { foreach ($permissions as $p) { if ($datastream !== NULL) { - $check = islandora_datastream_access($p, $datastream); + $check = islandora_datastream_access($p, $datastream, $user); } else { - $check = islandora_object_access($p, $object); + $check = islandora_object_access($p, $object, $user); } if ($check) { @@ -461,13 +461,13 @@ function islandora_user_access($object, array $permissions, $content_models = ar $has_required_content_models = empty($content_models) ? TRUE : count(array_intersect($object->models, $content_models)) > 0; } else { - $has_required_permissions = function ($permissions, $datastream, $object) { + $has_required_permissions = function ($permissions, $datastream, $object, $user) { foreach ($permissions as $p) { if ($datastream !== NULL) { - $check = islandora_datastream_access($p, $datastream); + $check = islandora_datastream_access($p, $datastream, $user); } else { - $check = islandora_object_access($p, $object); + $check = islandora_object_access($p, $object, $user); } if (!$check) { @@ -479,7 +479,7 @@ function islandora_user_access($object, array $permissions, $content_models = ar } return $accessible_namespace && - $has_required_permissions($permissions, $datastream, $object) && + $has_required_permissions($permissions, $datastream, $object, $account) && $has_required_content_models; } @@ -1188,6 +1188,9 @@ function islandora_object_access($op, $object, $user = NULL) { if (!isset($cache[$op][$object->id][$user->uid])) { module_load_include('inc', 'islandora', 'includes/utilities'); + if (!($object instanceof AbstractObject)) { + ddebug_backtrace(); + } $results = islandora_invoke_hook_list('islandora_object_access', $object->models, array( $op, $object, From 2a654d6e837c4c8809d22b99bed731c1dc847e70 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Tue, 11 Jun 2013 13:25:50 -0300 Subject: [PATCH 151/172] Pass the content models... --- islandora.module | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/islandora.module b/islandora.module index 9b81a388..504d9940 100644 --- a/islandora.module +++ b/islandora.module @@ -444,7 +444,7 @@ function islandora_user_access($object, array $permissions, $content_models = ar // Check for access. $accessible_namespace = islandora_namespace_accessible($object->id); if ($access_any) { - $has_required_permissions = function ($permissions, $datastream, $object, $user) { + $has_required_permissions = function ($permissions, $content_models, $datastream, $object, $user) { foreach ($permissions as $p) { if ($datastream !== NULL) { $check = islandora_datastream_access($p, $datastream, $user); @@ -458,10 +458,10 @@ function islandora_user_access($object, array $permissions, $content_models = ar } } }; - $has_required_content_models = empty($content_models) ? TRUE : count(array_intersect($object->models, $content_models)) > 0; + $has_required_content_models = empty($content_models) ? TRUE : (count(array_intersect($object->models, $content_models)) > 0); } else { - $has_required_permissions = function ($permissions, $datastream, $object, $user) { + $has_required_permissions = function ($permissions, $content_models, $datastream, $object, $user) { foreach ($permissions as $p) { if ($datastream !== NULL) { $check = islandora_datastream_access($p, $datastream, $user); @@ -479,7 +479,7 @@ function islandora_user_access($object, array $permissions, $content_models = ar } return $accessible_namespace && - $has_required_permissions($permissions, $datastream, $object, $account) && + $has_required_permissions($permissions, $content_models, $datastream, $object, $account) && $has_required_content_models; } From bb635ccbcdfe27e22b3c5e04cb1fa1dd13193f50 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Tue, 11 Jun 2013 13:43:02 -0300 Subject: [PATCH 152/172] The namespace check is handled via the hooked access callback. --- islandora.module | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/islandora.module b/islandora.module index 504d9940..0a676c76 100644 --- a/islandora.module +++ b/islandora.module @@ -442,7 +442,6 @@ function islandora_user_access($object, array $permissions, $content_models = ar } // Check for access. - $accessible_namespace = islandora_namespace_accessible($object->id); if ($access_any) { $has_required_permissions = function ($permissions, $content_models, $datastream, $object, $user) { foreach ($permissions as $p) { @@ -478,8 +477,7 @@ function islandora_user_access($object, array $permissions, $content_models = ar $has_required_content_models = count(array_diff($content_models, $object->models)) == 0; } - return $accessible_namespace && - $has_required_permissions($permissions, $content_models, $datastream, $object, $account) && + return $has_required_permissions($permissions, $content_models, $datastream, $object, $account) && $has_required_content_models; } From b1479d5af78e909783aca21b9df708798ad980a1 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Tue, 11 Jun 2013 13:50:07 -0300 Subject: [PATCH 153/172] Revert "Pass the content models..." This reverts commit 2a654d6e837c4c8809d22b99bed731c1dc847e70... The content models weren't needed or used... Messed up matching braces in my head. Conflicts: islandora.module --- islandora.module | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/islandora.module b/islandora.module index 0a676c76..3997de63 100644 --- a/islandora.module +++ b/islandora.module @@ -443,7 +443,7 @@ function islandora_user_access($object, array $permissions, $content_models = ar // Check for access. if ($access_any) { - $has_required_permissions = function ($permissions, $content_models, $datastream, $object, $user) { + $has_required_permissions = function ($permissions, $datastream, $object, $user) { foreach ($permissions as $p) { if ($datastream !== NULL) { $check = islandora_datastream_access($p, $datastream, $user); @@ -457,10 +457,10 @@ function islandora_user_access($object, array $permissions, $content_models = ar } } }; - $has_required_content_models = empty($content_models) ? TRUE : (count(array_intersect($object->models, $content_models)) > 0); + $has_required_content_models = empty($content_models) ? TRUE : count(array_intersect($object->models, $content_models)) > 0; } else { - $has_required_permissions = function ($permissions, $content_models, $datastream, $object, $user) { + $has_required_permissions = function ($permissions, $datastream, $object, $user) { foreach ($permissions as $p) { if ($datastream !== NULL) { $check = islandora_datastream_access($p, $datastream, $user); @@ -477,7 +477,7 @@ function islandora_user_access($object, array $permissions, $content_models = ar $has_required_content_models = count(array_diff($content_models, $object->models)) == 0; } - return $has_required_permissions($permissions, $content_models, $datastream, $object, $account) && + return $has_required_permissions($permissions, $datastream, $object, $account) && $has_required_content_models; } From 54bee2e233c76f7939b118a7474bc359509b11a8 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Tue, 11 Jun 2013 13:56:27 -0300 Subject: [PATCH 154/172] Return the final result from the permission anonymous functions. ... Was missing... Also, the handling of an empty array of permissions was happening only implicitly. --- islandora.module | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/islandora.module b/islandora.module index 3997de63..b4f4ca7a 100644 --- a/islandora.module +++ b/islandora.module @@ -413,7 +413,7 @@ function islandora_user_access($object, array $permissions, $content_models = ar return FALSE; } } - if (!$is_repository_accessible || !is_object($object)) { + if (!$is_repository_accessible || !is_object($object) || empty($permissions)) { return FALSE; } // Determine the user account to test against. @@ -456,6 +456,7 @@ function islandora_user_access($object, array $permissions, $content_models = ar return TRUE; } } + return FALSE; }; $has_required_content_models = empty($content_models) ? TRUE : count(array_intersect($object->models, $content_models)) > 0; } @@ -473,6 +474,7 @@ function islandora_user_access($object, array $permissions, $content_models = ar return FALSE; } } + return TRUE; }; $has_required_content_models = count(array_diff($content_models, $object->models)) == 0; } From 023a410c714201484ae2548ae7e6e925d72e16a2 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Tue, 11 Jun 2013 15:20:37 -0300 Subject: [PATCH 155/172] Add some basic tests for the hooked access callback. --- islandora.info | 1 + tests/hooked_access.test | 181 ++++++++++++++++++++++ tests/islandora_hooked_access_test.info | 7 + tests/islandora_hooked_access_test.module | 31 ++++ 4 files changed, 220 insertions(+) create mode 100644 tests/hooked_access.test create mode 100644 tests/islandora_hooked_access_test.info create mode 100644 tests/islandora_hooked_access_test.module diff --git a/islandora.info b/islandora.info index 4f6a5858..ce6ba947 100644 --- a/islandora.info +++ b/islandora.info @@ -15,5 +15,6 @@ files[] = tests/islandora_web_test_case.inc files[] = tests/authtokens.test files[] = tests/hooks.test files[] = tests/ingest.test +files[] = tests/hooked_access.test files[] = tests/islandora_manage_permissions.test php = 5.3 diff --git a/tests/hooked_access.test b/tests/hooked_access.test new file mode 100644 index 00000000..0f7610e0 --- /dev/null +++ b/tests/hooked_access.test @@ -0,0 +1,181 @@ + 'Islandora Hooked Access Callback', + 'description' => 'Ensure that the hooked access callback returns appropriate results.', + 'group' => 'Islandora', + ); + } + + /** + * Creates an admin user and a connection to a fedora repository. + * + * @see IslandoraWebTestCase::setUp() + */ + public function setUp() { + parent::setUp('islandora_hooked_access_test'); + $this->repository = $this->admin->repository; + $this->objects = array( + 'test:testAccessHook', + ); + $this->op = FEDORA_VIEW_OBJECTS; + $this->other_op = FEDORA_INGEST; + $this->denied_op = FEDORA_PURGE; + $this->purgeTestObjects(); + $this->dsid = 'asdf'; + $this->createTestObjects(); + $this->object = $this->repository->getObject('test:testAccessHook'); + } + + /** + * Free any objects/resources created for this test. + * + * @see IslandoraWebTestCase::tearDown() + */ + public function tearDown() { + $this->purgeTestObjects(); + unset($this->repository); + unset($_SESSION['islandora_hooked_access_test']); + parent::tearDown(); + } + + public function createTestObjects() { + foreach ($this->objects as $object_id) { + $object = $this->repository->constructObject($object_id); + $object->label = $object_id; + + $datastream = $object->constructDatastream($this->dsid, 'M'); + $datastream->label = 'fdsa'; + $datastream->mimetype = 'text/plain'; + $datastream->content = 'Some kinda awesome content stuffs...'; + + $object->ingestDatastream($datastream); + $this->repository->ingestObject($object); + } + } + + /** + * Purge any objects created by the test's in this class. + */ + public function purgeTestObjects() { + foreach ($this->objects as $object) { + try { + $object = $this->repository->getObject($object); + $this->repository->purgeObject($object->id); + } + catch (Exception $e) { + // Meh... Either it didn't exist or the purge failed. + } + } + } + + /** + * Deny an object permission check without an object. + */ + public function testDenyBadObject() { + $this->assertFalse(islandora_object_access($this->op, 'this is not an object'), 'Deny bad objects.'); + } + + /** + * Deny a datastream permission check without a datastream. + */ + public function testDenyBadDatastream() { + $this->assertFalse(islandora_datastream_access($this->op, 'this is not a datastream'), 'Deny bad datastreams.'); + } + + /** + * Allow operation on object. + */ + public function testAllowObject() { + $user = $this->drupalCreateUser(array($this->op)); + + $_SESSION['islandora_hooked_access_test'] = array( + $this->op, + $this->object, + $user, + ); + $this->assertTrue(islandora_object_access($this->op, $this->object, $user), 'Allow object access.'); + } + + /** + * Allow operation on datastream. + */ + public function testAllowDatastream() { + $user = $this->drupalCreateUser(array($this->op)); + + $_SESSION['islandora_hooked_access_test'] = array( + $this->op, + $this->object['asdf'], + $user, + ); + $this->assertTrue(islandora_datastream_access($this->op, $this->object['asdf'], $user), 'Allow datastream access.'); + } + + /** + * Deny an operation which was not explicitly allowed on an object. + */ + public function testDenyObjectImplicit() { + $user = $this->drupalCreateUser(array($this->other_op)); + + // This variable forces either a TRUE or FALSE from Islandora's + // implementation of hook_islandora_object_access(). + variable_set('islandora_strict_user_access_enforcement', FALSE); + $_SESSION['islandora_hooked_access_test'] = array( + $this->other_op, + $this->object, + $user, + ); + $this->assertFalse(islandora_object_access($this->op, $this->object, $user), 'Implied denial of object access.'); + } + + /** + * Deny an operation which was not explicitly allowed on a datastream. + */ + public function testDenyDatastreamImplicit() { + $user = $this->drupalCreateUser(array($this->other_op)); + + // This variable forces either a TRUE or FALSE from Islandora's + // implementation of hook_islandora_object_access(). + variable_set('islandora_strict_user_access_enforcement', FALSE); + + $_SESSION['islandora_hooked_access_test'] = array( + $this->other_op, + $this->object['asdf'], + $user, + ); + $this->assertFalse(islandora_datastream_access($this->op, $this->object['asdf'], $user), 'Implied denial of datastream access.'); + } + + /** + * Deny an operation which was not explicitly allowed on an object. + */ + public function testDenyObjectExplicit() { + $this->assertFalse(islandora_object_access($this->denied_op, $this->object), 'Explicit denial of object access.'); + } + + /** + * Deny an operation which was not explicitly allowed on a datastream. + */ + public function testDenyDatastreamExplicit() { + $this->assertFalse(islandora_datastream_access($this->denied_op, $this->object['asdf']), 'Explicit denial of datastream access.'); + } +} diff --git a/tests/islandora_hooked_access_test.info b/tests/islandora_hooked_access_test.info new file mode 100644 index 00000000..6c585daf --- /dev/null +++ b/tests/islandora_hooked_access_test.info @@ -0,0 +1,7 @@ +name = Islandora Hooked Access Callback testing +description = Tests callback hooks. Do not enable. +core = 7.x +package = Testing +hidden = TRUE +files[] = islandora_hooks_test.module +dependencies[] = islandora diff --git a/tests/islandora_hooked_access_test.module b/tests/islandora_hooked_access_test.module new file mode 100644 index 00000000..de417738 --- /dev/null +++ b/tests/islandora_hooked_access_test.module @@ -0,0 +1,31 @@ + Date: Tue, 11 Jun 2013 16:12:40 -0300 Subject: [PATCH 156/172] Add missing function comment. --- tests/hooked_access.test | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/hooked_access.test b/tests/hooked_access.test index 0f7610e0..90a893c7 100644 --- a/tests/hooked_access.test +++ b/tests/hooked_access.test @@ -58,6 +58,9 @@ class IslandoraHookedAccessTestCase extends IslandoraWebTestCase { parent::tearDown(); } + /** + * Create the test object(s) to use during the test. + */ public function createTestObjects() { foreach ($this->objects as $object_id) { $object = $this->repository->constructObject($object_id); From d796f2250abacb5615cbfd9b4a7bab6fa91ff8a4 Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Fri, 7 Jun 2013 03:31:35 +0200 Subject: [PATCH 157/172] Admin settings form will now display even if the Repository is not accessible. Also includes some general clean up. * Namespaces no longer uses ajax now uses states. * Abstracted out repository access message into a seperate function. * Simplified the code. --- includes/admin.form.inc | 230 +++++++++++++++++----------------------- 1 file changed, 96 insertions(+), 134 deletions(-) diff --git a/includes/admin.form.inc b/includes/admin.form.inc index a1f22652..9c215b02 100644 --- a/includes/admin.form.inc +++ b/includes/admin.form.inc @@ -19,139 +19,116 @@ function islandora_repository_admin(array $form, array &$form_state) { module_load_include('inc', 'islandora', 'includes/utilities'); drupal_add_css(drupal_get_path('module', 'islandora') . '/css/islandora.admin.css'); + $url = islandora_system_settings_form_default_value('islandora_base_url', 'http://localhost:8080/fedora', $form_state); + $restrict_namespaces = islandora_system_settings_form_default_value('islandora_namespace_restriction_enforced', FALSE, $form_state); + $confirmation_message = islandora_admin_settings_form_repository_access_message($url); + $form = array( + 'islandora_tabs' => array( + '#type' => 'vertical_tabs', + 'islandora_general' => array( + '#type' => 'fieldset', + '#title' => t('General Configuarion'), + 'wrapper' => array( + '#prefix' => '
', + '#suffix' => '
', + '#type' => 'markup', + 'islandora_base_url' => array( + '#type' => 'textfield', + '#title' => t('Fedora base URL'), + '#default_value' => variable_get('islandora_base_url', 'http://localhost:8080/fedora'), + '#description' => t('The URL to use for REST connections
!confirmation_message', array( + '!confirmation_message' => $confirmation_message)), + '#required' => TRUE, + '#ajax' => array( + 'callback' => 'islandora_update_url_div', + 'wrapper' => 'islandora-url', + 'effect' => 'fade', + 'event' => 'blur', + 'progress' => array('type' => 'throbber'), + ), + ), + ), + 'islandora_repository_pid' => array( + '#type' => 'textfield', + '#title' => t('Root Collection PID'), + '#default_value' => variable_get('islandora_repository_pid', 'islandora:root'), + '#description' => t('The PID of the Root Collection Object'), + '#required' => TRUE, + ), + ), + 'islandora_namespace' => array( + '#type' => 'fieldset', + '#title' => t('Namespaces'), + 'wrapper' => array( + '#type' => 'markup', + '#prefix' => '
', + '#suffix' => '
', + 'islandora_namespace_restriction_enforced' => array( + '#type' => 'checkbox', + '#title' => t('Enforce namespace restrictions'), + '#description' => t("Allow administrator to restrict user's access to the PID namepaces listed below"), + '#default_value' => $restrict_namespaces, + ), + 'islandora_pids_allowed' => array( + '#type' => 'textfield', + '#title' => t('PID namespaces allowed in this Drupal install'), + '#description' => t('A list of PID namespaces, separated by spaces, that users are permitted to access from this Drupal installation.
This could be more than a simple namespace, e.g. demo:mydemos.
The namespace islandora: is reserved, and is always allowed.'), + '#default_value' => variable_get('islandora_pids_allowed', 'default: demo: changeme: ilives: islandora-book: books: newspapers: '), + '#states' => array( + 'invisible' => array( + ':input[name="islandora_namespace_restriction_enforced"]' => array('checked' => FALSE), + ), + ), + ), + ), + ), + ), + ); + return system_settings_form($form); +} - $form = array(); - if (isset($form_state['values']['islandora_base_url'])) { - $url = $form_state['values']['islandora_base_url']; - } - else { - $url = variable_get('islandora_base_url', 'http://localhost:8080/fedora'); - } - +/** + * Gets a message which describes if the repository is accessible. + * + * Also describes if the user is considered an authenticated user by the + * repository. + * + * @param string $url + * The url to the Fedora Repository. + * + * @return string + * A message describing the accessibility of the repository at the given url. + */ +function islandora_admin_settings_form_repository_access_message($url) { + $info = $dc = FALSE; $connection = islandora_get_tuque_connection(NULL, $url); - if (!$connection) { - return; - } - - try { - $info = $connection->api->a->describeRepository(); - } - catch (RepositoryException $e) { - $info = FALSE; - } - - if ($info) { + if ($connection) { try { + $info = $connection->api->a->describeRepository(); + // If we are able to successfully call API-M::getDatastream, assume we are + // an authenticated user, as API-M is usally locked down. $dc = $connection->api->m->getDatastream('fedora-system:ContentModel-3.0', 'DC'); } catch (RepositoryException $e) { - $dc = FALSE; + // Ignore, we only testing to see what is accessible. } } - - if ($info) { - if ($dc) { - $confirmation_message = theme_image(array('path' => 'misc/watchdog-ok.png', 'attributes' => array())); - $confirmation_message .= t('Successfully connected to Fedora Server (Version !version).', array( - '!version' => $info['repositoryVersion'])); - } - else { - $confirmation_message = theme_image(array('path' => 'misc/watchdog-warning.png', 'attributes' => array())); - $confirmation_message .= t('Unable to authenticate when connecting to to Fedora Server (Version !version). Please configure the !filter.', - array('!version' => $info['repositoryVersion'], '!filter' => 'Drupal Filter')); - } + if ($info && $dc) { + $confirmation_message = theme_image(array('path' => 'misc/watchdog-ok.png', 'attributes' => array())); + $confirmation_message .= t('Successfully connected to Fedora Server (Version !version).', array( + '!version' => $info['repositoryVersion'])); + } + elseif ($info) { + $confirmation_message = theme_image(array('path' => 'misc/watchdog-warning.png', 'attributes' => array())); + $confirmation_message .= t('Unable to authenticate when connecting to to Fedora Server (Version !version). Please configure the !filter.', array( + '!version' => $info['repositoryVersion'], '!filter' => 'Drupal Filter')); } else { $confirmation_message = theme_image(array('path' => 'misc/watchdog-error.png', 'attributes' => array())); $confirmation_message .= t('Unable to connect to Fedora server at !islandora_url', array( '!islandora_url' => $url)); } - - $form['islandora_tabs'] = array( - '#type' => 'vertical_tabs', - ); - - $form['islandora_tabs']['islandora_general'] = array( - '#type' => 'fieldset', - '#title' => t('General Configuarion'), - ); - - // Ajax wrapper for url checking. - $form['islandora_tabs']['islandora_general']['wrapper'] = array( - '#prefix' => '
', - '#suffix' => '
', - '#type' => 'markup', - ); - - $form['islandora_tabs']['islandora_general']['wrapper']['islandora_base_url'] = array( - '#type' => 'textfield', - '#title' => t('Fedora base URL'), - '#default_value' => variable_get('islandora_base_url', 'http://localhost:8080/fedora'), - '#description' => t('The URL to use for REST connections
!confirmation_message', array( - '!confirmation_message' => $confirmation_message, - )), - '#required' => TRUE, - '#ajax' => array( - 'callback' => 'islandora_update_url_div', - 'wrapper' => 'islandora-url', - 'effect' => 'fade', - 'event' => 'blur', - 'progress' => array('type' => 'throbber'), - ), - ); - - $form['islandora_tabs']['islandora_general']['islandora_repository_pid'] = array( - '#type' => 'textfield', - '#title' => t('Root Collection PID'), - '#default_value' => variable_get('islandora_repository_pid', 'islandora:root'), - '#description' => t('The PID of the Root Collection Object'), - '#required' => TRUE, - ); - - $form['islandora_tabs']['islandora_namespace'] = array( - '#type' => 'fieldset', - '#title' => t('Namespaces'), - ); - - $form['islandora_tabs']['islandora_namespace']['wrapper'] = array( - '#type' => 'markup', - '#prefix' => '
', - '#suffix' => '
', - ); - - $form['islandora_tabs']['islandora_namespace']['wrapper']['islandora_namespace_restriction_enforced'] = array( - '#weight' => -1, - '#type' => 'checkbox', - '#title' => t('Enforce namespace restrictions'), - '#description' => t("Allow administrator to restrict user's access to the PID namepaces listed below"), - '#default_value' => variable_get('islandora_namespace_restriction_enforced', FALSE), - '#ajax' => array( - 'callback' => 'islandora_update_namespace_div', - 'wrapper' => 'islandora-namespace', - 'effect' => 'fade', - 'event' => 'change', - 'progress' => array('type' => 'throbber'), - ), - ); - - if (isset($form_state['values']['islandora_namespace_restriction_enforced'])) { - $namespaces = $form_state['values']['islandora_namespace_restriction_enforced']; - } - else { - $namespaces = variable_get('islandora_namespace_restriction_enforced', FALSE); - } - - if ($namespaces) { - $form['islandora_tabs']['islandora_namespace']['wrapper']['islandora_pids_allowed'] = array( - '#type' => 'textfield', - '#title' => t('PID namespaces allowed in this Drupal install'), - '#default_value' => variable_get('islandora_pids_allowed', 'default: demo: changeme: ilives: islandora-book: books: newspapers: '), - '#description' => t('A list of PID namespaces, separated by spaces, that users are permitted to access from this Drupal installation.
This could be more than a simple namespace, e.g. demo:mydemos.
The namespace islandora: is reserved, and is always allowed.'), - '#weight' => 0, - ); - } - - return system_settings_form($form); + return $confirmation_message; } /** @@ -168,18 +145,3 @@ function islandora_repository_admin(array $form, array &$form_state) { function islandora_update_url_div(array $form, array $form_state) { return $form['islandora_tabs']['islandora_general']['wrapper']; } - -/** - * Get the element to render for the AJAX event that triggered this callback. - * - * @param array $form - * The Drupal form definition. - * @param array $form_state - * The Drupal form state. - * - * @return array - * The form element to render. - */ -function islandora_update_namespace_div(array $form, array $form_state) { - return $form['islandora_tabs']['islandora_namespace']['wrapper']; -} From 523c2d8e9f6cce39a77370657518d61239a03e66 Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Thu, 13 Jun 2013 01:11:58 +0200 Subject: [PATCH 158/172] Removed uneeded wrapper element from namespace tab on admin config. --- includes/admin.form.inc | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/includes/admin.form.inc b/includes/admin.form.inc index 9c215b02..d34bd5d5 100644 --- a/includes/admin.form.inc +++ b/includes/admin.form.inc @@ -59,25 +59,20 @@ function islandora_repository_admin(array $form, array &$form_state) { 'islandora_namespace' => array( '#type' => 'fieldset', '#title' => t('Namespaces'), - 'wrapper' => array( - '#type' => 'markup', - '#prefix' => '
', - '#suffix' => '
', - 'islandora_namespace_restriction_enforced' => array( - '#type' => 'checkbox', - '#title' => t('Enforce namespace restrictions'), - '#description' => t("Allow administrator to restrict user's access to the PID namepaces listed below"), - '#default_value' => $restrict_namespaces, - ), - 'islandora_pids_allowed' => array( - '#type' => 'textfield', - '#title' => t('PID namespaces allowed in this Drupal install'), - '#description' => t('A list of PID namespaces, separated by spaces, that users are permitted to access from this Drupal installation.
This could be more than a simple namespace, e.g. demo:mydemos.
The namespace islandora: is reserved, and is always allowed.'), - '#default_value' => variable_get('islandora_pids_allowed', 'default: demo: changeme: ilives: islandora-book: books: newspapers: '), - '#states' => array( - 'invisible' => array( - ':input[name="islandora_namespace_restriction_enforced"]' => array('checked' => FALSE), - ), + 'islandora_namespace_restriction_enforced' => array( + '#type' => 'checkbox', + '#title' => t('Enforce namespace restrictions'), + '#description' => t("Allow administrator to restrict user's access to the PID namepaces listed below"), + '#default_value' => $restrict_namespaces, + ), + 'islandora_pids_allowed' => array( + '#type' => 'textfield', + '#title' => t('PID namespaces allowed in this Drupal install'), + '#description' => t('A list of PID namespaces, separated by spaces, that users are permitted to access from this Drupal installation.
This could be more than a simple namespace, e.g. demo:mydemos.
The namespace islandora: is reserved, and is always allowed.'), + '#default_value' => variable_get('islandora_pids_allowed', 'default: demo: changeme: ilives: islandora-book: books: newspapers: '), + '#states' => array( + 'invisible' => array( + ':input[name="islandora_namespace_restriction_enforced"]' => array('checked' => FALSE), ), ), ), From 6384036901074155fed6bb0b39ed7044be6ced74 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Fri, 14 Jun 2013 10:51:39 -0300 Subject: [PATCH 159/172] Squash ddebug_backtrace(). --- islandora.module | 3 --- 1 file changed, 3 deletions(-) diff --git a/islandora.module b/islandora.module index b4f4ca7a..58e1a3a9 100644 --- a/islandora.module +++ b/islandora.module @@ -1188,9 +1188,6 @@ function islandora_object_access($op, $object, $user = NULL) { if (!isset($cache[$op][$object->id][$user->uid])) { module_load_include('inc', 'islandora', 'includes/utilities'); - if (!($object instanceof AbstractObject)) { - ddebug_backtrace(); - } $results = islandora_invoke_hook_list('islandora_object_access', $object->models, array( $op, $object, From 9b22de0e579d659e6c3c5db6abad029f7dec1d43 Mon Sep 17 00:00:00 2001 From: Nelson Hart Date: Fri, 14 Jun 2013 13:00:01 -0300 Subject: [PATCH 160/172] getting customized menu item to use in breadcrumb --- includes/breadcrumb.inc | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/includes/breadcrumb.inc b/includes/breadcrumb.inc index 9c587442..872eb70a 100644 --- a/includes/breadcrumb.inc +++ b/includes/breadcrumb.inc @@ -58,13 +58,17 @@ function islandora_get_breadcrumbs_recursive($pid, FedoraRepository $repository, $root = variable_get('islandora_repository_pid', 'islandora:root'); if ($pid == $root) { $title = 'Islandora Repository'; - $trail = menu_get_active_trail(); - foreach ($trail as $key => $item) { - if ($item['link_path'] == 'islandora') { - $title = $item['link_title']; - break; - } + $mlid = db_select('menu_links', 'ml') + ->condition('ml.link_path', 'islandora') + ->fields('ml', array('mlid')) + ->execute() + ->fetchField(); + + if ($mlid) { + $link = menu_link_load($mlid); + $title = (isset($link['title']) ? $link['title'] : $title); } + return array( l(t('Home'), ''), l($title, 'islandora'), From daa15012924d71d0efbdb41b8a3e5cacc3a65a2a Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Wed, 19 Jun 2013 08:02:11 -0300 Subject: [PATCH 161/172] Change initial variable name. --- islandora.module | 53 ++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/islandora.module b/islandora.module index 58e1a3a9..88664bd1 100644 --- a/islandora.module +++ b/islandora.module @@ -381,7 +381,7 @@ function islandora_forms($form_id) { * * @global $user * - * @param mixed $object + * @param mixed $object_or_datastream * The AbstractObject or AbstractDatastream to test for accessibility, if NULL * is given the object is assumed to not exist or be inaccessible. * @param array $permissions @@ -392,7 +392,7 @@ function islandora_forms($form_id) { * (optional) TRUE to grant access if any single requirement is met from both * the permissions and content models parameters. FALSE if all requirements * must be met from both the permissions and content model parameters. - * @param object $account + * @param object $user * (optional) The account to check, if not given check the GET parameters for * a token to restore the user. If no GET parameter is present use currently * logged in user. @@ -401,9 +401,10 @@ function islandora_forms($form_id) { * TRUE if the user is allowed to access this object/datastream, FALSE * otherwise. */ -function islandora_user_access($object, array $permissions, $content_models = array(), $access_any = TRUE, $account = NULL) { +function islandora_user_access($object_or_datastream, array $permissions, $content_models = array(), $access_any = TRUE, $user = NULL) { module_load_include('inc', 'islandora', 'includes/utilities'); $is_repository_accessible = &drupal_static(__FUNCTION__); + // If the repository is inaccessible then access always fails. if (!isset($is_repository_accessible)) { $is_repository_accessible = islandora_describe_repository(); @@ -413,37 +414,39 @@ function islandora_user_access($object, array $permissions, $content_models = ar return FALSE; } } - if (!$is_repository_accessible || !is_object($object) || empty($permissions)) { + if (!$is_repository_accessible || !is_object($object_or_datastream) || empty($permissions)) { return FALSE; } + + // Determine what has been passed as $object. + if (is_subclass_of($object_or_datastream, 'AbstractObject')) { + $object = $object_or_datastream; + $datastream = NULL; + } + elseif (is_subclass_of($object_or_datastream, 'AbstractDatastream')) { + $datastream = $object_or_datastream; + $object = $datastream->parent; + } + // Determine the user account to test against. - if (!isset($account)) { + if (!isset($user)) { $token = filter_input(INPUT_GET, 'token', FILTER_SANITIZE_STRING); if ($token) { module_load_include('inc', 'islandora', 'includes/authtokens'); - $user = islandora_validate_object_token($object->id, $datastream->id, $token); + $token_user = islandora_validate_object_token($object->id, $datastream->id, $token); if ($user) { - $account = user_load($user->uid); + $user = user_load($token_user->uid); } } else { global $user; - $account = $user; } } - // Determine what has been passed as $object. - if (is_subclass_of($object, 'AbstractObject')) { - $datastream = NULL; - // $object stays $object... - } - elseif (is_subclass_of($object, 'AbstractDatastream')) { - $datastream = $object; - $object = $datastream->parent; - } // Check for access. if ($access_any) { - $has_required_permissions = function ($permissions, $datastream, $object, $user) { + $has_required_content_models = empty($content_models) ? TRUE : count(array_intersect($object->models, $content_models)) > 0; + if ($has_required_content_models) { foreach ($permissions as $p) { if ($datastream !== NULL) { $check = islandora_datastream_access($p, $datastream, $user); @@ -457,11 +460,11 @@ function islandora_user_access($object, array $permissions, $content_models = ar } } return FALSE; - }; - $has_required_content_models = empty($content_models) ? TRUE : count(array_intersect($object->models, $content_models)) > 0; + } } else { - $has_required_permissions = function ($permissions, $datastream, $object, $user) { + $has_required_content_models = count(array_diff($content_models, $object->models)) == 0; + if ($has_required_content_models) { foreach ($permissions as $p) { if ($datastream !== NULL) { $check = islandora_datastream_access($p, $datastream, $user); @@ -474,13 +477,11 @@ function islandora_user_access($object, array $permissions, $content_models = ar return FALSE; } } + // Should already have failed if there are no $permissions. return TRUE; - }; - $has_required_content_models = count(array_diff($content_models, $object->models)) == 0; + } } - - return $has_required_permissions($permissions, $datastream, $object, $account) && - $has_required_content_models; + return FALSE; } /** From 344a4058947d1cfc0ef3ec62168e8734b891ead9 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Wed, 19 Jun 2013 08:05:06 -0300 Subject: [PATCH 162/172] Be somewhat more descriptive in API doc. --- islandora.api.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/islandora.api.php b/islandora.api.php index aa6df5b6..129787f4 100644 --- a/islandora.api.php +++ b/islandora.api.php @@ -445,7 +445,7 @@ function hook_CMODEL_PID_islandora_ingest_steps(array $form_state) { } /** - * Hookable access hook. + * Object-level access callback hook. * * @param string $op * A string define an operation to check. Should be defined via @@ -483,7 +483,7 @@ function hook_CMODEL_PID_islandora_object_access($op, $object, $user) { } /** - * Hookable access hook. + * Datastream-level access callback hook. * * @param string $op * A string define an operation to check. Should be defined via From 6f9b7b877ac75d0fb8592e3d31ba977e9b6794bc Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Wed, 19 Jun 2013 08:09:54 -0300 Subject: [PATCH 163/172] Get rid of non-strict policy enforcement. --- includes/admin.form.inc | 7 ------- islandora.module | 21 +++------------------ 2 files changed, 3 insertions(+), 25 deletions(-) diff --git a/includes/admin.form.inc b/includes/admin.form.inc index f4db785b..a1f22652 100644 --- a/includes/admin.form.inc +++ b/includes/admin.form.inc @@ -108,13 +108,6 @@ function islandora_repository_admin(array $form, array &$form_state) { '#required' => TRUE, ); - $form['islandora_tabs']['islandora_general']['islandora_strict_user_access_enforcement'] = array( - '#type' => 'checkbox', - '#title' => t('Strict User Access Enforcement'), - '#description' => t('Restrict permissions to the result of user_access(); other modules will be able to deny things, but other modules will not be able to allow operations not allowed via Drupal permissions.'), - '#default_value' => variable_get('islandora_strict_user_access_enforcement', TRUE), - ); - $form['islandora_tabs']['islandora_namespace'] = array( '#type' => 'fieldset', '#title' => t('Namespaces'), diff --git a/islandora.module b/islandora.module index 88664bd1..58a23a10 100644 --- a/islandora.module +++ b/islandora.module @@ -1205,28 +1205,13 @@ function islandora_object_access($op, $object, $user = NULL) { /** * Implements hook_islandora_object_access(). * - * Denies according to PID namespace restrictions, passes according to - * user_access(), and makes no indication if namespace restrictions passed but - * user_access() returned a fail, to allow other modules to allow an operation. + * Denies according to PID namespace restrictions, then passes or denies + * according to core Drupal permissions according to user_access(). */ function islandora_islandora_object_access($op, $object, $user) { module_load_include('inc', 'islandora', 'includes/utilities'); - $to_return = islandora_namespace_accessible($object->id); - $user_access_result = user_access($op, $user); - - if ($to_return && $user_access_result) { - // Straight Drupal permissions, let's allow it. - return TRUE; - } - elseif ($to_return === FALSE || (variable_get('islandora_strict_user_access_enforcement', TRUE) && !$user_access_result)) { - // PID namespace is outside of those allowed. Forbid! - return FALSE; - } - else { - // Neither allowing of forbidding, to allow other modules to override. - return NULL; - } + return islandora_namespace_accessible($object->id) && user_access($op, $user); } /** From 7aa11510018ed50ff8b35ddd0ac1d42f49bad2d4 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Wed, 19 Jun 2013 08:27:48 -0300 Subject: [PATCH 164/172] Deprecate old and use new functions. --- includes/utilities.inc | 6 ++++++ islandora.module | 30 ++++++++++++++++-------------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/includes/utilities.inc b/includes/utilities.inc index 4d69155d..cc4845bf 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -673,6 +673,9 @@ function islandora_get_comp_ds_mappings($pid) { * TRUE if the account has all the given permissions, FALSE otherwise. */ function islandora_user_access_all(array $perms, $account = NULL) { + $message = islandora_deprecated('7.x-1.2', 'Roll your own code.'); + trigger_error($message, E_USER_DEPRECATED); + foreach ($perms as $perm) { if (!user_access($perm, $account)) { return FALSE; @@ -694,6 +697,9 @@ function islandora_user_access_all(array $perms, $account = NULL) { * otherwise. */ function islandora_user_access_any(array $perms, $account = NULL) { + $message = islandora_deprecated('7.x-1.2', 'Roll your own code.'); + trigger_error($message, E_USER_DEPRECATED); + foreach ($perms as $perm) { if (user_access($perm, $account)) { return TRUE; diff --git a/islandora.module b/islandora.module index 58a23a10..3c7d9419 100644 --- a/islandora.module +++ b/islandora.module @@ -190,8 +190,8 @@ function islandora_menu() { 'page arguments' => array(4, FALSE), 'type' => MENU_CALLBACK, 'file' => 'includes/datastream.inc', - 'access callback' => 'islandora_object_datastream_access_callback', - 'access arguments' => array(FEDORA_VIEW_OBJECTS, 2, 4), + 'access callback' => 'islandora_datastream_access', + 'access arguments' => array(FEDORA_VIEW_OBJECTS, 4), 'load arguments' => array(2), ); // This menu item uses token authentication in islandora_tokened_object. @@ -208,8 +208,8 @@ function islandora_menu() { 'page arguments' => array(4), 'type' => MENU_CALLBACK, 'file' => 'includes/datastream.inc', - 'access callback' => 'islandora_object_datastream_access_callback', - 'access arguments' => array(FEDORA_VIEW_OBJECTS, 2, 4), + 'access callback' => 'islandora_datastream_access', + 'access arguments' => array(FEDORA_VIEW_OBJECTS, 4), 'load arguments' => array(2), ); $items['islandora/object/%islandora_object/datastream/%islandora_datastream/edit'] = array( @@ -218,8 +218,8 @@ function islandora_menu() { 'page arguments' => array(4), 'type' => MENU_CALLBACK, 'file' => 'includes/datastream.inc', - 'access callback' => 'islandora_object_datastream_access_callback', - 'access arguments' => array(FEDORA_METADATA_EDIT, 2, 4), + 'access callback' => 'islandora_datastream_access', + 'access arguments' => array(FEDORA_METADATA_EDIT, 4), 'load arguments' => array(2), ); $items['islandora/object/%islandora_object/datastream/%islandora_datastream/delete'] = array( @@ -228,8 +228,8 @@ function islandora_menu() { 'page arguments' => array('islandora_delete_datastream_form', 4), 'file' => 'includes/delete_datastream.form.inc', 'type' => MENU_CALLBACK, - 'access callback' => 'islandora_object_datastream_access_callback', - 'access arguments' => array(FEDORA_PURGE, 2, 4), + 'access callback' => 'islandora_datastream_access', + 'access arguments' => array(FEDORA_PURGE, 4), 'load arguments' => array(2), ); $items['islandora/object/%islandora_object/print'] = array( @@ -237,7 +237,7 @@ function islandora_menu() { 'page callback' => 'islandora_print_object', 'page arguments' => array(2), 'type' => MENU_CALLBACK, - 'access callback' => 'islandora_object_access_callback', + 'access callback' => 'islandora_object_access', 'access arguments' => array(FEDORA_VIEW_OBJECTS, 2), 'load arguments' => array(2), ); @@ -245,7 +245,7 @@ function islandora_menu() { 'page callback' => 'islandora_download_clip', 'page arguments' => array(2), 'type' => MENU_CALLBACK, - 'access callback' => 'islandora_object_access_callback', + 'access callback' => 'islandora_object_access', 'access arguments' => array(FEDORA_VIEW_OBJECTS, 2), 'load arguments' => array(2), ); @@ -531,6 +531,10 @@ function islandora_object_access_callback($perm, $object = NULL) { * TRUE if the user is allowed to access this object, FALSE otherwise. */ function islandora_object_datastream_access_callback($perm, $object = NULL, $datastream = NULL, $account = NULL) { + module_load_include('inc', 'islandora', 'includes/utilities'); + $message = islandora_deprecated('7.x-1.2', 'Use islandora_datastream_access().'); + trigger_error($message, E_USER_DEPRECATED); + return islandora_datastream_access($perm, $datastream, $account); } @@ -539,10 +543,8 @@ function islandora_object_datastream_access_callback($perm, $object = NULL, $dat * * This function will validate and use a token if present in the GET parameters. * - * Checks for object existance, accessiblitly, namespace permissions, + * Checks for object existance, accessibility, namespace permissions, * and user permissions - * - * @see islandora_object_datastream_tokened_access_callback() */ function islandora_object_datastream_tokened_access_callback($perm, $object = NULL, $datastream = NULL) { module_load_include('inc', 'islandora', 'includes/utilities'); @@ -557,7 +559,7 @@ function islandora_object_datastream_tokened_access_callback($perm, $object = NU } } - return islandora_object_datastream_access_callback($perm, $object, $datastream, $token_account); + return islandora_datastream_access($perm, $datastream, $token_account); } /** From fa3449813077f7734419a5c6049e71bb81a1d7a3 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Wed, 19 Jun 2013 09:10:07 -0300 Subject: [PATCH 165/172] Themify datastream link creation. --- includes/datastream.inc | 38 +++++++++++------- islandora.module | 16 ++++++++ theme/theme.inc | 88 +++++++++++++++++++++++++++++++++++++++-- 3 files changed, 124 insertions(+), 18 deletions(-) diff --git a/includes/datastream.inc b/includes/datastream.inc index 902d5670..e8aa2fbd 100644 --- a/includes/datastream.inc +++ b/includes/datastream.inc @@ -84,9 +84,12 @@ function islandora_datastream_get_url(AbstractDatastream $datastream, $type = 'd * The datastream to generated the url to. */ function islandora_datastream_get_delete_link(AbstractDatastream $datastream) { - $datastreams = module_invoke_all('islandora_undeletable_datastreams', $datastream->parent->models); - $can_delete = !in_array($datastream->id, $datastreams) && islandora_datastream_access(FEDORA_PURGE, $datastream); - return $can_delete ? l(t('delete'), "islandora/object/{$datastream->parent->id}/datastream/{$datastream->id}/delete") : ''; + $message = islandora_deprecated('7.x-1.2', 'Use the "islandora_datastream_delete_link" theme implementation.'); + trigger_error($message, E_USER_DEPRECATED); + + return theme('islandora_datastream_delete_link', array( + 'datastream' => $datastream, + )); } /** @@ -96,9 +99,12 @@ function islandora_datastream_get_delete_link(AbstractDatastream $datastream) { * The datastream to generated the url to. */ function islandora_datastream_edit_get_link(AbstractDatastream $datastream) { - $edit_registry = module_invoke_all('islandora_edit_datastream_registry', $datastream->parent, $datastream); - $can_edit = count($edit_registry) > 0 && islandora_datastream_access(FEDORA_METADATA_EDIT, $datastream); - return $can_edit ? l(t('edit'), "islandora/object/{$datastream->parent->id}/datastream/{$datastream->id}/edit") : ''; + $message = islandora_deprecated('7.x-1.2', 'Use the "islandora_datastream_edit_link" theme implementation.'); + trigger_error($message, E_USER_DEPRECATED); + + return theme('islandora_datastream_edit_link', array( + 'datastream' => $datastream, + )); } /** @@ -156,10 +162,12 @@ function islandora_edit_datastream_registry_render(array $edit_registry) { * user is not allowed to see the given datastream. */ function islandora_datastream_get_download_link(AbstractDatastream $datastream) { - $label = t('download'); - return islandora_datastream_access(FEDORA_VIEW_OBJECTS, $datastream) ? - l($label, islandora_datastream_get_url($datastream, 'download')) : - ''; + $message = islandora_deprecated('7.x-1.2', 'Use the "islandora_datastream_download_link" theme implementation.'); + trigger_error($message, E_USER_DEPRECATED); + + return theme('islandora_datastream_download_link', array( + 'datastream' => $datastream, + )); } /** @@ -173,8 +181,10 @@ function islandora_datastream_get_download_link(AbstractDatastream $datastream) * datastream ID if the user is not allowed to see the given datastream. */ function islandora_datastream_get_view_link(AbstractDatastream $datastream) { - $label = check_plain($datastream->id); - return islandora_datastream_access(FEDORA_VIEW_OBJECTS, $datastream) ? - l($label, islandora_datastream_get_url($datastream, 'view')) : - $label; + $message = islandora_deprecated('7.x-1.2', 'Use the "islandora_datastream_view_link" theme implementation.'); + trigger_error($message, E_USER_DEPRECATED); + + return theme('islandora_datastream_view_link', array( + 'datastream' => $datastream, + )); } diff --git a/islandora.module b/islandora.module index 3c7d9419..baa1460c 100644 --- a/islandora.module +++ b/islandora.module @@ -322,6 +322,22 @@ function islandora_theme() { 'template' => 'theme/islandora-objects-list', 'variables' => array('objects' => NULL), ), + 'islandora_datastream_edit_link' => array( + 'file' => 'theme/theme.inc', + 'variables' => array('datastream' => NULL), + ), + 'islandora_datastream_delete_link' => array( + 'file' => 'theme/theme.inc', + 'variables' => array('datastream' => NULL), + ), + 'islandora_datastream_view_link' => array( + 'file' => 'theme/theme.inc', + 'variables' => array('datastream' => NULL), + ), + 'islandora_datastream_download_link' => array( + 'file' => 'theme/theme.inc', + 'variables' => array('datastream' => NULL), + ), ); } diff --git a/theme/theme.inc b/theme/theme.inc index ce6f2659..cf048745 100644 --- a/theme/theme.inc +++ b/theme/theme.inc @@ -29,7 +29,9 @@ function islandora_preprocess_islandora_default_edit(array &$variables) { $rows[] = array( array( 'class' => 'datastream-id', - 'data' => islandora_datastream_get_view_link($ds), + 'data' => theme('islandora_datastream_view_link', array( + 'datastream' => $ds, + )), ), array( 'class' => 'datastream-label', @@ -49,15 +51,21 @@ function islandora_preprocess_islandora_default_edit(array &$variables) { ), array( 'class' => 'datastream-download', - 'data' => islandora_datastream_get_download_link($ds), + 'data' => theme('islandora_datastream_download_link', array( + 'datastream' => $ds, + )), ), array( 'class' => 'datstream-edit', - 'data' => islandora_datastream_edit_get_link($ds), + 'data' => theme('islandora_datastream_edit_link', array( + 'datastream' => $ds, + )), ), array( 'class' => 'datastream-delete', - 'data' => islandora_datastream_get_delete_link($ds), + 'data' => theme('islandora_datastream_delete_link', array( + 'datastream' => $ds, + )), ), ); } @@ -224,3 +232,75 @@ function islandora_preprocess_islandora_objects(array &$variables) { $module_path = drupal_get_path('module', 'islandora'); drupal_add_css("$module_path/css/islandora.objects.css"); } + +/** + * Renders a link to allow downloading of a datatream. + * + * @param array $vars + * An array containing: + * - datastream: An AbstractDatastream for which to generate a download link. + */ +function theme_islandora_datastream_download_link(array $vars) { + $datastream = $vars['datastream']; + module_load_include('inc', 'islandora', 'includes/utilities'); + + $label = t('download'); + return islandora_datastream_access(FEDORA_VIEW_OBJECTS, $datastream) ? + l($label, islandora_datastream_get_url($datastream, 'download')) : + ''; +} + +/** + * Renders a link to allow viewing of a datatream. + * + * @param array $vars + * An array containing: + * - datastream: An AbstractDatastream for which to generate a view link. + */ +function theme_islandora_datastream_view_link(array $vars) { + $datastream = $vars['datastream']; + module_load_include('inc', 'islandora', 'includes/utilities'); + + $label = check_plain($datastream->label); + return islandora_datastream_access(FEDORA_VIEW_OBJECTS, $datastream) ? + l($label, islandora_datastream_get_url($datastream, 'view')) : + $label; +} + +/** + * Renders a link to allow deleting of a datatream. + * + * @param array $vars + * An array containing: + * - datastream: An AbstractDatastream for which to generate a delete link. + */ +function theme_islandora_datastream_delete_link(array $vars) { + $datastream = $vars['datastream']; + + $datastreams = module_invoke_all('islandora_undeletable_datastreams', $datastream->parent->models); + + $can_delete = !in_array($datastream->id, $datastreams) && islandora_datastream_access(FEDORA_PURGE, $datastream); + + return $can_delete ? + l(t('delete'), "islandora/object/{$datastream->parent->id}/datastream/{$datastream->id}/delete") : + ''; +} + +/** + * Renders a link to allow editing of a datatream. + * + * @param array $vars + * An array containing: + * - datastream: An AbstractDatastream for which to generate a edit link. + */ +function theme_islandora_datastream_edit_link(array $vars) { + $datastream = $vars['datastream']; + + $edit_registry = module_invoke_all('islandora_edit_datastream_registry', $datastream->parent, $datastream); + + $can_edit = count($edit_registry) > 0 && islandora_datastream_access(FEDORA_METADATA_EDIT, $datastream); + + return $can_edit ? + l(t('edit'), "islandora/object/{$datastream->parent->id}/datastream/{$datastream->id}/edit") : + ''; +} From 6d677c4319c4ca1a5b500db7af5e0452166d8ed0 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Wed, 19 Jun 2013 09:11:54 -0300 Subject: [PATCH 166/172] Get rid of implicit denial tests. Variable no longer exists, so these are no longer useful. --- tests/hooked_access.test | 35 ----------------------------------- 1 file changed, 35 deletions(-) diff --git a/tests/hooked_access.test b/tests/hooked_access.test index 90a893c7..0039460e 100644 --- a/tests/hooked_access.test +++ b/tests/hooked_access.test @@ -133,41 +133,6 @@ class IslandoraHookedAccessTestCase extends IslandoraWebTestCase { $this->assertTrue(islandora_datastream_access($this->op, $this->object['asdf'], $user), 'Allow datastream access.'); } - /** - * Deny an operation which was not explicitly allowed on an object. - */ - public function testDenyObjectImplicit() { - $user = $this->drupalCreateUser(array($this->other_op)); - - // This variable forces either a TRUE or FALSE from Islandora's - // implementation of hook_islandora_object_access(). - variable_set('islandora_strict_user_access_enforcement', FALSE); - $_SESSION['islandora_hooked_access_test'] = array( - $this->other_op, - $this->object, - $user, - ); - $this->assertFalse(islandora_object_access($this->op, $this->object, $user), 'Implied denial of object access.'); - } - - /** - * Deny an operation which was not explicitly allowed on a datastream. - */ - public function testDenyDatastreamImplicit() { - $user = $this->drupalCreateUser(array($this->other_op)); - - // This variable forces either a TRUE or FALSE from Islandora's - // implementation of hook_islandora_object_access(). - variable_set('islandora_strict_user_access_enforcement', FALSE); - - $_SESSION['islandora_hooked_access_test'] = array( - $this->other_op, - $this->object['asdf'], - $user, - ); - $this->assertFalse(islandora_datastream_access($this->op, $this->object['asdf'], $user), 'Implied denial of datastream access.'); - } - /** * Deny an operation which was not explicitly allowed on an object. */ From 09e9785ecfd4ad1b305f5a244101c9925d676cc5 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Wed, 19 Jun 2013 09:45:42 -0300 Subject: [PATCH 167/172] Add filter_xss() to trigger_error() calls... Hurray coder! :P --- includes/datastream.inc | 8 ++++---- includes/utilities.inc | 8 ++++---- islandora.module | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/includes/datastream.inc b/includes/datastream.inc index e8aa2fbd..dc01bdfe 100644 --- a/includes/datastream.inc +++ b/includes/datastream.inc @@ -85,7 +85,7 @@ function islandora_datastream_get_url(AbstractDatastream $datastream, $type = 'd */ function islandora_datastream_get_delete_link(AbstractDatastream $datastream) { $message = islandora_deprecated('7.x-1.2', 'Use the "islandora_datastream_delete_link" theme implementation.'); - trigger_error($message, E_USER_DEPRECATED); + trigger_error(filter_xss($message), E_USER_DEPRECATED); return theme('islandora_datastream_delete_link', array( 'datastream' => $datastream, @@ -100,7 +100,7 @@ function islandora_datastream_get_delete_link(AbstractDatastream $datastream) { */ function islandora_datastream_edit_get_link(AbstractDatastream $datastream) { $message = islandora_deprecated('7.x-1.2', 'Use the "islandora_datastream_edit_link" theme implementation.'); - trigger_error($message, E_USER_DEPRECATED); + trigger_error(filter_xss($message), E_USER_DEPRECATED); return theme('islandora_datastream_edit_link', array( 'datastream' => $datastream, @@ -163,7 +163,7 @@ function islandora_edit_datastream_registry_render(array $edit_registry) { */ function islandora_datastream_get_download_link(AbstractDatastream $datastream) { $message = islandora_deprecated('7.x-1.2', 'Use the "islandora_datastream_download_link" theme implementation.'); - trigger_error($message, E_USER_DEPRECATED); + trigger_error(filter_xss($message), E_USER_DEPRECATED); return theme('islandora_datastream_download_link', array( 'datastream' => $datastream, @@ -182,7 +182,7 @@ function islandora_datastream_get_download_link(AbstractDatastream $datastream) */ function islandora_datastream_get_view_link(AbstractDatastream $datastream) { $message = islandora_deprecated('7.x-1.2', 'Use the "islandora_datastream_view_link" theme implementation.'); - trigger_error($message, E_USER_DEPRECATED); + trigger_error(filter_xss($message), E_USER_DEPRECATED); return theme('islandora_datastream_view_link', array( 'datastream' => $datastream, diff --git a/includes/utilities.inc b/includes/utilities.inc index cc4845bf..38e7666f 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -673,8 +673,8 @@ function islandora_get_comp_ds_mappings($pid) { * TRUE if the account has all the given permissions, FALSE otherwise. */ function islandora_user_access_all(array $perms, $account = NULL) { - $message = islandora_deprecated('7.x-1.2', 'Roll your own code.'); - trigger_error($message, E_USER_DEPRECATED); + $message = islandora_deprecated('7.x-1.2', 'Roll your own code or use islandora_user_access().'); + trigger_error(filter_xss($message), E_USER_DEPRECATED); foreach ($perms as $perm) { if (!user_access($perm, $account)) { @@ -697,8 +697,8 @@ function islandora_user_access_all(array $perms, $account = NULL) { * otherwise. */ function islandora_user_access_any(array $perms, $account = NULL) { - $message = islandora_deprecated('7.x-1.2', 'Roll your own code.'); - trigger_error($message, E_USER_DEPRECATED); + $message = islandora_deprecated('7.x-1.2', 'Roll your own code or use islandora_user_access().'); + trigger_error(filter_xss($message), E_USER_DEPRECATED); foreach ($perms as $perm) { if (user_access($perm, $account)) { diff --git a/islandora.module b/islandora.module index baa1460c..ba6d972e 100644 --- a/islandora.module +++ b/islandora.module @@ -549,7 +549,7 @@ function islandora_object_access_callback($perm, $object = NULL) { function islandora_object_datastream_access_callback($perm, $object = NULL, $datastream = NULL, $account = NULL) { module_load_include('inc', 'islandora', 'includes/utilities'); $message = islandora_deprecated('7.x-1.2', 'Use islandora_datastream_access().'); - trigger_error($message, E_USER_DEPRECATED); + trigger_error(filter_xss($message), E_USER_DEPRECATED); return islandora_datastream_access($perm, $datastream, $account); } From a99cce882f829ae285a8d68b55a4887bd1b23dbd Mon Sep 17 00:00:00 2001 From: phil Date: Wed, 19 Jun 2013 16:28:18 -0300 Subject: [PATCH 168/172] added title callback to change the drupal title --- islandora.module | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/islandora.module b/islandora.module index 7e1936c3..f211b130 100644 --- a/islandora.module +++ b/islandora.module @@ -94,7 +94,8 @@ function islandora_menu() { 'access arguments' => array(FEDORA_VIEW_OBJECTS), ); $items['islandora/object/%islandora_object'] = array( - 'title' => 'Repository', + 'title callback' => 'islandora_drupal_title', + 'title arguments' => array(2), 'page callback' => 'islandora_view_object', 'page arguments' => array(2), 'type' => MENU_NORMAL_ITEM, @@ -755,6 +756,25 @@ function islandora_view_object(AbstractObject $object) { return implode('', $output); } + +/** + * Title callback for drupal title. + * + * Changes the drupal title to be the objects label. + * models that their modules want to provide a view for. + * + * @param AbstractObject $object + * The object to view. + * + * @return string + * The objects label. + */ +function islandora_drupal_title(AbstractObject $object) { + module_load_include('inc', 'islandora', 'includes/breadcrumb'); + drupal_set_breadcrumb(islandora_get_breadcrumbs($object)); + + return $object->label; +} /** * Renders the default view object page for the given object. * From acc142b8d93f39ae918dcc2b929d107a0d1370d8 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Thu, 20 Jun 2013 09:23:15 -0300 Subject: [PATCH 169/172] Implement basic collection filter hook for namespaces. --- islandora.module | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/islandora.module b/islandora.module index 7e1936c3..ea4050f7 100644 --- a/islandora.module +++ b/islandora.module @@ -1319,3 +1319,17 @@ function islandora_datastream_access($op, $datastream, $user = NULL) { return $cache[$op][$datastream->parent->id][$datastream->id][$user->uid]; } + +/* + * Implements hook_islandora_basic_collection_get_filters(). + */ +function islandora_islandora_basic_collection_get_filters() { + $enforced = variable_get('islandora_namespace_restriction_enforced', FALSE); + if ($enforced) { + $namespace_array = islandora_get_allowed_namespaces(); + $namespace_sparql = implode('|', $namespace_array); + return format_string('regex(str(?object), "info:fedora/(!namespaces):")', array( + '!namespaces' => $namespace_sparql, + )); + } +} From 0f00f43f9910c443d1f740daa511706e90b50d08 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Thu, 20 Jun 2013 09:33:42 -0300 Subject: [PATCH 170/172] Fix function comment (parsing)... --- islandora.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/islandora.module b/islandora.module index ea4050f7..2324af5d 100644 --- a/islandora.module +++ b/islandora.module @@ -1320,7 +1320,7 @@ function islandora_datastream_access($op, $datastream, $user = NULL) { return $cache[$op][$datastream->parent->id][$datastream->id][$user->uid]; } -/* +/** * Implements hook_islandora_basic_collection_get_filters(). */ function islandora_islandora_basic_collection_get_filters() { From 08162d0ad520844639ac953f5d7de84560950fca Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Thu, 20 Jun 2013 13:52:53 -0300 Subject: [PATCH 171/172] Fix the link text... Some tests depend on it. --- theme/theme.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/theme/theme.inc b/theme/theme.inc index cf048745..f07f95d4 100644 --- a/theme/theme.inc +++ b/theme/theme.inc @@ -261,7 +261,7 @@ function theme_islandora_datastream_view_link(array $vars) { $datastream = $vars['datastream']; module_load_include('inc', 'islandora', 'includes/utilities'); - $label = check_plain($datastream->label); + $label = check_plain($datastream->id); return islandora_datastream_access(FEDORA_VIEW_OBJECTS, $datastream) ? l($label, islandora_datastream_get_url($datastream, 'view')) : $label; From 5884812486522804cbd588315190e37801efa820 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Thu, 20 Jun 2013 14:38:41 -0300 Subject: [PATCH 172/172] Fix hook implementation. ... Function was name inappropriately... Herp derp. --- islandora.module | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/islandora.module b/islandora.module index 2324af5d..174ba5fa 100644 --- a/islandora.module +++ b/islandora.module @@ -1321,9 +1321,9 @@ function islandora_datastream_access($op, $datastream, $user = NULL) { } /** - * Implements hook_islandora_basic_collection_get_filters(). + * Implements hook_islandora_basic_collection_get_query_filters(). */ -function islandora_islandora_basic_collection_get_filters() { +function islandora_islandora_basic_collection_get_query_filters() { $enforced = variable_get('islandora_namespace_restriction_enforced', FALSE); if ($enforced) { $namespace_array = islandora_get_allowed_namespaces();