Browse Source

Make control group selection optional.

pull/126/head
Adam Vessey 13 years ago
parent
commit
b609a8fd5c
  1. 62
      fedora_repository.module
  2. 50
      formClass.inc

62
fedora_repository.module

@ -388,7 +388,7 @@ function add_stream_form_submit($form, &$form_state) {
try { try {
$item = new Fedora_Item($pid); $item = new Fedora_Item($pid);
$item->add_datastream_from_url($form_state['storage']['stream_url'], $dsid, $dsLabel, $form_state['storage']['ds_mimetype'], $form_state['values']['control_group']); $item->add_datastream_from_url($form_state['storage']['stream_url'], $dsid, $dsLabel, $form_state['storage']['ds_mimetype'], $form_state['storage']['control_group']);
if ($file = $form_state['values']['add-stream-file-location']) { if ($file = $form_state['values']['add-stream-file-location']) {
$object_helper = new ObjectHelper(); $object_helper = new ObjectHelper();
@ -450,14 +450,12 @@ function add_stream_form_validate($form, &$form_state) {
// 'file_validate_image_resolution' => array('85x85'), // 'file_validate_image_resolution' => array('85x85'),
// 'file_validate_size' => array(30 * 1024), // 'file_validate_size' => array(30 * 1024),
); );
$mimetype = new MimeClass(); $controlGroup = $form_state['storage']['control_group'] = $form_state['values']['control_group'];
$controlGroup = $form_state['values']['control_group']; if ((($controlGroup && in_array($controlGroup, array('X', 'M'))) || !$controlGroup) && (($fileObject = file_save_upload('add-stream-file-location', $validators)) !== 0)) {
if (in_array($controlGroup, array('X', 'M')) && ($fileObject = file_save_upload('add-stream-file-location', $validators)) !== 0) {
// Move the uploaded file to Drupal's files directory. // Move the uploaded file to Drupal's files directory.
file_move($fileObject->filepath, 0, 'FILE_EXISTS_RENAME'); file_move($fileObject->filepath, 0, 'FILE_EXISTS_RENAME');
$form_state['values']['add-stream-file-location'] = $fileObject->filepath; $form_state['values']['add-stream-file-location'] = $fileObject->filepath;
$form_state['storage']['ds_mimetype'] = $mimetype->getType($fileObject->filepath);
$file_basename = basename($fileObject->filepath); $file_basename = basename($fileObject->filepath);
$file_directory = dirname($fileObject->filepath); $file_directory = dirname($fileObject->filepath);
@ -466,14 +464,25 @@ function add_stream_form_validate($form, &$form_state) {
'absolute' => TRUE, 'absolute' => TRUE,
)); ));
} }
elseif (in_array($controlGroup, array('M', 'R', 'E')) && ($ref = $form_state['values']['ds_reference'])) { elseif ($controlGroup && in_array($controlGroup, array('M', 'R', 'E')) && ($ref = $form_state['values']['ds_reference'])) {
$form_state['storage']['ds_mimetype'] = $mimetype->getType($ref);
$form_state['storage']['stream_url'] = $form_state['values']['ds_reference']; $form_state['storage']['stream_url'] = $form_state['values']['ds_reference'];
} }
else { else {
form_set_error('', t('No file given when "X" or "M", or no reference given when "M", "R" or "E".')); form_set_error('', t('No file given when "X" or "M", or no reference given when "M", "R" or "E".'));
} }
$mimeClass = new MimeClass();
$mimetype = $form_state['storage']['ds_mimetype'] = $mimeClass->getType($form_state['storage']['stream_url']);
if (!$controlGroup) {
if ($mimetype == 'text/xml') {
$form_state['storage']['control_group'] = 'X';
}
else {
$form_state['storage']['control_group'] = 'M';
}
}
// TODO: Add error checking here. // TODO: Add error checking here.
$form_state['rebuild'] = FALSE; $form_state['rebuild'] = FALSE;
} }
@ -665,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;
} }
@ -685,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;

50
formClass.inc

