From 9c501934837b41aa602a25e9e3fca81571a77472 Mon Sep 17 00:00:00 2001 From: MorganDawe Date: Tue, 13 May 2014 12:41:59 +0000 Subject: [PATCH 1/5] Updated the mimedetect and added a helper function to process dsids that are not in an objects content model, such as user added. --- includes/datastream.version.inc | 39 +++++++++++++++++++++++++++++---- includes/mime_detect.inc | 2 +- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/includes/datastream.version.inc b/includes/datastream.version.inc index 85f20c0e..323c3252 100644 --- a/includes/datastream.version.inc +++ b/includes/datastream.version.inc @@ -231,6 +231,34 @@ function islandora_revert_datastream_version_form_submit(array $form, array &$fo $form_state['redirect'] = "islandora/object/{$islandora_object->id}/datastream/{$datastream_to_revert->id}/version"; } +/** + * Process available dsids, mime and extensions for a given object. + * + * @param AbstractObject $object + * The FedoraObject to process available extensions + * + * @return array() + * An associative array, merged from calls to + * islandora_get_datastreams_requirements_from_content_models() + * and an objects dsid's. + */ +function islandora_get_object_extensions(AbstractObject $object) { + $extensions = islandora_get_datastreams_requirements_from_models($object->models); + foreach($object as $datastream){ + // Could be a datastream not associated in a content model, + // such as user added. + if (!isset($extensions[$datastream->id])) { + // Add the extensions manually. + $extensions[$datastream->id] = array( + 'id' => $datastream->id, + 'optional' => TRUE, + 'mime' => array($datastream->mimeType), + ); + } + } + return $extensions; +} + /** * The admin replace datastream form. * @@ -252,12 +280,15 @@ function islandora_datastream_version_replace_form($form, &$form_state, Abstract $form_state['object_id'] = $object->id; $form_state['dsid'] = $datastream->id; $form_state['object'] = $object; - $extensions = islandora_get_datastreams_requirements_from_models($object->models); + $extensions = islandora_get_object_extensions($object); $mime_detect = new MimeDetect(); $ext = array(); - foreach ($extensions[$datastream->id]['mime'] as $key => $value) { - $str = $mime_detect->getExtension($value); - array_push($ext, $str); + if (isset($extensions[$datastream->id])) { + foreach ($extensions[$datastream->id]['mime'] as $key => $value) { + dsm($value, "getting value for"); + $str = $mime_detect->getExtension($value); + array_push($ext, $str); + } } $comma = count($ext) > 1 ? "," : ""; $ext = array(implode($comma, $ext)); diff --git a/includes/mime_detect.inc b/includes/mime_detect.inc index e76975d6..a027015c 100644 --- a/includes/mime_detect.inc +++ b/includes/mime_detect.inc @@ -144,7 +144,7 @@ class MimeDetect { "ief" => "image/ief", "jpeg" => "image/jpeg", "jpe" => "image/jpeg", - "jpg" => "image/jpeg", + "jpg" => "image/jpg", "jp2" => "image/jp2", "png" => "image/png", "tiff" => "image/tiff", From 18badb79996eb25d19deab3f8f7d72360cb65ead Mon Sep 17 00:00:00 2001 From: MorganDawe Date: Tue, 13 May 2014 12:49:58 +0000 Subject: [PATCH 2/5] Removed debug statement. --- includes/datastream.version.inc | 1 - 1 file changed, 1 deletion(-) diff --git a/includes/datastream.version.inc b/includes/datastream.version.inc index 323c3252..be01805f 100644 --- a/includes/datastream.version.inc +++ b/includes/datastream.version.inc @@ -285,7 +285,6 @@ function islandora_datastream_version_replace_form($form, &$form_state, Abstract $ext = array(); if (isset($extensions[$datastream->id])) { foreach ($extensions[$datastream->id]['mime'] as $key => $value) { - dsm($value, "getting value for"); $str = $mime_detect->getExtension($value); array_push($ext, $str); } From d466bb054adc7d1059391ea668bf109be63ef99e Mon Sep 17 00:00:00 2001 From: MorganDawe Date: Tue, 13 May 2014 13:51:57 +0000 Subject: [PATCH 3/5] Added two spaces to comply with coding standards. --- includes/datastream.version.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/datastream.version.inc b/includes/datastream.version.inc index be01805f..f245830c 100644 --- a/includes/datastream.version.inc +++ b/includes/datastream.version.inc @@ -244,7 +244,7 @@ function islandora_revert_datastream_version_form_submit(array $form, array &$fo */ function islandora_get_object_extensions(AbstractObject $object) { $extensions = islandora_get_datastreams_requirements_from_models($object->models); - foreach($object as $datastream){ + foreach ($object as $datastream) { // Could be a datastream not associated in a content model, // such as user added. if (!isset($extensions[$datastream->id])) { From 8b3d781b3b78aa8704c75cce5f20781073fd5e1f Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Thu, 22 May 2014 18:50:44 +0000 Subject: [PATCH 4/5] Correct recently broken MIME-type. --- 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 ac0c9fbd..c1be1b92 100644 --- a/includes/mime_detect.inc +++ b/includes/mime_detect.inc @@ -144,7 +144,7 @@ class MimeDetect { "ief" => "image/ief", "jpeg" => "image/jpeg", "jpe" => "image/jpeg", - "jpg" => "image/jpg", + "jpg" => "image/jpeg", "jp2" => "image/jp2", "png" => "image/png", "tiff" => "image/tiff", From 69188416bdd6d144c8a7e0659322efe7c473353d Mon Sep 17 00:00:00 2001 From: willtp87 Date: Sun, 25 May 2014 10:56:31 -0400 Subject: [PATCH 5/5] less batches --- includes/derivatives.inc | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/includes/derivatives.inc b/includes/derivatives.inc index 47ec4fad..72d61235 100644 --- a/includes/derivatives.inc +++ b/includes/derivatives.inc @@ -21,25 +21,28 @@ function islandora_run_derivatives(AbstractObject $object, $dsid) { islandora_derivative_logging($logging_results); } else { - batch_set( - // Title won't show for batch in a batch. + $operations = islandora_do_batch_derivatives( + $object, array( - 'init_message' => t('Preparing derivatives for @label', array('@label' => $object->label)), - 'error_message' => t('An error occured creating derivatives.'), - 'progress_message' => t( - 'Creating derivatives for @label
Time elapsed: @elapsed
- Estimated time remaining @estimate.', - array('@label' => $object->label) - ), - 'file' => drupal_get_path('module', 'islandora') . '/includes/regenerate_derivatives.form.inc', - 'operations' => islandora_do_batch_derivatives( - $object, - array( - 'source_dsid' => $dsid, - ) - ), + 'source_dsid' => $dsid, ) ); + if ($operations) { + batch_set( + // Title won't show for batch in a batch. + array( + 'init_message' => t('Preparing derivatives for @label', array('@label' => $object->label)), + 'error_message' => t('An error occured creating derivatives.'), + 'progress_message' => t( + 'Creating derivatives for @label
Time elapsed: @elapsed
+ Estimated time remaining @estimate.', + array('@label' => $object->label) + ), + 'file' => drupal_get_path('module', 'islandora') . '/includes/regenerate_derivatives.form.inc', + 'operations' => $operations, + ) + ); + } } }