Browse Source

Merge branch '7.x' of github.com:Islandora/islandora into 7.x

pull/547/head
Alan Stanley 10 years ago
parent
commit
3764973b65
  1. 7
      includes/admin.form.inc
  2. 4
      includes/datastream.inc
  3. 39
      includes/derivatives.inc
  4. 1
      includes/mime_detect.inc
  5. 31
      includes/mimetype.utils.inc
  6. 2
      includes/regenerate_derivatives.form.inc
  7. 1
      islandora.install
  8. 25
      islandora.module
  9. 25
      tests/scripts/travis_setup.sh

7
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.'), '#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), '#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( 'islandora_namespace' => array(
'#type' => 'fieldset', '#type' => 'fieldset',

4
includes/datastream.inc

@ -30,6 +30,7 @@ function islandora_download_datastream(AbstractDatastream $datastream) {
* The version of the datastream to display * The version of the datastream to display
*/ */
function islandora_view_datastream(AbstractDatastream $datastream, $download = FALSE, $version = NULL) { 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 // 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 // handlers", such as query logging... The problem is that they might blindly
// add additional output which will break things if what is actually being // 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(); return drupal_not_found();
} }
} }
header('Content-type: ' . $datastream->mimetype); header('Content-type: ' . $datastream->mimetype);
if ($datastream->controlGroup == 'M' || $datastream->controlGroup == 'X') { if ($datastream->controlGroup == 'M' || $datastream->controlGroup == 'X') {
header('Content-length: ' . $datastream->size); header('Content-length: ' . $datastream->size);
@ -53,7 +53,7 @@ function islandora_view_datastream(AbstractDatastream $datastream, $download = F
if ($download) { if ($download) {
// Browsers will not append all extensions. // Browsers will not append all extensions.
$mime_detect = new MimeDetect(); $mime_detect = new MimeDetect();
$extension = '.' . $mime_detect->getExtension($datastream->mimetype); $extension = '.' . islandora_get_extension_for_mimetype($datastream->mimetype);
// Prevent adding on a duplicate extension. // Prevent adding on a duplicate extension.
$label = $datastream->label; $label = $datastream->label;
$extension_length = strlen($extension); $extension_length = strlen($extension);

39
includes/derivatives.inc

@ -4,6 +4,9 @@
* Defines functions used when constructing derivatives. * Defines functions used when constructing derivatives.
*/ */
// Relations.
define('ISLANDORA_DEFER_DERIVATIVES_FLAG', 'deferDerivatives');
/** /**
* Decides which derivative function to call and runs it. * 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); $hooks = array_filter($hooks, $filter_function);
return $hooks; 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
);
}

1
includes/mime_detect.inc

@ -134,7 +134,6 @@ class MimeDetect {
'xhtml' => 'application/xhtml+xml', 'xhtml' => 'application/xhtml+xml',
'xsl' => 'text/xsl', 'xsl' => 'text/xsl',
'xslt' => 'text/xsl', 'xslt' => 'text/xsl',
'xml' => 'application/xml',
'csv' => 'text/csv', 'csv' => 'text/csv',
'tsv' => 'text/tab-separated-values', 'tsv' => 'text/tab-separated-values',
'txt' => 'text/plain', 'txt' => 'text/plain',

31
includes/mimetype.utils.inc

@ -0,0 +1,31 @@
<?php
/**
* @file
* Mimetype specific utility functions.
*/
/**
* Retrieve the correct file extension for a give mimetype.
*
* @param string $mimetype
* The mimetype whose extension is required.
*
* @return string
* The extension mapped to the given mimetype.
*/
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";
$mimetype_mapping = file_mimetype_mapping();
$extension_index = array_search($mimetype, $mimetype_mapping['mimetypes']);
$mime_array_flipped = array_reverse($mimetype_mapping['extensions']);
$extension = array_search($extension_index, $mime_array_flipped);
// We can only have one mapping in drupal for 'xml'.
if ($mimetype == "text/xml") {
return "xml";
}
return $extension;
}

2
includes/regenerate_derivatives.form.inc

@ -95,6 +95,7 @@ function islandora_regenerate_object_derivatives_form_submit(array $form, array
*/ */
function islandora_regenerate_object_derivatives_batch(AbstractObject $object) { function islandora_regenerate_object_derivatives_batch(AbstractObject $object) {
module_load_include('inc', 'islandora', 'includes/derivatives'); module_load_include('inc', 'islandora', 'includes/derivatives');
islandora_remove_defer_derivatives_flag($object);
return array( return array(
'title' => t('Regenerating all derivatives for @label', array('@label' => $object->label)), 'title' => t('Regenerating all derivatives for @label', array('@label' => $object->label)),
'operations' => islandora_do_batch_derivatives($object, array('force' => TRUE)), '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) { function islandora_regenerate_datastream_derivative_batch(AbstractDatastream $datastream) {
module_load_include('inc', 'islandora', 'includes/derivatives'); module_load_include('inc', 'islandora', 'includes/derivatives');
islandora_remove_defer_derivatives_flag($datastream->parent);
return array( return array(
'title' => t('Regenerating derivatives for the @dsid datastream', array('@dsid' => $datastream->id)), 'title' => t('Regenerating derivatives for the @dsid datastream', array('@dsid' => $datastream->id)),
'operations' => islandora_do_batch_derivatives($datastream->parent, array( 'operations' => islandora_do_batch_derivatives($datastream->parent, array(

1
islandora.install

@ -46,6 +46,7 @@ function islandora_uninstall() {
// Add new variables to clean up. // Add new variables to clean up.
$variables = array( $variables = array(
'islandora_ds_replace_exclude_enforced', 'islandora_ds_replace_exclude_enforced',
'islandora_defer_derivatives_on_ingest',
); );
array_walk($variables, 'variable_del'); array_walk($variables, 'variable_del');
} }

25
islandora.module

@ -1564,9 +1564,12 @@ function islandora_entity_property_info() {
*/ */
function islandora_download_clip(AbstractObject $object) { function islandora_download_clip(AbstractObject $object) {
if (isset($_GET['clip'])) { if (isset($_GET['clip'])) {
$url = $_GET['clip'];
if (!preg_match('/^https?:\/\//', $url)) {
$is_https = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on'; $is_https = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on';
$http_protocol = $is_https ? 'https' : 'http'; $http_protocol = $is_https ? 'https' : 'http';
$url = $http_protocol . '://' . $_SERVER['HTTP_HOST'] . $_GET['clip']; $url = $http_protocol . '://' . $_SERVER['HTTP_HOST'] . $url;
}
$filename = $object->label; $filename = $object->label;
header("Content-Disposition: attachment; filename=\"{$filename}.jpg\""); header("Content-Disposition: attachment; filename=\"{$filename}.jpg\"");
header("Content-type: image/jpeg"); header("Content-type: image/jpeg");
@ -1590,6 +1593,7 @@ function islandora_download_clip(AbstractObject $object) {
function islandora_file_mimetype_mapping_alter(&$mapping) { function islandora_file_mimetype_mapping_alter(&$mapping) {
$mime_detect = new MimeDetect(); $mime_detect = new MimeDetect();
$types = $mime_detect->getMimeTypes(); $types = $mime_detect->getMimeTypes();
$diff = array_diff_key($types, $mapping['extensions']); $diff = array_diff_key($types, $mapping['extensions']);
foreach ($diff as $ext => $mime) { foreach ($diff as $ext => $mime) {
$mapping['mimetypes'][] = $mime; $mapping['mimetypes'][] = $mime;
@ -1719,6 +1723,10 @@ function islandora_islandora_basic_collection_get_query_filters() {
*/ */
function islandora_islandora_object_ingested(AbstractObject $object) { function islandora_islandora_object_ingested(AbstractObject $object) {
module_load_include('inc', 'islandora', 'includes/derivatives'); module_load_include('inc', 'islandora', 'includes/derivatives');
// Defer derivatives if necessary.
if (islandora_get_defer_derivatives_flag($object)) {
return;
}
islandora_run_derivatives($object, NULL); 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) { function islandora_islandora_datastream_ingested(AbstractObject $object, AbstractDatastream $datastream) {
module_load_include('inc', 'islandora', 'includes/derivatives'); 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); 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);
}
}

25
tests/scripts/travis_setup.sh

@ -1,14 +1,13 @@
#!/bin/bash #!/bin/bash
mysql -u root -e 'create database drupal;' mysql -u root -e 'create database drupal;'
mysql -u root -e "create database fedora;" 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 fedora.* To 'fedora'@'localhost' IDENTIFIED BY 'fedora';"
mysql -u root -e "GRANT ALL PRIVILEGES ON drupal.* To 'drupal'@'localhost' IDENTIFIED BY 'drupal';" mysql -u root -e "GRANT ALL PRIVILEGES ON drupal.* To 'drupal'@'localhost' IDENTIFIED BY 'drupal';"
cd $HOME cd $HOME
git clone git://github.com/Islandora/tuque.git 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 cd islandora_tomcat
git fsck
export CATALINA_HOME='.' 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" 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 ./bin/startup.sh
@ -18,20 +17,22 @@ pear upgrade --force Console_Getopt
pear upgrade --force pear pear upgrade --force pear
pear channel-discover pear.drush.org pear channel-discover pear.drush.org
# "prefer-source" required due to SSL shenanigans on the Travis boxes... wget http://alpha.library.yorku.ca/drush-6.3.tar.gz
composer global require --prefer-source 'squizlabs/php_codesniffer=*' 'sebastian/phpcpd=*' 'drush/drush:6.3.0' tar xf drush-6.3.tar.gz
# Because we can't add to the PATH here and this file is used in many repos, sudo mv drush-6.3 /opt/
# let's just throw symlinks in. sudo ln -s /opt/drush-6.3/drush /usr/bin/drush
find $HOME/.composer/vendor/bin -executable \! -type d -exec sudo ln -s {} /usr/local/sbin/ \;
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 phpenv rehash
drush dl --yes drupal drush dl --yes drupal
cd drupal-* cd drupal-*
drush si minimal --db-url=mysql://drupal:drupal@localhost/drupal --yes 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 & drush runserver --php-cgi=$HOME/.phpenv/shims/php-cgi localhost:8081 &>/tmp/drush_webserver.log &
ln -s $ISLANDORA_DIR sites/all/modules/islandora 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 mv sites/all/modules/islandora/tests/travis.test_config.ini sites/all/modules/islandora/tests/test_config.ini

Loading…
Cancel
Save