diff --git a/includes/admin.form.inc b/includes/admin.form.inc index 69f09fd2..42612ea0 100644 --- a/includes/admin.form.inc +++ b/includes/admin.form.inc @@ -61,6 +61,13 @@ function islandora_repository_admin(array $form, array &$form_state) { '#description' => t('HTTP caching can reduce network traffic, by allowing clients to used cached copies.'), '#default_value' => variable_get('islandora_use_datastream_cache_headers', TRUE), ), + 'islandora_defer_derivatives_on_ingest' => array( + '#type' => 'checkbox', + '#title' => t('Defer derivative generation during ingest'), + '#description' => t('Prevent derivatives from running during ingest, + useful if derivatives are to be created by an external service.'), + '#default_value' => variable_get('islandora_defer_derivatives_on_ingest', FALSE), + ), ), 'islandora_namespace' => array( '#type' => 'fieldset', diff --git a/includes/datastream.inc b/includes/datastream.inc index edc8ceb1..592870b7 100644 --- a/includes/datastream.inc +++ b/includes/datastream.inc @@ -30,6 +30,7 @@ function islandora_download_datastream(AbstractDatastream $datastream) { * The version of the datastream to display */ function islandora_view_datastream(AbstractDatastream $datastream, $download = FALSE, $version = NULL) { + module_load_include('inc', 'islandora', 'includes/mimetype.utils'); // XXX: Certain features of the Devel module rely on the use of "shutdown // handlers", such as query logging... The problem is that they might blindly // add additional output which will break things if what is actually being @@ -45,7 +46,6 @@ function islandora_view_datastream(AbstractDatastream $datastream, $download = F return drupal_not_found(); } } - header('Content-type: ' . $datastream->mimetype); if ($datastream->controlGroup == 'M' || $datastream->controlGroup == 'X') { header('Content-length: ' . $datastream->size); @@ -53,7 +53,7 @@ function islandora_view_datastream(AbstractDatastream $datastream, $download = F if ($download) { // Browsers will not append all extensions. $mime_detect = new MimeDetect(); - $extension = '.' . $mime_detect->getExtension($datastream->mimetype); + $extension = '.' . islandora_get_extension_for_mimetype($datastream->mimetype); // Prevent adding on a duplicate extension. $label = $datastream->label; $extension_length = strlen($extension); diff --git a/includes/derivatives.inc b/includes/derivatives.inc index 72d61235..7248f03f 100644 --- a/includes/derivatives.inc +++ b/includes/derivatives.inc @@ -4,6 +4,9 @@ * Defines functions used when constructing derivatives. */ +// Relations. +define('ISLANDORA_DEFER_DERIVATIVES_FLAG', 'deferDerivatives'); + /** * Decides which derivative function to call and runs it. * @@ -245,3 +248,39 @@ function islandora_filter_derivatives($hooks, $options, AbstractObject $object) $hooks = array_filter($hooks, $filter_function); return $hooks; } + +/** + * Set the defer derivatives flag on an object. + */ +function islandora_set_defer_derivatives_flag(AbstractObject $object) { + $object->relationships->add( + ISLANDORA_RELS_EXT_URI, + ISLANDORA_DEFER_DERIVATIVES_FLAG, + 'true', + RELS_TYPE_PLAIN_LITERAL + ); +} + +/** + * Get the defer derivatives flag on an object. + */ +function islandora_get_defer_derivatives_flag(AbstractObject $object) { + return $object->relationships->get( + ISLANDORA_RELS_EXT_URI, + ISLANDORA_DEFER_DERIVATIVES_FLAG, + 'true', + RELS_TYPE_PLAIN_LITERAL + ); +} + +/** + * Remove the defer derivatives flag on an object. + */ +function islandora_remove_defer_derivatives_flag(AbstractObject $object) { + $object->relationships->remove( + ISLANDORA_RELS_EXT_URI, + ISLANDORA_DEFER_DERIVATIVES_FLAG, + 'true', + RELS_TYPE_PLAIN_LITERAL + ); +} diff --git a/includes/mime_detect.inc b/includes/mime_detect.inc index 29fcf1e5..da2c69f3 100644 --- a/includes/mime_detect.inc +++ b/includes/mime_detect.inc @@ -134,7 +134,6 @@ class MimeDetect { 'xhtml' => 'application/xhtml+xml', 'xsl' => 'text/xsl', 'xslt' => 'text/xsl', - 'xml' => 'application/xml', 'csv' => 'text/csv', 'tsv' => 'text/tab-separated-values', 'txt' => 'text/plain', diff --git a/includes/mimetype.utils.inc b/includes/mimetype.utils.inc new file mode 100644 index 00000000..989c55cd --- /dev/null +++ b/includes/mimetype.utils.inc @@ -0,0 +1,31 @@ + t('Regenerating all derivatives for @label', array('@label' => $object->label)), 'operations' => islandora_do_batch_derivatives($object, array('force' => TRUE)), @@ -117,6 +118,7 @@ function islandora_regenerate_object_derivatives_batch(AbstractObject $object) { */ function islandora_regenerate_datastream_derivative_batch(AbstractDatastream $datastream) { module_load_include('inc', 'islandora', 'includes/derivatives'); + islandora_remove_defer_derivatives_flag($datastream->parent); return array( 'title' => t('Regenerating derivatives for the @dsid datastream', array('@dsid' => $datastream->id)), 'operations' => islandora_do_batch_derivatives($datastream->parent, array( diff --git a/islandora.install b/islandora.install index f37894e9..12c92009 100644 --- a/islandora.install +++ b/islandora.install @@ -46,6 +46,7 @@ function islandora_uninstall() { // Add new variables to clean up. $variables = array( 'islandora_ds_replace_exclude_enforced', + 'islandora_defer_derivatives_on_ingest', ); array_walk($variables, 'variable_del'); } diff --git a/islandora.module b/islandora.module index b2bb99b8..b692438e 100644 --- a/islandora.module +++ b/islandora.module @@ -1564,9 +1564,12 @@ function islandora_entity_property_info() { */ 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'; - $url = $http_protocol . '://' . $_SERVER['HTTP_HOST'] . $_GET['clip']; + $url = $_GET['clip']; + if (!preg_match('/^https?:\/\//', $url)) { + $is_https = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on'; + $http_protocol = $is_https ? 'https' : 'http'; + $url = $http_protocol . '://' . $_SERVER['HTTP_HOST'] . $url; + } $filename = $object->label; header("Content-Disposition: attachment; filename=\"{$filename}.jpg\""); header("Content-type: image/jpeg"); @@ -1590,6 +1593,7 @@ function islandora_download_clip(AbstractObject $object) { 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) { $mapping['mimetypes'][] = $mime; @@ -1719,6 +1723,10 @@ function islandora_islandora_basic_collection_get_query_filters() { */ function islandora_islandora_object_ingested(AbstractObject $object) { module_load_include('inc', 'islandora', 'includes/derivatives'); + // Defer derivatives if necessary. + if (islandora_get_defer_derivatives_flag($object)) { + return; + } islandora_run_derivatives($object, NULL); } @@ -1730,6 +1738,10 @@ function islandora_islandora_object_ingested(AbstractObject $object) { */ function islandora_islandora_datastream_ingested(AbstractObject $object, AbstractDatastream $datastream) { module_load_include('inc', 'islandora', 'includes/derivatives'); + // Defer derivatives if necessary. + if (islandora_get_defer_derivatives_flag($object)) { + return; + } islandora_run_derivatives($object, $datastream->id); } @@ -1951,3 +1963,14 @@ function islandora_menu_local_tasks_alter(&$data, $router_item, $root_path) { } } } + +/** + * Implements hook_islandora_object_alter(). + */ +function islandora_islandora_object_alter(AbstractObject $object, array &$context) { + // Prevent derivative creation during ingest if var is set. + if ($context['action'] == 'ingest' && variable_get('islandora_defer_derivatives_on_ingest', FALSE)) { + module_load_include('inc', 'islandora', 'includes/derivatives'); + islandora_set_defer_derivatives_flag($object); + } +} diff --git a/tests/scripts/travis_setup.sh b/tests/scripts/travis_setup.sh index 0b33d4b0..5a8c78ef 100755 --- a/tests/scripts/travis_setup.sh +++ b/tests/scripts/travis_setup.sh @@ -1,14 +1,13 @@ #!/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 +wget http://alpha.library.yorku.ca/islandora_tomcat.$FEDORA_VERSION.tar.gz +tar xf islandora_tomcat.$FEDORA_VERSION.tar.gz cd islandora_tomcat -git fsck export CATALINA_HOME='.' export JAVA_OPTS="-Xms1024m -Xmx1024m -XX:MaxPermSize=512m -XX:+CMSClassUnloadingEnabled -Djavax.net.ssl.trustStore=$CATALINA_HOME/fedora/server/truststore -Djavax.net.ssl.trustStorePassword=tomcat" ./bin/startup.sh @@ -18,20 +17,22 @@ pear upgrade --force Console_Getopt pear upgrade --force pear pear channel-discover pear.drush.org -# "prefer-source" required due to SSL shenanigans on the Travis boxes... -composer global require --prefer-source 'squizlabs/php_codesniffer=*' 'sebastian/phpcpd=*' 'drush/drush:6.3.0' -# Because we can't add to the PATH here and this file is used in many repos, -# let's just throw symlinks in. -find $HOME/.composer/vendor/bin -executable \! -type d -exec sudo ln -s {} /usr/local/sbin/ \; +wget http://alpha.library.yorku.ca/drush-6.3.tar.gz +tar xf drush-6.3.tar.gz +sudo mv drush-6.3 /opt/ +sudo ln -s /opt/drush-6.3/drush /usr/bin/drush + +wget http://alpha.library.yorku.ca/PHP_CodeSniffer-1.5.4.tgz +pear install PHP_CodeSniffer-1.5.4.tgz + +wget http://alpha.library.yorku.ca/phpcpd.phar +sudo mv phpcpd.phar /usr/local/bin/phpcpd +sudo chmod +x /usr/local/bin/phpcpd phpenv rehash drush dl --yes drupal cd drupal-* drush si minimal --db-url=mysql://drupal:drupal@localhost/drupal --yes -# Needs to make things from Composer be available (PHP CS, primarily) -sudo chmod a+w sites/default/settings.php -echo "include_once '$HOME/.composer/vendor/autoload.php';" >> sites/default/settings.php -sudo chmod a-w sites/default/settings.php drush runserver --php-cgi=$HOME/.phpenv/shims/php-cgi localhost:8081 &>/tmp/drush_webserver.log & 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