@ -331,6 +331,13 @@ class formClass {
'#options' => array(ObjectHelper::$DISPLAY_ALWAYS => t('Always'), ObjectHelper::$DISPLAY_NEVER => t('Never'), ObjectHelper::$DISPLAY_NO_MODEL_OUTPUT => t('Only if no Content Model display output.')), '#options' => array(ObjectHelper::$DISPLAY_ALWAYS => t('Always'), ObjectHelper::$DISPLAY_NEVER => t('Never'), ObjectHelper::$DISPLAY_NO_MODEL_OUTPUT => t('Only if no Content Model display output.')),
'#description' => t('Determines when to display the list of objects when viewing a collection page.'), '#description' => t('Determines when to display the list of objects when viewing a collection page.'),
); );
$form['advanced']['fedora_control_group_control_during_ingest'] = array(
'#type' => 'checkbox',
'#title' => t('Allow control groups select in datastream ingest'),
'#description' => t('Whether or not we should allow the user to select which control group to ingest a stream as, or to follow the old paradigm--to add stream IDed as XML as inline, and everything else as managed.'),
'#default_value' => variable_get('fedora_control_group_control_during_ingest', FALSE),
);
//Export functionality //Export functionality
$form['advanced']['module']['export_area'] = array( $form['advanced']['module']['export_area'] = array(
@ -685,12 +692,16 @@ class formClass {
// '#required'=>'TRUE', // '#required'=>'TRUE',
'#description' => t('The file to upload. (Only for Managed and Inline)') '#description' => t('The file to upload. (Only for Managed and Inline)')
); );
$form['fieldset']['ds_reference'] = array(
'#type' => 'textfield', if (variable_get('fedora_control_group_control_during_ingest', FALSE)) {
'#title' => t('Datastream reference'), $form['fieldset']['ds_reference'] = array(
'#size' => 48, '#type' => 'textfield',
'#description' => t('A URL reference to resolve for the contents of the datastream. (Required for External and Redirect, but will still work for Managed and Inline.)'), '#title' => t('Datastream reference'),
); '#size' => 48,
'#description' => t('A URL reference to resolve for the contents of the datastream. (Required for External and Redirect, but will still work for Managed and Inline.)'),
);
}
$form['#redirect'] = "fedora/repository/$pid/"; $form['#redirect'] = "fedora/repository/$pid/";
$form['fieldset']['submit'] = array( $form['fieldset']['submit'] = array(
'#type' => 'submit', '#type' => 'submit',
@ -716,18 +727,21 @@ class formClass {
'#weight' => -1, '#weight' => -1,
); );
} }
$form['fieldset']['control_group'] = array(
'#type' => 'select', if (variable_get('fedora_control_group_control_during_ingest', FALSE)) {
'#title' => t('Control group'), $form['fieldset']['control_group'] = array(
'#options' => array( '#type' => 'select',
'X' => t('Inline XML'), '#title' => t('Control group'),
'M' => t('Managed datastream'), '#options' => array(
'E' => t('Externally Referenced/managed datastream'), 'X' => t('Inline XML'),
'R' => t('Redirect datastream'), 'M' => t('Managed datastream'),
), 'E' => t('Externally Referenced/managed datastream'),
'#description' => t('The manner in which the datastream will be stored. "Inline XML" must be XML and will be placed directly into the FOXML for the object. "Managed" datastreams are made to live on the filesystem as discrete files in the Fedora data directory. Both "Redirect" and "External" streams are URL references; the difference being the redirect stream instruct clients to perform an HTTP redirect, such that the data does not pass though Fedora (useful for streaming). External streams are mediated (by which I mean loaded and streamed from) the Fedora server.'), 'R' => t('Redirect datastream'),
'#weight' => 0, ),
); '#description' => t('The manner in which the datastream will be stored. "Inline XML" must be XML and will be placed directly into the FOXML for the object. "Managed" datastreams are made to live on the filesystem as discrete files in the Fedora data directory. Both "Redirect" and "External" streams are URL references; the difference being the redirect stream instruct clients to perform an HTTP redirect, such that the data does not pass though Fedora (useful for streaming). External streams are mediated (by which I mean loaded and streamed from) the Fedora server.'),
'#weight' => 0,
);
}
return $form; return $form;
} }

Loading…
Cancel
Save