From 429b70c518910247104bb0f3abaf4167ac07d05f Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Fri, 8 Jun 2012 17:04:13 -0300 Subject: [PATCH 1/9] ISLANDORA-485 AHAH causes file upload Little patch to allow use of upload_element instead of the normal "file" element --- fedora_repository.module | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/fedora_repository.module b/fedora_repository.module index 2dc986f8..45fe0037 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -220,18 +220,26 @@ function fedora_repository_ingest_form_validate($form, &$form_state) { // Get the uploaded file. $validators = array(); - if (!empty($_FILES['files']['name']['ingest-file-location'])) { - $fileObject = file_save_upload('ingest-file-location', $validators); + $ifl = 'ingest-file-location'; + $fileObject = NULL; + //Check if it's already there; this is what upload_element provides. + if (is_a($form_state['values'][$ifl], 'stdClass') && property_exists($form_state['values'][$ifl], '')) { + $fileObject = $form_state['values'][$ifl]; + } + elseif (!empty($_FILES['files']['name'][$ifl])) { + $fileObject = file_save_upload($ifl, $validators); + } + if ($fileObject !== NULL && property_exists($fileObject, 'filepath')) { file_move($fileObject->filepath, 0, 'FILE_EXISTS_RENAME'); - $form_state['values']['ingest-file-location'] = $fileObject->filepath; + $form_state['values'][$ifl] = $fileObject->filepath; } - if (isset($form_state['values']['ingest-file-location']) && file_exists($form_state['values']['ingest-file-location'])) { + if (isset($form_state['values'][$ifl]) && file_exists($form_state['values'][$ifl])) { module_load_include('inc', 'fedora_repository', 'ContentModel'); module_load_include('inc', 'fedora_repository', 'MimeClass'); - $file = $form_state['values']['ingest-file-location']; + $file = $form_state['values'][$ifl]; $contentModelPid = ContentModel::getPidFromIdentifier($form_state['values']['models']); $contentModelDsid = ContentModel::getDSIDFromIdentifier($form_state['values']['models']); @@ -244,11 +252,11 @@ function fedora_repository_ingest_form_validate($form, &$form_state) { if (!empty($file)) { if (!in_array($dformat, $allowedMimeTypes)) { - form_set_error('ingest-file-location', - t('The uploaded file\'s mimetype') . - ' (' . $dformat . ') ' . - t('is not associated with this Content Model. The allowed types are') . - ' ' . implode(' ', $allowedMimeTypes)); + form_set_error($ifl, + t('The uploaded file\'s mimetype (@mime) is not associated with this Content Model. The allowed types are: @allowed', array( + '@mime' => $dformat, + '@allowed' => implode(', ', $allowedMimeTypes), + )); file_delete($file); return; } From c1b3890357b6edafbbf7ea1d9627fe9701f64fa2 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Mon, 11 Jun 2012 10:01:28 -0300 Subject: [PATCH 2/9] Fix syntax error. --- fedora_repository.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fedora_repository.module b/fedora_repository.module index 45fe0037..52aa116e 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -256,7 +256,7 @@ function fedora_repository_ingest_form_validate($form, &$form_state) { t('The uploaded file\'s mimetype (@mime) is not associated with this Content Model. The allowed types are: @allowed', array( '@mime' => $dformat, '@allowed' => implode(', ', $allowedMimeTypes), - )); + ))); file_delete($file); return; } From d8b404d7b5372c4ed70ec9ab8e000cd0f41feb32 Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Tue, 12 Jun 2012 14:28:20 -0300 Subject: [PATCH 3/9] Added tuque wrapper for use in 6.x development --- api/tuque.inc | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 api/tuque.inc diff --git a/api/tuque.inc b/api/tuque.inc new file mode 100644 index 00000000..74dfa730 --- /dev/null +++ b/api/tuque.inc @@ -0,0 +1,93 @@ +uid == 0){ + $user_string = 'anonymous'; + $pass_string = 'anonymous'; + } else { + $user_string = $user->name; + $pass_string = $user->pass; + } + + if (!isset($url)) { + $url = variable_get('islandora_base_url', 'http://localhost:8080/fedora'); + } + + if(self::exists()) { + $this->connection = new RepositoryConnection($url, $user_string, $pass_string); + $this->connection->reuseConnection = TRUE; + $this->api = new FedoraApi($this->connection); + $this->cache = new SimpleCache(); + $this->repository = new FedoraRepository($this->api, $this->cache); + } + } + + static function exists() { + return class_exists('RepositoryConnection'); + } + + static function getError() { + $islandora_doc_link = l(t('Islandora documentation'), 'https://wiki.duraspace.org/display/ISLANDORA/Islandora'); + $tuque_link = l(t('Tuque Fedora API'), 'http://github.com/islandora/tuque'); + $message = t('Islandora requires the !tuque_url. Please install in /sites/all/libraries/tuque before continuing. See the !islandora_url.', array( '!tuque_url' => $tuque_link, '!islandora_url' => $islandora_doc_link)); + drupal_set_message($message, 'error', FALSE); + } +} + From a4985161f7b9d0017a9028df7f8d4fec3530f1ca Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Tue, 12 Jun 2012 17:13:50 -0300 Subject: [PATCH 4/9] Comment spacing, islandora_object_load function --- api/tuque.inc | 79 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 52 insertions(+), 27 deletions(-) diff --git a/api/tuque.inc b/api/tuque.inc index 74dfa730..723d1df9 100644 --- a/api/tuque.inc +++ b/api/tuque.inc @@ -3,15 +3,15 @@ $islandora_module_path = drupal_get_path('module', 'fedora_repository'); //do this until we expost these in a module or library -@include_once 'sites/all/libraries/tuque/Datastream.php'; -@include_once 'sites/all/libraries/tuque/FedoraApi.php'; -@include_once 'sites/all/libraries/tuque/FedoraApiSerializer.php'; -@include_once 'sites/all/libraries/tuque/Object.php'; -@include_once 'sites/all/libraries/tuque/RepositoryConnection.php'; -@include_once 'sites/all/libraries/tuque/Cache.php'; -@include_once 'sites/all/libraries/tuque/RepositoryException.php'; -@include_once 'sites/all/libraries/tuque/Repository.php'; -@include_once 'sites/all/libraries/tuque/FedoraRelationships.php'; +@include_once 'sites/default/libraries/tuque/Datastream.php'; +@include_once 'sites/default/libraries/tuque/FedoraApi.php'; +@include_once 'sites/default/libraries/tuque/FedoraApiSerializer.php'; +@include_once 'sites/default/libraries/tuque/Object.php'; +@include_once 'sites/default/libraries/tuque/RepositoryConnection.php'; +@include_once 'sites/default/libraries/tuque/Cache.php'; +@include_once 'sites/default/libraries/tuque/RepositoryException.php'; +@include_once 'sites/default/libraries/tuque/Repository.php'; +@include_once 'sites/default/libraries/tuque/FedoraRelationships.php'; @include_once "$islandora_module_path/libraries/tuque/Datastream.php"; @include_once "$islandora_module_path/libraries/tuque/FedoraApi.php"; @@ -26,31 +26,31 @@ $islandora_module_path = drupal_get_path('module', 'fedora_repository'); class IslandoraTuque { /** - * Connection to the repository - * - * @var RepositoryConnection - */ +* Connection to the repository +* +* @var RepositoryConnection +*/ public $connection = NULL; /** - * The Fedora API we are using - * - * @var FedoraAPI - */ +* The Fedora API we are using +* +* @var FedoraAPI +*/ public $api = NULL; /** - * The cache we use to connect. - * - * @var SimpleCache - */ +* The cache we use to connect. +* +* @var SimpleCache +*/ public $cache = NULL; /** - * The repository object. - * - * @var FedoraRepository - */ +* The repository object. +* +* @var FedoraRepository +*/ public $repository = NULL; function __construct($user = NULL, $url = NULL) { @@ -77,8 +77,9 @@ class IslandoraTuque { $this->cache = new SimpleCache(); $this->repository = new FedoraRepository($this->api, $this->cache); } - } - + + } + static function exists() { return class_exists('RepositoryConnection'); } @@ -89,5 +90,29 @@ class IslandoraTuque { $message = t('Islandora requires the !tuque_url. Please install in /sites/all/libraries/tuque before continuing. See the !islandora_url.', array( '!tuque_url' => $tuque_link, '!islandora_url' => $islandora_doc_link)); drupal_set_message($message, 'error', FALSE); } + + } +function islandora_object_load($object_id) { + static $islandora_tuque = NULL; + + if(!$islandora_tuque) { + $islandora_tuque = new IslandoraTuque(); + } + + if(IslandoraTuque::exists()) { + try { + $fedora_object = $islandora_tuque->repository->getObject($object_id); + } catch (Exception $e) { + return NULL; + } + return $fedora_object; + } + else { + IslandoraTuque::getError(); + return NULL; + } + } + + From 3cb70d92238ef33e8fadaf0e42f6a11985f55095 Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Tue, 12 Jun 2012 17:20:17 -0300 Subject: [PATCH 5/9] Comment spacing, islandora_object_load function --- api/tuque.inc | 53 ++++++++++++++++++++++++--------------------------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/api/tuque.inc b/api/tuque.inc index 723d1df9..553c4fe6 100644 --- a/api/tuque.inc +++ b/api/tuque.inc @@ -3,15 +3,15 @@ $islandora_module_path = drupal_get_path('module', 'fedora_repository'); //do this until we expost these in a module or library -@include_once 'sites/default/libraries/tuque/Datastream.php'; -@include_once 'sites/default/libraries/tuque/FedoraApi.php'; -@include_once 'sites/default/libraries/tuque/FedoraApiSerializer.php'; -@include_once 'sites/default/libraries/tuque/Object.php'; -@include_once 'sites/default/libraries/tuque/RepositoryConnection.php'; -@include_once 'sites/default/libraries/tuque/Cache.php'; -@include_once 'sites/default/libraries/tuque/RepositoryException.php'; -@include_once 'sites/default/libraries/tuque/Repository.php'; -@include_once 'sites/default/libraries/tuque/FedoraRelationships.php'; +@include_once 'sites/all/libraries/tuque/Datastream.php'; +@include_once 'sites/all/libraries/tuque/FedoraApi.php'; +@include_once 'sites/all/libraries/tuque/FedoraApiSerializer.php'; +@include_once 'sites/all/libraries/tuque/Object.php'; +@include_once 'sites/all/libraries/tuque/RepositoryConnection.php'; +@include_once 'sites/all/libraries/tuque/Cache.php'; +@include_once 'sites/all/libraries/tuque/RepositoryException.php'; +@include_once 'sites/all/libraries/tuque/Repository.php'; +@include_once 'sites/all/libraries/tuque/FedoraRelationships.php'; @include_once "$islandora_module_path/libraries/tuque/Datastream.php"; @include_once "$islandora_module_path/libraries/tuque/FedoraApi.php"; @@ -26,31 +26,31 @@ $islandora_module_path = drupal_get_path('module', 'fedora_repository'); class IslandoraTuque { /** -* Connection to the repository -* -* @var RepositoryConnection -*/ + * Connection to the repository + * + * @var RepositoryConnection + */ public $connection = NULL; /** -* The Fedora API we are using -* -* @var FedoraAPI -*/ + * The Fedora API we are using + * + * @var FedoraAPI + */ public $api = NULL; /** -* The cache we use to connect. -* -* @var SimpleCache -*/ + * The cache we use to connect. + * + * @var SimpleCache + */ public $cache = NULL; /** -* The repository object. -* -* @var FedoraRepository -*/ + * The repository object. + * + * @var FedoraRepository + */ public $repository = NULL; function __construct($user = NULL, $url = NULL) { @@ -77,7 +77,6 @@ class IslandoraTuque { $this->cache = new SimpleCache(); $this->repository = new FedoraRepository($this->api, $this->cache); } - } static function exists() { @@ -90,8 +89,6 @@ class IslandoraTuque { $message = t('Islandora requires the !tuque_url. Please install in /sites/all/libraries/tuque before continuing. See the !islandora_url.', array( '!tuque_url' => $tuque_link, '!islandora_url' => $islandora_doc_link)); drupal_set_message($message, 'error', FALSE); } - - } function islandora_object_load($object_id) { From c2f0b10ffc72cc3f547d00421f3dc2aee00a2748 Mon Sep 17 00:00:00 2001 From: Jason MacWilliams Date: Thu, 14 Jun 2012 15:43:51 -0300 Subject: [PATCH 6/9] updated configurations to save display mode as well and config options, also report a successful save to the user --- ObjectDetails.inc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ObjectDetails.inc b/ObjectDetails.inc index 9ee2d88b..38409615 100644 --- a/ObjectDetails.inc +++ b/ObjectDetails.inc @@ -207,8 +207,10 @@ function fedora_repository_object_details_XSLT_config() { * The user supplied values for the form. */ function fedora_repository_object_details_XSLT_config_submit($form, &$form_state) { + variable_set('islandora_object_details_display_table', 'xslt'); variable_set('islandora_object_details_xslt_sheet', $form_state['values']['xslt']); variable_set('islandora_object_details_xslt_datastream', $form_state['values']['dsid']); + drupal_set_message('Object Details view has been set to XSLT and your configuration has been saved'); } /** @@ -268,5 +270,7 @@ function fedora_repository_object_details_table_config() { * The user supplied values for the form. */ function fedora_repository_object_details_table_config_submit($form, &$form_state) { + variable_set('islandora_object_details_display_table', 'table'); variable_set('islandora_object_details_table_datastream', $form_state['values']['dsid']); + drupal_set_message('Object Details view has been set to Table and your configuration has been saved'); } From 5db38dde915f091fbafa1b8eca24ab42d60b2b6c Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Mon, 18 Jun 2012 15:29:22 +0200 Subject: [PATCH 7/9] Use drupal set headers to allow proper page caching, but disable caching... Noticed at first that it wasn't working, and then it made the DB huge... Anyway. --- ObjectHelper.inc | 14 +++++++------- fedora_repository.module | 6 ++++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/ObjectHelper.inc b/ObjectHelper.inc index 25dd8c53..c757fae6 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -186,7 +186,7 @@ class ObjectHelper { //Set what headers we can... if ($mimeType = $info['content_type']) { - header("Content-Type: $mimeType"); + drupal_set_header("Content-Type: $mimeType"); if ($asAttachment) { $suggestedFileName = "$label"; @@ -212,7 +212,7 @@ class ObjectHelper { $suggestedFileName = "$label.$ext"; } - header('Content-Disposition: attachment; filename="' . $suggestedFileName . '"'); + drupal_set_header('Content-Disposition: attachment; filename="' . $suggestedFileName . '"'); } } @@ -227,14 +227,14 @@ class ObjectHelper { unset($query['q']); } - header('HTTP/1.1 307 Moved Temporarily'); - header('Location: ' . url($effective_url, array('query' => $query))); + drupal_set_header('HTTP/1.1 307 Moved Temporarily'); + drupal_set_header('Location: ' . url($effective_url, array('query' => $query))); } elseif ((isset($user) && $user->uid != 0) || $forceSoap || isset($_SERVER['HTTPS'])) { //If not anonymous, soap is force or we're using HTTPS //Have the webserver mediate the transfer (download and restream) if (($contentSize = self::getDatastreamSize($pid, $dsID, TRUE)) > 0) { - header("Content-Length: $contentSize"); + drupal_set_header("Content-Length: $contentSize"); } $opts = array( @@ -253,8 +253,8 @@ class ObjectHelper { } } else { //Try to redirect directly to Fedora. - header('HTTP/1.1 307 Moved Temporarily'); - header('Location: ' . $url); + drupal_set_header('HTTP/1.1 307 Moved Temporarily'); + drupal_set_header('Location: ' . $url); } } else { diff --git a/fedora_repository.module b/fedora_repository.module index 8642de9c..e66c6ce0 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -994,10 +994,10 @@ function fedora_repository_islandora_tabs($content_models, $pid, $page_number) { //can disable showing the object details tab in admin UI if (variable_get('fedora_repository_show_object_details_tab', TRUE)) { $object_details = $obj->showFieldSets(); - $cmodel_tabs = array_merge($cmodels_tabs, $object_details); + $cmodels_tabs = array_merge($cmodels_tabs, $object_details); } - return array_merge($cmodels_tabs, $object_details); + return $cmodels_tabs; } /** @@ -1159,6 +1159,8 @@ function fedora_object_as_attachment($pid, $dsId, $label=NULL, $version=NULL) { drupal_set_message(t("no pid or dsid given to create an object with!")); return ' '; } + //Disable the page cache, so entire datastreams do not get thrown into the page cache. + $GLOBALS['conf']['cache'] = FALSE; $objectHelper = new ObjectHelper(); $objectHelper->makeObject($pid, $dsId, TRUE, $label, FALSE, $version); From 63d505a1f1870b827bb5ea84c87c4679652caf6d Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Mon, 18 Jun 2012 14:06:23 -0300 Subject: [PATCH 8/9] Use the relevant constant. --- fedora_repository.module | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fedora_repository.module b/fedora_repository.module index 27341204..a4f337e9 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -1170,8 +1170,9 @@ function fedora_object_as_attachment($pid, $dsId, $label=NULL, $version=NULL) { drupal_set_message(t("no pid or dsid given to create an object with!")); return ' '; } + //Disable the page cache, so entire datastreams do not get thrown into the page cache. - $GLOBALS['conf']['cache'] = FALSE; + $GLOBALS['conf']['cache'] = CACHE_DISABLED; $objectHelper = new ObjectHelper(); $objectHelper->makeObject($pid, $dsId, TRUE, $label, FALSE, $version); From 08e0c679b3998092ff09f49896fafc5e017ee388 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Mon, 18 Jun 2012 21:43:48 +0200 Subject: [PATCH 9/9] Speed up breadcrumb query. ... Guess it doesn't really do much towards optimization server-side. --- ObjectHelper.inc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ObjectHelper.inc b/ObjectHelper.inc index 564c451e..396505d4 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -1047,12 +1047,11 @@ PREFIX rels-ext: SELECT ?parentObject ?title ?content FROM <#ri> WHERE { - ?this ?relationship ?parentObject . + ?relationship ?parentObject . ?parentObject fedora-model:label ?title ; fedora-model:state fedora-model:Active ; fedora-model:hasModel ?content . FILTER( - sameTerm(?this, ) && ( sameTerm(?relationship, rels-ext:isMemberOfCollection) || sameTerm(?relationship, rels-ext:isMemberOf) ||