Browse Source

Fix error when label contains an extension.

Error intro'd during datastream replace 'improvements'.
pull/101/head
Adam Vessey 13 years ago
parent
commit
132248951d
  1. 37
      fedora_repository.module

37
fedora_repository.module

@ -674,10 +674,14 @@ function fedora_repository_replace_stream_form_validate($form, &$form_state) {
return; return;
} }
/* -----------------------------------------------------------------
* TODO: need a better way to get mimetypes
*/
module_load_include('inc', 'fedora_repository', 'MimeClass'); module_load_include('inc', 'fedora_repository', 'MimeClass');
$mime = new MimeClass(); $mime = new MimeClass();
$mimetype = $form_state['storage']['mime_type'] = $mime->getType($file->filepath);
if ($mime->getType($file->filepath) == 'text/xml' && !DOMDocument::load($file->filepath)) { if ($mimetype == 'text/xml' && !DOMDocument::load($file->filepath)) {
form_set_error('file', 'Invalid XML format.'); form_set_error('file', 'Invalid XML format.');
return; return;
} }
@ -694,37 +698,28 @@ function fedora_repository_replace_stream_form_validate($form, &$form_state) {
* @param array $form_state * @param array $form_state
*/ */
function fedora_repository_replace_stream_form_submit($form, &$form_state) { function fedora_repository_replace_stream_form_submit($form, &$form_state) {
global $base_url;
$file = $form_state['values']['file']; $file = $form_state['values']['file'];
if ($file !== NULL) {
$file = $form_state['values']['reference'];
}
$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'];
$streamUrl = ($file !== NULL) ?
url($file->filepath, array('absolute' => TRUE)):
url($form_state['values']['reference'], array('absolute' => TRUE));
// 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 // use strrpos to get the last dot
if ($indexOfDot !== FALSE) { if (($indexOfDot = strrpos($dsLabel, '.')) !== 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.; substr($streamUrl, strrpos($streamUrl, '.')); // Add the file extention to the end of the label.
} }
$streamUrl = url($file->filepath, array(
'absolute' => TRUE,
));
/* ----------------------------------------------------------------- $dformat = $form_state['storage']['mime_type'];
* TODO: need a better way to get mimetypes
*/
module_load_include('inc', 'fedora_repository', 'MimeClass');
$mimetype = new MimeClass();
$dformat = $mimetype->getType($file->filepath);
$item = new Fedora_Item($pid); $item = new Fedora_Item($pid);
$item->modify_datastream($streamUrl, $dsid, $dsLabel, $dformat); $item->modify_datastream($streamUrl, $dsid, $dsLabel, $dformat);
$form_state['redirect'] = 'fedora/repository/' . $pid; $form_state['redirect'] = 'fedora/repository/' . $pid;

Loading…
Cancel
Save