Browse Source

Merge pull request #305 from MorganDawe/7.x

Updated islandora_prepare_new_object to work with file system path.
pull/315/merge
William Panting 12 years ago
parent
commit
c66fcbb7d7
  1. 4
      includes/ingest.form.inc
  2. 8
      includes/tuque_wrapper.inc
  3. 34
      includes/utilities.inc
  4. 2
      islandora.module
  5. 10
      tests/hooks.test

4
includes/ingest.form.inc

@ -35,7 +35,7 @@ function islandora_ingest_form(array $form, array &$form_state, array $configura
islandora_ingest_form_init_form_state_storage($form_state, $configuration); islandora_ingest_form_init_form_state_storage($form_state, $configuration);
return islandora_ingest_form_execute_step($form, $form_state); return islandora_ingest_form_execute_step($form, $form_state);
} }
catch(Exception $e) { catch (Exception $e) {
drupal_set_message($e->getMessage(), 'error'); drupal_set_message($e->getMessage(), 'error');
return array(array( return array(array(
'#markup' => l(t('Back'), 'javascript:window.history.back();', array('external' => TRUE)))); '#markup' => l(t('Back'), 'javascript:window.history.back();', array('external' => TRUE))));
@ -242,7 +242,7 @@ function islandora_ingest_get_approximate_steps(array $configuration) {
try { try {
islandora_ingest_form_validate_configuration($configuration); islandora_ingest_form_validate_configuration($configuration);
} }
catch(InvalidArgumentException $e) { catch (InvalidArgumentException $e) {
// Don't log or display exception. // Don't log or display exception.
return array(); return array();
} }

8
includes/tuque_wrapper.inc

@ -205,7 +205,7 @@ class IslandoraFedoraApiM extends FedoraApiM {
} }
return $ret; return $ret;
} }
catch(Exception $e) { catch (Exception $e) {
watchdog('islandora', 'Failed to modify datastream @dsid from @pid</br>code: @code<br/>message: @msg', array( watchdog('islandora', 'Failed to modify datastream @dsid from @pid</br>code: @code<br/>message: @msg', array(
'@pid' => $pid, '@pid' => $pid,
'@dsid' => $dsid, '@dsid' => $dsid,
@ -239,7 +239,7 @@ class IslandoraFedoraApiM extends FedoraApiM {
} }
return $ret; return $ret;
} }
catch(Exception $e) { catch (Exception $e) {
watchdog('islandora', 'Failed to modify object: @pid</br>code: @code<br/>message: @msg', array( watchdog('islandora', 'Failed to modify object: @pid</br>code: @code<br/>message: @msg', array(
'@pid' => $pid, '@pid' => $pid,
'@code' => $e->getCode(), '@code' => $e->getCode(),
@ -281,7 +281,7 @@ class IslandoraFedoraApiM extends FedoraApiM {
return $ret; return $ret;
} }
} }
catch(Exception $e) { catch (Exception $e) {
watchdog('islandora', 'Failed to purge datastream @dsid from @pid</br>code: @code<br/>message: @msg', array( watchdog('islandora', 'Failed to purge datastream @dsid from @pid</br>code: @code<br/>message: @msg', array(
'@pid' => $pid, '@pid' => $pid,
'@dsid' => $dsid, '@dsid' => $dsid,
@ -325,7 +325,7 @@ class IslandoraFedoraApiM extends FedoraApiM {
return $ret; return $ret;
} }
} }
catch(Exception $e) { catch (Exception $e) {
watchdog('islandora', 'Failed to purge object @pid</br>code: @code<br/>message: @msg', array( watchdog('islandora', 'Failed to purge object @pid</br>code: @code<br/>message: @msg', array(
'@pid' => $pid, '@pid' => $pid,
'@code' => $e->getCode(), '@code' => $e->getCode(),

34
includes/utilities.inc

@ -465,20 +465,44 @@ function islandora_prepare_new_object($namespace = NULL, $label = NULL, $datastr
if (isset($ds['control_group']) && in_array($ds['control_group'], $groups)) { if (isset($ds['control_group']) && in_array($ds['control_group'], $groups)) {
$control_group = $ds['control_group']; $control_group = $ds['control_group'];
} }
$ds_uri = FALSE;
$as_file = FALSE;
if (file_valid_uri($ds['datastream_file'])) { if (file_valid_uri($ds['datastream_file'])) {
// A local file with as a Drupal file/stream wrapper URI.
$datastream_file = $ds['datastream_file'];
$as_file = TRUE;
}
elseif (is_readable($ds['datastream_file'])) {
// A local file as a filesystem path.
$datastream_file = drupal_realpath($ds['datastream_file']);
$as_file = TRUE;
}
else {
$scheme = parse_url($ds['datastream_file'], PHP_URL_SCHEME);
if (in_array($scheme, stream_get_wrappers())) {
// A URI which gets handled by one of the PHP-native stream wrappers.
$datastream_file = $ds['datastream_file']; $datastream_file = $ds['datastream_file'];
$ds_uri = TRUE; $as_file = TRUE;
} }
else { else {
// Schema does not match available php stream wrapper. Attempt to
// set datastream_file by url for the given scheme. Https (SSL) can
// cause this to fail, and trigger an output log in watchdog.
$datastream_file = url($ds['datastream_file'], array('absolute' => TRUE)); $datastream_file = url($ds['datastream_file'], array('absolute' => TRUE));
watchdog('islandora', 'Attempting to ingest %file in islandora_prepare_new_object(), ' .
' but it does not appear to be readable. We will pass the path through' .
' url(), and pass along as such.',
array('%file' => $datastream_file),
WATCHDOG_WARNING);
} }
}
$datastream = $object->constructDatastream($dsid, $control_group); $datastream = $object->constructDatastream($dsid, $control_group);
$datastream->label = $label; $datastream->label = $label;
$datastream->mimetype = $mimetype; $datastream->mimetype = $mimetype;
switch ($control_group) { switch ($control_group) {
case 'M': case 'M':
if ($ds_uri) { if ($as_file) {
$datastream->setContentFromFile($datastream_file); $datastream->setContentFromFile($datastream_file);
} }
else { else {
@ -490,8 +514,10 @@ function islandora_prepare_new_object($namespace = NULL, $label = NULL, $datastr
$datastream->setContentFromString(file_get_contents($datastream_file)); $datastream->setContentFromString(file_get_contents($datastream_file));
break; break;
} }
$object->ingestDatastream($datastream); $object->ingestDatastream($datastream);
} }
return $object; return $object;
} }
@ -506,7 +532,7 @@ function islandora_display_repository_inaccessible_message() {
$link = l($text, 'admin/islandora/configure', array('attributes' => array('title' => $text))); $link = l($text, 'admin/islandora/configure', array('attributes' => array('title' => $text)));
$message = t('Could not connect to the repository. Please check the settings on the !link page.', $message = t('Could not connect to the repository. Please check the settings on the !link page.',
array('!link' => $link)); array('!link' => $link));
drupal_set_message($message, 'error', FALSE); drupal_set_message(check_plain($message), 'error', FALSE);
} }
/** /**

2
islandora.module

@ -966,7 +966,7 @@ function islandora_delete_object(FedoraObject &$object) {
$object = NULL; $object = NULL;
return TRUE; return TRUE;
} }
catch(Exception $e) { catch (Exception $e) {
// Exception message gets logged in Tuque Wrapper. // Exception message gets logged in Tuque Wrapper.
return FALSE; return FALSE;
} }

10
tests/hooks.test

@ -67,7 +67,7 @@ class IslandoraHooksTestCase extends IslandoraWebTestCase {
$object->label = "Don't Block"; $object->label = "Don't Block";
$this->repository->purgeObject($object->id); $this->repository->purgeObject($object->id);
} }
catch(Exception $e) { catch (Exception $e) {
// Meh... Either it didn't exist or the purge failed. // Meh... Either it didn't exist or the purge failed.
} }
} }
@ -95,7 +95,7 @@ class IslandoraHooksTestCase extends IslandoraWebTestCase {
$this->fail('Blocked ingest should throw an Exception.'); $this->fail('Blocked ingest should throw an Exception.');
$this->repository->purgeObject($object->id); $this->repository->purgeObject($object->id);
} }
catch(Exception $e) { catch (Exception $e) {
$this->pass('Ingest blocked and exception thrown.'); $this->pass('Ingest blocked and exception thrown.');
$this->assert($_SESSION['islandora_hooks']['alter'][ISLANDORA_OBJECT_INGESTED_HOOK], 'Called "hook_islandora_object_alter" when blocking ingesting via FedoraRepository::ingestObject.'); $this->assert($_SESSION['islandora_hooks']['alter'][ISLANDORA_OBJECT_INGESTED_HOOK], 'Called "hook_islandora_object_alter" when blocking ingesting via FedoraRepository::ingestObject.');
$this->assertFalse($_SESSION['islandora_hooks']['hook'][ISLANDORA_OBJECT_INGESTED_HOOK], 'Did not called ISLANDORA_OBJECT_INGESTED_HOOK when blocking ingesting via FedoraRepository::ingestObject.'); $this->assertFalse($_SESSION['islandora_hooks']['hook'][ISLANDORA_OBJECT_INGESTED_HOOK], 'Did not called ISLANDORA_OBJECT_INGESTED_HOOK when blocking ingesting via FedoraRepository::ingestObject.');
@ -115,7 +115,7 @@ class IslandoraHooksTestCase extends IslandoraWebTestCase {
$object->label = 'block'; $object->label = 'block';
$this->fail('Blocked modify should throw an Exception.'); $this->fail('Blocked modify should throw an Exception.');
} }
catch(Exception $e) { catch (Exception $e) {
$this->pass('Modify blocked and exception thrown.'); $this->pass('Modify blocked and exception thrown.');
$this->assertNotEqual($object->label, 'block', 'Modification did not stick.'); $this->assertNotEqual($object->label, 'block', 'Modification did not stick.');
$this->assert($_SESSION['islandora_hooks']['alter'][ISLANDORA_OBJECT_MODIFIED_HOOK], 'Called "hook_islandora_object_alter" when blocking modifying via set magic functions.'); $this->assert($_SESSION['islandora_hooks']['alter'][ISLANDORA_OBJECT_MODIFIED_HOOK], 'Called "hook_islandora_object_alter" when blocking modifying via set magic functions.');
@ -149,7 +149,7 @@ class IslandoraHooksTestCase extends IslandoraWebTestCase {
$this->repository->purgeObject($object->id); $this->repository->purgeObject($object->id);
$this->fail('Blocked modify should throw an Exception.'); $this->fail('Blocked modify should throw an Exception.');
} }
catch(Exception $e) { catch (Exception $e) {
$this->pass('Modify blocked and exception thrown.'); $this->pass('Modify blocked and exception thrown.');
$this->assert($_SESSION['islandora_hooks']['alter'][ISLANDORA_OBJECT_PURGED_HOOK], 'Called "hook_islandora_object_alter" when blocking purge via FedoraRepository::purgeObject.'); $this->assert($_SESSION['islandora_hooks']['alter'][ISLANDORA_OBJECT_PURGED_HOOK], 'Called "hook_islandora_object_alter" when blocking purge via FedoraRepository::purgeObject.');
$this->assertFalse($_SESSION['islandora_hooks']['hook'][ISLANDORA_OBJECT_PURGED_HOOK], 'Called ISLANDORA_OBJECT_PURGED_HOOK when blocking purge via FedoraRepository::purgeObject.'); $this->assertFalse($_SESSION['islandora_hooks']['hook'][ISLANDORA_OBJECT_PURGED_HOOK], 'Called ISLANDORA_OBJECT_PURGED_HOOK when blocking purge via FedoraRepository::purgeObject.');
@ -191,7 +191,7 @@ class IslandoraHooksTestCase extends IslandoraWebTestCase {
$ds->label = 'block'; $ds->label = 'block';
$this->fail('Blocked modify should throw an Exception.'); $this->fail('Blocked modify should throw an Exception.');
} }
catch(Exception $e) { catch (Exception $e) {
$this->pass('Modify blocked and exception thrown.'); $this->pass('Modify blocked and exception thrown.');
$this->assert($_SESSION['islandora_hooks']['alter'][ISLANDORA_DATASTREAM_MODIFIED_HOOK], 'Called "hook_islandora_datastream_alter" when blocking modifying via set magic functions.'); $this->assert($_SESSION['islandora_hooks']['alter'][ISLANDORA_DATASTREAM_MODIFIED_HOOK], 'Called "hook_islandora_datastream_alter" when blocking modifying via set magic functions.');
$this->assertFALSE($_SESSION['islandora_hooks']['hook'][ISLANDORA_DATASTREAM_MODIFIED_HOOK], 'Called ISLANDORA_DATASTREAM_MODIFIED_HOOK when blocking modifying via set magic functions.'); $this->assertFALSE($_SESSION['islandora_hooks']['hook'][ISLANDORA_DATASTREAM_MODIFIED_HOOK], 'Called ISLANDORA_DATASTREAM_MODIFIED_HOOK when blocking modifying via set magic functions.');

Loading…
Cancel
Save