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. 35
      fedora_repository.module

35
fedora_repository.module

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

Loading…
Cancel
Save