From 2ba465b33ff0f475bec376719283d2d2da132039 Mon Sep 17 00:00:00 2001 From: Alexander O'Neill Date: Thu, 17 Feb 2011 15:33:22 -0400 Subject: [PATCH] ISLANDORA-158 Fix for non-alphanumeric filenames --- api/fedora_item.inc | 2 +- fedora_repository.module | 25 +++++++++++++++++-------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/api/fedora_item.inc b/api/fedora_item.inc index 463ba6df..59bc1275 100644 --- a/api/fedora_item.inc +++ b/api/fedora_item.inc @@ -96,7 +96,7 @@ class Fedora_Item { 'logMessage' => ($logMessage != null)?$logMessage: 'Ingested object '. $datastream_id ); - return $this->soap_call( 'addDataStream', $params )->datastreamID; + return $this->soap_call( 'addDataStream', $params ); } function add_datastream_from_string($str, $datastream_id, $datastream_label = NULL, $datastream_mimetype = 'text/xml', $controlGroup = 'M',$logMessage = null) { diff --git a/fedora_repository.module b/fedora_repository.module index 62cc48a7..a5b1274f 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -307,8 +307,9 @@ function add_stream_form_submit($form, &$form_state) { $pid = $form_state['values']['pid']; $dsid = $form_state['values']['stream_id']; $dsLabel = $form_state['values']['stream_label'] . substr($file, strrpos($file, '.')); // Add the file extention to the end of the label.; - - $streamUrl = $base_url . '/' . drupal_urlencode($file); + $file_basename = basename($file); + $file_directory = dirname($file); + $streamUrl = $base_url . '/' . $file_directory . '/' . urlencode($file_basename); /* ----------------------------------------------------------------- * need a better way to get mimetypes @@ -518,7 +519,7 @@ function fedora_repository_replace_stream_form_validate($form, &$form_state) { } function fedora_repository_replace_stream_form_submit($form, &$form_state) { - + global $base_url; $file = $form_state['values']['file']; $pid = $form_state['values']['pid']; $dsid = $form_state['values']['dsId']; @@ -526,21 +527,29 @@ function fedora_repository_replace_stream_form_submit($form, &$form_state) { // 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.; + $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', 'ObjectHelper'); module_load_include('inc', 'Fedora_Repository', 'ConnectionHelper'); + module_load_include('inc', 'fedora_repository', 'api/fedora_item'); + + - $streamUrl = file_create_url($file->filepath); + $file_basename = basename($file->filepath); + $file_directory = dirname($file->filepath); + $streamUrl = $base_url . '/' . $file_directory . '/' . urlencode($file_basename); /* ----------------------------------------------------------------- * need a better way to get mimetypes */ $mimetype = new MimeClass(); $dformat = $mimetype->getType($file->filepath); - + $item = new Fedora_Item($pid); + //$item->add_datastream_from_url($streamUrl, $dsid, $dsLabel, $dformat, $controlGroup); + $item->modify_datastream_by_reference($streamUrl, $dsid, $dsLabel, $dformat); + /* $controlGroup = "M"; $function = 'modifyDatastreamByReference'; $params = array( @@ -587,7 +596,7 @@ function fedora_repository_replace_stream_form_submit($form, &$form_state) { drupal_set_message(t($e->getMessage()), 'error'); return; } - +*/ drupal_goto('fedora/repository/' . $pid . '/-/' . $dsId); }