Browse Source

Use wrapping modify_datastream wrapper in replace datastream callback.

pull/126/head
Adam Vessey 13 years ago
parent
commit
fe7628559f
  1. 31
      fedora_repository.module

31
fedora_repository.module

@ -658,10 +658,10 @@ function fedora_repository_replace_stream_form_validate($form, &$form_state) {
return; return;
} }
$doc = new DOMDocument(); module_load_include('inc', 'fedora_repository', 'MimeClass');
module_load_include('inc', 'Fedora_Repository', 'MimeClass');
$mime = new MimeClass(); $mime = new MimeClass();
if ($mime->getType($file->filepath) == 'text/xml' && !$doc->load($file->filepath)) {
if ($mime->getType($file->filepath) == 'text/xml' && !DOMDocument::load($file->filepath)) {
form_set_error('file', 'Invalid XML format.'); form_set_error('file', 'Invalid XML format.');
return; return;
} }
@ -683,39 +683,32 @@ function fedora_repository_replace_stream_form_submit($form, &$form_state) {
$pid = $form_state['values']['pid']; $pid = $form_state['values']['pid'];
$dsid = $form_state['values']['dsId']; $dsid = $form_state['values']['dsId'];
$dsLabel = $form_state['values']['dsLabel']; $dsLabel = $form_state['values']['dsLabel'];
// Remove the original file extension from the label and add the new one // Remove the original file extension from the label and add the new one
$indexOfDot = strrpos($dsLabel, '.'); //use strrpos to get the last dot $indexOfDot = strrpos($dsLabel, '.'); //use strrpos to get the last dot
if ($indexOfDot !== FALSE) { if ($indexOfDot !== FALSE) {
$dsLabel = substr($dsLabel, 0, $indexOfDot); $dsLabel = substr($dsLabel, 0, $indexOfDot);
$dsLabel .= substr($file->filename, strrpos($file->filename, '.')); // Add the file extention to the end of the label.; $dsLabel .= substr($file->filename, strrpos($file->filename, '.')); // Add the file extention to the end of the label.;
} }
module_load_include('inc', 'Fedora_Repository', 'MimeClass');
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$file_basename = basename($file->filepath); $streamUrl = url($file->filepath, array(
$file_directory = dirname($file->filepath); 'absolute' => TRUE,
$streamUrl = $base_url . '/' . $file_directory . '/' . urlencode($file_basename); ));
/* ----------------------------------------------------------------- /* -----------------------------------------------------------------
* TODO: need a better way to get mimetypes * TODO: need a better way to get mimetypes
*/ */
module_load_include('inc', 'fedora_repository', 'MimeClass');
$mimetype = new MimeClass(); $mimetype = new MimeClass();
$dformat = $mimetype->getType($file->filepath); $dformat = $mimetype->getType($file->filepath);
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$item = new Fedora_Item($pid); $item = new Fedora_Item($pid);
$info = $item->get_datastream_info($dsid);
if($info->datastream->controlGroup == 'M') { if(in_array($info->datastream->controlGroup, array('M', 'X'))) {
$item->modify_datastream_by_reference($streamUrl, $dsid, $dsLabel, $dformat); $item->modify_datastream($streamUrl, $dsid, $dsLabel, $dformat);
} elseif ($info->datastream->controlGroup == 'X') {
if($dformat == 'text/xml') {
$item->modify_datastream_by_value(file_get_contents($file->filepath), $dsid, $dsLabel, $dformat);
}
else {
drupal_set_message('File must be of mimetype text/xml in order to replace inline XML datastream.', 'error');
}
} else { } else {
drupal_set_message('Cannot replace Redirect or Managed Datastream.', 'error'); drupal_set_message(t('Cannot replace Redirect or Managed Datastream.'), 'error');
} }
$form_state['redirect'] = 'fedora/repository/' . $pid; $form_state['redirect'] = 'fedora/repository/' . $pid;

Loading…
Cancel
Save