Browse Source

Use wrapping modify_datastream wrapper in replace datastream callback.

pull/101/head
Adam Vessey 13 years ago
parent
commit
5aefe46f85
  1. 31
      fedora_repository.module

31
fedora_repository.module

@ -658,10 +658,10 @@ function fedora_repository_replace_stream_form_validate($form, &$form_state) {
return;
}
$doc = new DOMDocument();
module_load_include('inc', 'Fedora_Repository', 'MimeClass');
module_load_include('inc', 'fedora_repository', '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.');
return;
}
@ -683,39 +683,32 @@ function fedora_repository_replace_stream_form_submit($form, &$form_state) {
$pid = $form_state['values']['pid'];
$dsid = $form_state['values']['dsId'];
$dsLabel = $form_state['values']['dsLabel'];
// Remove the original file extension from the label and add the new one
$indexOfDot = strrpos($dsLabel, '.'); //use strrpos to get the last dot
if ($indexOfDot !== FALSE) {
$dsLabel = substr($dsLabel, 0, $indexOfDot);
$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);
$file_directory = dirname($file->filepath);
$streamUrl = $base_url . '/' . $file_directory . '/' . urlencode($file_basename);
$streamUrl = url($file->filepath, array(
'absolute' => TRUE,
));
/* -----------------------------------------------------------------
* TODO: need a better way to get mimetypes
*/
module_load_include('inc', 'fedora_repository', 'MimeClass');
$mimetype = new MimeClass();
$dformat = $mimetype->getType($file->filepath);
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$item = new Fedora_Item($pid);
$info = $item->get_datastream_info($dsid);
if($info->datastream->controlGroup == 'M') {
$item->modify_datastream_by_reference($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');
}
if(in_array($info->datastream->controlGroup, array('M', 'X'))) {
$item->modify_datastream($streamUrl, $dsid, $dsLabel, $dformat);
} 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;

Loading…
Cancel
Save