From 24cb55c7261b723f4d26de2af2311bb7c373254b Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Thu, 6 Feb 2014 16:17:23 -0400 Subject: [PATCH 1/7] wrapped command to avoid errors for uninstalled objects --- islandora.drush.inc | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/islandora.drush.inc b/islandora.drush.inc index acf3994f..4013c9a6 100644 --- a/islandora.drush.inc +++ b/islandora.drush.inc @@ -177,23 +177,25 @@ function drush_islandora_solution_pack_install_content_models() { $objects_to_add = array(); foreach ($info['objects'] as $key => $candidate) { $object = islandora_object_load($candidate); - if (in_array('fedora-system:ContentModel-3.0', $object->models)) { + if ($object && in_array('fedora-system:ContentModel-3.0', $object->models)) { $objects_to_add[] = $candidate; } } - foreach ($objects_to_add as $object_to_add) { - $old_object = islandora_object_load($object_to_add->id); - if ($old_object) { - $deleted = islandora_delete_object($old_object); - if (!$deleted) { - drush_log(dt('@object did not delete.', array('@object' => $old_object->id), 'error')); - continue; + if (count($objects_to_add) > 0) { + foreach ($objects_to_add as $object_to_add) { + $old_object = islandora_object_load($object_to_add->id); + if ($old_object) { + $deleted = islandora_delete_object($old_object); + if (!$deleted) { + drush_log(dt('@object did not delete.', array('@object' => $old_object->id), 'error')); + continue; + } + } + $new_object = islandora_add_object($object_to_add); + $verb = $deleted ? dt("Replaced") : dt("Added"); + if ($new_object) { + drush_log("$verb " . $object_to_add->id . " - " . $object_to_add->label); } - } - $new_object = islandora_add_object($object_to_add); - $verb = $deleted ? dt("Replaced") : dt("Added"); - if ($new_object) { - drush_log("$verb " . $object_to_add->id . " - " . $object_to_add->label); } } } From dcc81b1fcde787c7e6f6b3c695abf61a482e0304 Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Thu, 11 Sep 2014 11:26:32 -0300 Subject: [PATCH 2/7] added islandora xml default for datastrram replacement --- includes/datastream.version.inc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/includes/datastream.version.inc b/includes/datastream.version.inc index 83a94aef..bd0b8942 100644 --- a/includes/datastream.version.inc +++ b/includes/datastream.version.inc @@ -275,6 +275,7 @@ function islandora_get_object_extensions(AbstractObject $object) { function islandora_datastream_version_replace_form($form, &$form_state, AbstractDatastream $datastream) { module_load_include('inc', 'islandora', 'includes/content_model'); module_load_include('inc', 'islandora', 'includes/utilities'); + module_load_include('inc', 'islandora', 'includes/mimetype.utils'); $object = islandora_object_load($datastream->parent->id); $form_state['object_id'] = $object->id; @@ -290,6 +291,7 @@ function islandora_datastream_version_replace_form($form, &$form_state, Abstract } } $valid_extensions = implode(' ', $ext); + $valid_extensions .= ' ' . islandora_get_extension_for_mimetype($datastream->mimetype); $upload_size = min((int) ini_get('post_max_size'), (int) ini_get('upload_max_filesize')); return array( 'dsid_fieldset' => array( From b7d20be402298b7fb145acdd2925dab13611f123 Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Fri, 12 Sep 2014 09:39:03 -0300 Subject: [PATCH 3/7] updated mimetype selection --- includes/datastream.version.inc | 14 +++++--------- includes/mimetype.utils.inc | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/includes/datastream.version.inc b/includes/datastream.version.inc index bd0b8942..8e7b789c 100644 --- a/includes/datastream.version.inc +++ b/includes/datastream.version.inc @@ -282,16 +282,12 @@ function islandora_datastream_version_replace_form($form, &$form_state, Abstract $form_state['dsid'] = $datastream->id; $form_state['object'] = $object; $datastream_mime_map = islandora_get_object_extensions($object); - $mime_detect = new MimeDetect(); - $ext = array(); - if (isset($datastream_mime_map[$datastream->id])) { - foreach ($datastream_mime_map[$datastream->id]['mime'] as $key => $value) { - $extensions = $mime_detect->getValidExtensions($value); - $ext = array_merge($ext, $extensions); - } + $mimes = $datastream_mime_map[$datastream->id]['mime']; + $drupal_extensions = array(); + foreach ($mimes as $mime) { + $drupal_extensions = array_merge($drupal_extensions, islandora_get_extensions_for_mimetype($mime)); } - $valid_extensions = implode(' ', $ext); - $valid_extensions .= ' ' . islandora_get_extension_for_mimetype($datastream->mimetype); + $valid_extensions = implode(' ', $drupal_extensions); $upload_size = min((int) ini_get('post_max_size'), (int) ini_get('upload_max_filesize')); return array( 'dsid_fieldset' => array( diff --git a/includes/mimetype.utils.inc b/includes/mimetype.utils.inc index 989c55cd..a9ca5a6c 100644 --- a/includes/mimetype.utils.inc +++ b/includes/mimetype.utils.inc @@ -1,4 +1,5 @@ Date: Fri, 12 Sep 2014 09:42:26 -0300 Subject: [PATCH 4/7] updated mimetype selection --- includes/datastream.version.inc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/datastream.version.inc b/includes/datastream.version.inc index 8e7b789c..be08fb38 100644 --- a/includes/datastream.version.inc +++ b/includes/datastream.version.inc @@ -283,11 +283,11 @@ function islandora_datastream_version_replace_form($form, &$form_state, Abstract $form_state['object'] = $object; $datastream_mime_map = islandora_get_object_extensions($object); $mimes = $datastream_mime_map[$datastream->id]['mime']; - $drupal_extensions = array(); + $extensions = array(); foreach ($mimes as $mime) { - $drupal_extensions = array_merge($drupal_extensions, islandora_get_extensions_for_mimetype($mime)); + $extensions = array_merge($extensions, islandora_get_extensions_for_mimetype($mime)); } - $valid_extensions = implode(' ', $drupal_extensions); + $valid_extensions = implode(' ', $extensions); $upload_size = min((int) ini_get('post_max_size'), (int) ini_get('upload_max_filesize')); return array( 'dsid_fieldset' => array( From cc49c28ddd809784861b0cdf6b278f524729875c Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Fri, 12 Sep 2014 10:10:00 -0300 Subject: [PATCH 5/7] coder --- includes/mimetype.utils.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/mimetype.utils.inc b/includes/mimetype.utils.inc index a9ca5a6c..3aef6994 100644 --- a/includes/mimetype.utils.inc +++ b/includes/mimetype.utils.inc @@ -57,4 +57,4 @@ function islandora_get_extensions_for_mimetype($mimetype) { $extensions[] = 'xml'; } return $extensions; -} \ No newline at end of file +} From 9b49ec7bbfd07c8b661e3f53bbed62325e26ab44 Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Fri, 12 Sep 2014 10:28:41 -0300 Subject: [PATCH 6/7] allwed for existing non-standard mimetype --- includes/datastream.version.inc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/includes/datastream.version.inc b/includes/datastream.version.inc index be08fb38..e97640d4 100644 --- a/includes/datastream.version.inc +++ b/includes/datastream.version.inc @@ -282,7 +282,11 @@ function islandora_datastream_version_replace_form($form, &$form_state, Abstract $form_state['dsid'] = $datastream->id; $form_state['object'] = $object; $datastream_mime_map = islandora_get_object_extensions($object); + $current_mime = $datastream->mimetype; $mimes = $datastream_mime_map[$datastream->id]['mime']; + if (!in_array($current_mime, $mimes)) { + $mimes[] = $current_mime; + } $extensions = array(); foreach ($mimes as $mime) { $extensions = array_merge($extensions, islandora_get_extensions_for_mimetype($mime)); From d47e777adde0c0a58fb9e5d9c76eb27531f131b2 Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Mon, 15 Sep 2014 10:42:11 -0300 Subject: [PATCH 7/7] removed unused variable, added default --- includes/datastream.inc | 1 - includes/mimetype.utils.inc | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/includes/datastream.inc b/includes/datastream.inc index 592870b7..edc0026b 100644 --- a/includes/datastream.inc +++ b/includes/datastream.inc @@ -52,7 +52,6 @@ function islandora_view_datastream(AbstractDatastream $datastream, $download = F } if ($download) { // Browsers will not append all extensions. - $mime_detect = new MimeDetect(); $extension = '.' . islandora_get_extension_for_mimetype($datastream->mimetype); // Prevent adding on a duplicate extension. $label = $datastream->label; diff --git a/includes/mimetype.utils.inc b/includes/mimetype.utils.inc index 3aef6994..1a20859d 100644 --- a/includes/mimetype.utils.inc +++ b/includes/mimetype.utils.inc @@ -12,13 +12,13 @@ * The mimetype whose extension is required. * * @return string - * The extension mapped to the given mimetype. + * The extension mapped to the given mimetype. Defaults to 'bin'. */ function islandora_get_extension_for_mimetype($mimetype) { // file.mimetypes.inc is a part of Drupal core, however is not // automatically loaded. Manually require it. require_once DRUPAL_ROOT . "/includes/file.mimetypes.inc"; - + $extension = 'bin'; $mimetype_mapping = file_mimetype_mapping(); $extension_index = array_search($mimetype, $mimetype_mapping['mimetypes']); if ($extension_index !== FALSE) {