From 7bdb11e355feee7aff0626f5f7ac404347ff7005 Mon Sep 17 00:00:00 2001 From: jonathangreen Date: Thu, 4 Jul 2013 10:48:40 -0300 Subject: [PATCH 1/7] Make travis test against 3.6.2 --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index adedf7b1..4498a8fa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,7 @@ branches: - 7.x env: - FEDORA_VERSION="3.5" + - FEDORA_VERSION="3.6.2" before_install: - export ISLANDORA_DIR=$TRAVIS_BUILD_DIR - $TRAVIS_BUILD_DIR/tests/scripts/travis_setup.sh From 69216abc810ad0eaf6f8f7f4797ebe07b56ad567 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Tue, 9 Jul 2013 16:21:21 +0000 Subject: [PATCH 2/7] Use renderable arrays instead of the array of strings we used to. ... Arrays of strings are still supported... Just not encouraged. --- includes/utilities.inc | 35 +++++++++++++++++++++++++++++++++++ islandora.module | 21 +++++++++++++++------ 2 files changed, 50 insertions(+), 6 deletions(-) diff --git a/includes/utilities.inc b/includes/utilities.inc index 66c03d26..29f450b1 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -865,3 +865,38 @@ function islandora_deprecated($release, $solution = NULL) { } return $message; } + +/** + * Transform recursively-merged array of strings to renderable arrays. + * + * Previously, functions/hooks like islandora_view_object would return an + * associative array with string values containing markup. These values were + * then imploded into one large piece of markup. Here, we transform this older + * structure which was generated into a renderable array, because renderable + * arrays are awesome! + * + * @param array $markup_array + * An associative array of which the values are either a string or an array + * of strings, which we transform to renderable markup elements (by + * reference). + */ +function islandora_array_of_markup_to_renderable_array(&$markup_array) { + foreach ($markup_array as &$value) { + if (!is_array($value)) { + $value = array( + '#markup' => $value, + ); + } + else { + foreach ($value as &$inner) { + if (!is_array($inner)) { + $inner = array( + '#markup' => $inner, + ); + } + } + unset($inner); + } + } + unset($value); +} diff --git a/islandora.module b/islandora.module index c579580c..8f552f37 100644 --- a/islandora.module +++ b/islandora.module @@ -624,6 +624,7 @@ function islandora_manage_overview_object(AbstractObject $object) { $output = array(); foreach (islandora_build_hook_list(ISLANDORA_OVERVIEW_HOOK, $object->models) as $hook) { $temp = module_invoke_all($hook, $object); + islandora_array_of_markup_to_renderable_array($temp); if (!empty($temp)) { $output = array_merge_recursive($output, $temp); } @@ -634,7 +635,7 @@ function islandora_manage_overview_object(AbstractObject $object) { } arsort($output); drupal_alter(ISLANDORA_OVERVIEW_HOOK, $object, $output); - return implode('', $output); + return $output; } /** @@ -649,7 +650,9 @@ function islandora_manage_overview_object(AbstractObject $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); + return array('Default overview output' => array( + '#markup' => $output, + )); } /** @@ -675,6 +678,7 @@ function islandora_edit_object(AbstractObject $object) { $output = array(); foreach (islandora_build_hook_list(ISLANDORA_EDIT_HOOK, $object->models) as $hook) { $temp = module_invoke_all($hook, $object); + islandora_array_of_markup_to_renderable_array($temp); if (!empty($temp)) { $output = array_merge_recursive($output, $temp); } @@ -685,7 +689,7 @@ function islandora_edit_object(AbstractObject $object) { } arsort($output); drupal_alter(ISLANDORA_EDIT_HOOK, $object, $output); - return implode('', $output); + return $output; } /** @@ -700,7 +704,9 @@ function islandora_edit_object(AbstractObject $object) { */ function islandora_default_islandora_edit_object(AbstractObject $object) { $output = theme('islandora_default_edit', array('islandora_object' => $object)); - return array('Default Edit output' => $output); + return array('Default Edit output' => array( + '#markup' => $output, + )); } /** @@ -743,6 +749,7 @@ function islandora_view_object(AbstractObject $object) { // @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); + islandora_array_of_markup_to_renderable_array($temp); if (!empty($temp)) { $output = array_merge_recursive($output, $temp); } @@ -753,7 +760,7 @@ function islandora_view_object(AbstractObject $object) { } arsort($output); drupal_alter($hooks, $object, $output); - return implode('', $output); + return $output; } @@ -786,7 +793,9 @@ function islandora_drupal_title(AbstractObject $object) { */ function islandora_default_islandora_view_object($object) { $output = theme('islandora_default', array('islandora_object' => $object)); - return array('Default output' => $output); + return array('Default output' => array( + '#markup' => $output, + )); } /** From c5680fd1e062510a1619ed6d408113ba89351251 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Tue, 9 Jul 2013 17:43:45 +0000 Subject: [PATCH 3/7] Change function name and slightly safer logic. --- includes/utilities.inc | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/includes/utilities.inc b/includes/utilities.inc index 29f450b1..5ce2ca14 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -869,6 +869,8 @@ function islandora_deprecated($release, $solution = NULL) { /** * Transform recursively-merged array of strings to renderable arrays. * + * Renderable arrays are passed-through as-is. + * * Previously, functions/hooks like islandora_view_object would return an * associative array with string values containing markup. These values were * then imploded into one large piece of markup. Here, we transform this older @@ -880,16 +882,24 @@ function islandora_deprecated($release, $solution = NULL) { * of strings, which we transform to renderable markup elements (by * reference). */ -function islandora_array_of_markup_to_renderable_array(&$markup_array) { +function islandora_as_renderable_array(&$markup_array) { foreach ($markup_array as &$value) { if (!is_array($value)) { + // Not a renderable array, just a string. Let's convert it to a + // renderable '#markup' element. $value = array( '#markup' => $value, ); } - else { + elseif (!isset($value['#type']) && !isset($value['#markup'])) { + // A simple array--possibly the result of a recursive merge? Let's + // look at each, to possibly convert them to a renderable '#markup' + // elements. foreach ($value as &$inner) { if (!is_array($inner)) { + // If it is an array at this level, we can assume that it is a + // renderable array. If it is not an array, convert to a renderable + // '#markup' element. $inner = array( '#markup' => $inner, ); From e6fe09947806fb8c095b857dd747669bee73a628 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Tue, 9 Jul 2013 17:46:36 +0000 Subject: [PATCH 4/7] Carry through through the function rename. Also, be sure to call the transformer function after the alter, just in case a modules adds in another value in the manner it used to use 'em. --- islandora.module | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/islandora.module b/islandora.module index 8f552f37..574aef51 100644 --- a/islandora.module +++ b/islandora.module @@ -624,7 +624,7 @@ function islandora_manage_overview_object(AbstractObject $object) { $output = array(); foreach (islandora_build_hook_list(ISLANDORA_OVERVIEW_HOOK, $object->models) as $hook) { $temp = module_invoke_all($hook, $object); - islandora_array_of_markup_to_renderable_array($temp); + islandora_as_renderable_array($temp); if (!empty($temp)) { $output = array_merge_recursive($output, $temp); } @@ -635,6 +635,7 @@ function islandora_manage_overview_object(AbstractObject $object) { } arsort($output); drupal_alter(ISLANDORA_OVERVIEW_HOOK, $object, $output); + islandora_as_renderable_array($output); return $output; } @@ -678,7 +679,7 @@ function islandora_edit_object(AbstractObject $object) { $output = array(); foreach (islandora_build_hook_list(ISLANDORA_EDIT_HOOK, $object->models) as $hook) { $temp = module_invoke_all($hook, $object); - islandora_array_of_markup_to_renderable_array($temp); + islandora_as_renderable_array($temp); if (!empty($temp)) { $output = array_merge_recursive($output, $temp); } @@ -689,6 +690,7 @@ function islandora_edit_object(AbstractObject $object) { } arsort($output); drupal_alter(ISLANDORA_EDIT_HOOK, $object, $output); + islandora_as_renderable_array($output); return $output; } @@ -749,7 +751,7 @@ function islandora_view_object(AbstractObject $object) { // @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); - islandora_array_of_markup_to_renderable_array($temp); + islandora_as_renderable_array($temp); if (!empty($temp)) { $output = array_merge_recursive($output, $temp); } @@ -760,6 +762,7 @@ function islandora_view_object(AbstractObject $object) { } arsort($output); drupal_alter($hooks, $object, $output); + islandora_as_renderable_array($output); return $output; } From cde90385b23c175a6c2fd6ba5b296971542b04be Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Tue, 9 Jul 2013 18:49:48 +0000 Subject: [PATCH 5/7] Fix code standard issues. --- islandora.module | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/islandora.module b/islandora.module index 574aef51..5b45fb1a 100644 --- a/islandora.module +++ b/islandora.module @@ -651,9 +651,11 @@ function islandora_manage_overview_object(AbstractObject $object) { */ function islandora_default_islandora_manage_overview_object(AbstractObject $object) { $output = theme('islandora_default_overview', array('islandora_object' => $object)); - return array('Default overview output' => array( - '#markup' => $output, - )); + return array( + 'Default overview output' => array( + '#markup' => $output, + ), + ); } /** @@ -706,9 +708,11 @@ function islandora_edit_object(AbstractObject $object) { */ function islandora_default_islandora_edit_object(AbstractObject $object) { $output = theme('islandora_default_edit', array('islandora_object' => $object)); - return array('Default Edit output' => array( - '#markup' => $output, - )); + return array( + 'Default Edit output' => array( + '#markup' => $output, + ), + ); } /** @@ -796,9 +800,11 @@ function islandora_drupal_title(AbstractObject $object) { */ function islandora_default_islandora_view_object($object) { $output = theme('islandora_default', array('islandora_object' => $object)); - return array('Default output' => array( - '#markup' => $output, - )); + return array( + 'Default output' => array( + '#markup' => $output, + ), + ); } /** From 6cc205ec1a390b7eca63a6983778e2c8a9c21caa Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Mon, 22 Jul 2013 12:54:55 +0200 Subject: [PATCH 6/7] Attempt to normalize XML data-streams when comparing for equality. Used during solution install/reinstall to determine if changes have been made. Fedora selectively strips newline characters within actual content. Now we normalize the two data-streams such that all newlines are made spaces and any preceding/trailing white-space within the document is removed. For Issue: https://dgi.ontimenow.com/viewitem.aspx?id=1989&type=features&force_use_number=false --- includes/solution_packs.inc | 6 ++++++ xml/strip_newlines_and_whitespace.xsl | 13 +++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 xml/strip_newlines_and_whitespace.xsl diff --git a/includes/solution_packs.inc b/includes/solution_packs.inc index 26bd77b5..18169562 100644 --- a/includes/solution_packs.inc +++ b/includes/solution_packs.inc @@ -431,12 +431,18 @@ function islandora_check_object_status(AbstractObject $object_definition) { // we need to replace the info:fedora namespace, as C14N hates it. // C14N also doesn't normalize whitespace at the end of lines and Fedora // may add some whitespace on some lines. + $xsl = new DOMDocument(); + $xsl->load(drupal_get_path('module', 'islandora') . '/xml/strip_newlines_and_whitespace.xsl'); + $xslt = new XSLTProcessor(); + $xslt->importStyleSheet($xsl); $object_definition_dom = new DOMDocument(); $object_definition_dom->preserveWhiteSpace = FALSE; $object_definition_dom->loadXML(str_replace('info:', 'http://', $ds->content)); + $object_definition_dom = $xslt->transformToDoc($object_definition_dom); $object_actual_dom = new DOMDocument(); $object_actual_dom->preserveWhiteSpace = FALSE; $object_actual_dom->loadXML(str_replace('info:', 'http://', $existing_object[$ds->id]->content)); + $object_actual_dom = $xslt->transformToDoc($object_actual_dom); // Fedora changes the xml structure so we need to cannonize it. if ($object_actual_dom->C14N() != $object_definition_dom->C14N()) { diff --git a/xml/strip_newlines_and_whitespace.xsl b/xml/strip_newlines_and_whitespace.xsl new file mode 100644 index 00000000..4d4e1057 --- /dev/null +++ b/xml/strip_newlines_and_whitespace.xsl @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file From c21ec669f66ffe57dbfa7f0b45bb9780f3cd22f1 Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Tue, 23 Jul 2013 00:59:32 +0200 Subject: [PATCH 7/7] Updated comment --- includes/solution_packs.inc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/includes/solution_packs.inc b/includes/solution_packs.inc index 18169562..72749d0d 100644 --- a/includes/solution_packs.inc +++ b/includes/solution_packs.inc @@ -430,7 +430,9 @@ function islandora_check_object_status(AbstractObject $object_definition) { // be equal as Fedora does some XML mangling. In order for C14N to work // we need to replace the info:fedora namespace, as C14N hates it. // C14N also doesn't normalize whitespace at the end of lines and Fedora - // may add some whitespace on some lines. + // will sometimes replace new-lines with white-space. So first we strip + // leading/tailing white-space and replace all new-lines within the xml + // document to account for Fedora's weird formatting. $xsl = new DOMDocument(); $xsl->load(drupal_get_path('module', 'islandora') . '/xml/strip_newlines_and_whitespace.xsl'); $xslt = new XSLTProcessor();