Browse Source

Merge pull request #222 from willtp87/7.x

islandora_check_object_status now handling Fedora's whitespacing
pull/223/merge
Jonathan Green 12 years ago
parent
commit
ddd584ec44
  1. 18
      includes/solution_packs.inc

18
includes/solution_packs.inc

@ -253,8 +253,7 @@ function islandora_install_solution_pack($module, $op = 'install') {
return;
}
$connection = islandora_get_tuque_connection();
$islandora_required_objects = $module . '_islandora_required_objects';
$required_objects = $islandora_required_objects($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',
@ -322,8 +321,7 @@ function islandora_uninstall_solution_pack($module) {
return;
}
$connection = islandora_get_tuque_connection();
$islandora_required_objects = $module . '_islandora_required_objects';
$required_objects = $islandora_required_objects($connection);
$required_objects = module_invoke($module, 'islandora_required_objects', $connection);
$objects = $required_objects[$module]['objects'];
$existing_objects = array_filter($objects, function($o) use($connection) {
$param = "pid={$o->id}";
@ -379,6 +377,7 @@ function islandora_check_object_status(NewFedoraObject $object_definition) {
$out_of_date_datastreams[] = $ds->id;
}
}
if (count($out_of_date_datastreams)) {
$status_friendly = format_plural(count($out_of_date_datastreams), 'Datastream out of date: %dsids.', 'Datastreams out of date: %dsids.', array('%dsids' => implode(', ', $out_of_date_datastreams)));
return array('status' => 'out_of_date', 'status_friendly' => $status_friendly, 'data' => $out_of_date_datastreams);
@ -388,18 +387,23 @@ function islandora_check_object_status(NewFedoraObject $object_definition) {
// performance trouble, we should maybe remove this.
$modified_datastreams = array();
foreach ($object_definition as $ds) {
if($ds->mimetype == 'text/xml' || $ds->mimetype == 'application/rdf+xml') {
if ($ds->mimetype == 'text/xml'
|| $ds->mimetype == 'application/rdf+xml'
|| $ds->mimetype == 'application/xml') {
// If the datastream is XML we use the domdocument C14N cannonicalization
// function to test if they are equal, because the strings likely won't
// 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.
$object_definition_dom = new DOMDocument();
$object_definition_dom->preserveWhiteSpace = FALSE;
$object_definition_dom->loadXML(str_replace('info:', 'http://', $ds->content));
$object_actual_dom = new DOMDocument();
$object_actual_dom->preserveWhiteSpace = FALSE;
$object_actual_dom->loadXML(str_replace('info:', 'http://', $existing_object[$ds->id]->content));
// We have to use the shutup function here. C14N throws warnings about the
// info:fedora namespace, but they are mostly useless.
// Fedora changes the xml structure so we need to cannonize it.
if ($object_actual_dom->C14N() != $object_definition_dom->C14N()) {
$modified_datastreams[] = $ds->id;
}

Loading…
Cancel
Save