Browse Source

Merge branch '6.x' of github.com:Islandora/islandora into 6.x-release

pull/213/head
jonathangreen 12 years ago
parent
commit
a5ed5391fd
  1. 17
      ObjectHelper.inc
  2. 115
      api/tuque.inc
  3. 31
      fedora_repository.module

17
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 {
@ -1026,12 +1026,11 @@ PREFIX rels-ext: <info:fedora/fedora-system:def/relations-external#>
SELECT ?parentObject ?title ?content
FROM <#ri>
WHERE {
?this ?relationship ?parentObject .
<info:fedora/$pid> ?relationship ?parentObject .
?parentObject fedora-model:label ?title ;
fedora-model:state fedora-model:Active ;
fedora-model:hasModel ?content .
FILTER(
sameTerm(?this, <info:fedora/$pid>) &&
(
sameTerm(?relationship, rels-ext:isMemberOfCollection) ||
sameTerm(?relationship, rels-ext:isMemberOf) ||

115
api/tuque.inc

@ -0,0 +1,115 @@
<?php
$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 "$islandora_module_path/libraries/tuque/Datastream.php";
@include_once "$islandora_module_path/libraries/tuque/FedoraApi.php";
@include_once "$islandora_module_path/libraries/tuque/FedoraApiSerializer.php";
@include_once "$islandora_module_path/libraries/tuque/Object.php";
@include_once "$islandora_module_path/libraries/tuque/RepositoryConnection.php";
@include_once "$islandora_module_path/libraries/tuque/Cache.php";
@include_once "$islandora_module_path/libraries/tuque/RepositoryException.php";
@include_once "$islandora_module_path/libraries/tuque/Repository.php";
@include_once "$islandora_module_path/libraries/tuque/FedoraRelationships.php";
class IslandoraTuque {
/**
* Connection to the repository
*
* @var RepositoryConnection
*/
public $connection = NULL;
/**
* The Fedora API we are using
*
* @var FedoraAPI
*/
public $api = NULL;
/**
* The cache we use to connect.
*
* @var SimpleCache
*/
public $cache = NULL;
/**
* The repository object.
*
* @var FedoraRepository
*/
public $repository = NULL;
function __construct($user = NULL, $url = NULL) {
if(!isset($user)) {
global $user;
}
if(!isset($user) || $user->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);
}
}
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;
}
}

31
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;
}
@ -1163,6 +1171,9 @@ function fedora_object_as_attachment($pid, $dsId, $label=NULL, $version=NULL) {
return ' ';
}
//Disable the page cache, so entire datastreams do not get thrown into the page cache.
$GLOBALS['conf']['cache'] = CACHE_DISABLED;
$objectHelper = new ObjectHelper();
$objectHelper->makeObject($pid, $dsId, TRUE, $label, FALSE, $version);
}

Loading…
Cancel
Save