Browse Source

code review feedback.

pull/499/head
MorganDawe 11 years ago
parent
commit
a98ea9dfa7
  1. 50
      includes/datastream.version.inc
  2. 12
      islandora.module
  3. 3
      theme/theme.inc

50
includes/datastream.version.inc

@ -252,48 +252,35 @@ function islandora_datastream_version_replace_form($form, &$form_state, Abstract
$form_state['object_id'] = $object->id;
$form_state['dsid'] = $datastream->id;
$form_state['object'] = $object;
$extensions = islandora_get_datastreams_requirements_from_models($object->models);
$ext = array(NULL);
if(isset($extensions[$datastream->id]['mime'])) {
$ext = array(implode(",", $extensions[$datastream->id]['mime']));
}
$upload_size = min((int) ini_get('post_max_size'), (int) ini_get('upload_max_filesize'));
return array(
'#redirect' => "islandora/object/{$object->id}",
'#attributes' => array(
'enctype' => 'multipart/form-data',
),
'dsid_fieldset' => array(
'#type' => 'fieldset',
'#title' => 'Update datastream with latest version',
'#title' => t("Update datastream with latest version"),
'#collapsible' => FALSE,
'#collapsed' => FALSE,
'dsid' => array(
'#disabled' => TRUE,
'#default_value' => $datastream->id,
'#title' => 'Datastream ID',
'#description' => t("The current ID for this stream that is unique to this object."),
'#type' => 'textfield',
'#size' => 64,
'#maxlength' => 64,
'#required' => TRUE,
'#type' => 'markup',
'#markup' => "<div>DSID: <b>$datastream->id</b></div>",
),
'label' => array(
'#disabled' => TRUE,
'#default_value' => $datastream->label,
'#title' => 'Datastream Label',
'#required' => TRUE,
'#size' => 64,
'#maxlength' => 64,
'#description' => t('The DSID human-readable label'),
'#type' => 'textfield',
'#type' => 'markup',
'#markup' => "<div>Label: <b>$datastream->label</b></div>",
),
'file' => array(
'#type' => 'managed_file',
'#required' => TRUE,
'#title' => t('Upload Document'),
'#size' => 48,
'#description' => t('Select a file to upload.<br/>Files must be less than <b>@size MB.</b>', array('@size' => $upload_size)),
'#default_value' => isset($form_state['values']['files']) ? $form_state['values']['files'] : NULL,
'#size' => 64,
'#description' => t('Select a file to upload.<br/>Files must be less than <strong>@size MB.</strong>', array('@size' => $upload_size)),
'#upload_location' => 'temporary://',
'#upload_validators' => array(
'file_validate_extensions' => array(NULL),
'file_validate_extensions' => $ext,
// Assume its specified in MB.
'file_validate_size' => array($upload_size * 1024 * 1024),
),
@ -329,12 +316,19 @@ function islandora_datastream_version_replace_form_submit($form, &$form_state) {
file_delete($file);
}
catch (exception $e) {
drupal_set_message(t('@message', array('@message' => check_plain($e->getMessage()))), 'error');
drupal_set_message(t('An error occurred during datastream updates. See watchlog for more information.'), 'error');
watchdog('islandora',
'Failed to add new versionable datastream.</br>code: @code<br/>message: @msg',
array(
'@code' => $e->getCode(),
'@msg' => $e->getMessage(),
),
WATCHDOG_ERROR
);
file_delete($file);
return;
}
drupal_set_message(t("Successfully Updated Datastream"));
$form_state['redirect'] = "islandora/object/{$object->id}";
}
/**

12
islandora.module

@ -34,11 +34,10 @@ define('ISLANDORA_INGEST', 'ingest fedora objects');
define('ISLANDORA_PURGE', 'delete fedora objects and datastreams');
define('ISLANDORA_MANAGE_PROPERTIES', 'manage object properties');
define('ISLANDORA_VIEW_DATASTREAM_HISTORY', 'view old datastream versions');
define('ISLANDORA_ADD_NEW_DATASTREAM_VERSION', 'add a new datastream version as latest');
define('ISLANDORA_MANAGE_DELETED_OBJECTS', 'manage deleted objects');
define('ISLANDORA_REVERT_DATASTREAM', 'revert to old datastream');
define('ISLANDORA_REGENERATE_DERIVATIVES', 'regenerate derivatives for an object');
define('ISLANDORA_REPLACE_DATASTREAM', 'replace a datastream with new content, preserving version history');
define('ISLANDORA_REPLACE_DATASTREAM_CONTENT', 'replace a datastream with new content, preserving version history');
// Hooks.
define('ISLANDORA_VIEW_HOOK', 'islandora_view_object');
@ -325,7 +324,7 @@ function islandora_menu() {
'file' => 'includes/datastream.version.inc',
'type' => MENU_CALLBACK,
'access callback' => 'islandora_datastream_access',
'access arguments' => array(ISLANDORA_ADD_NEW_DATASTREAM_VERSION, 4),
'access arguments' => array(ISLANDORA_REPLACE_DATASTREAM_CONTENT, 4),
'load arguments' => array(2),
);
$items['islandora/object/%islandora_object/datastream/%islandora_datastream/version/%/delete'] = array(
@ -597,10 +596,6 @@ function islandora_permission() {
'title' => t('View datastream history'),
'description' => t('View all previous versions of a datastream.'),
),
ISLANDORA_ADD_NEW_DATASTREAM_VERSION => array(
'title' => t('Add datastream version'),
'description' => t('Add to a datastreams version history as latest.'),
),
ISLANDORA_REVERT_DATASTREAM => array(
'title' => t('Revert datastream history'),
'description' => t('Revert to a previous version of a datastream.'),
@ -613,7 +608,7 @@ function islandora_permission() {
'title' => t('Regenerate derivatives'),
'description' => t('Regenerate derivatives for an object or per datastream.'),
),
ISLANDORA_REPLACE_DATASTREAM => array(
ISLANDORA_REPLACE_DATASTREAM_CONTENT => array(
'title' => t('Replace derivatives'),
'description' => t('Replace derivatives for an object or per datastream.'),
),
@ -722,6 +717,7 @@ function islandora_forms($form_id) {
* otherwise.
*/
function islandora_user_access($object_or_datastream, array $permissions, $content_models = array(), $access_any = TRUE, $user = NULL) {
module_load_include('inc', 'islandora', 'includes/utilities');
$is_repository_accessible = &drupal_static(__FUNCTION__);

3
theme/theme.inc

@ -456,8 +456,7 @@ function theme_islandora_datastream_version_link(array $vars) {
*/
function theme_islandora_datastream_replace_link(array $vars) {
$datastream = $vars['datastream'];
if (islandora_datastream_access(ISLANDORA_REPLACE_DATASTREAM, $datastream) &&
islandora_datastream_access(ISLANDORA_ADD_NEW_DATASTREAM_VERSION, $datastream)) {
if (islandora_datastream_access(ISLANDORA_REPLACE_DATASTREAM_CONTENT, $datastream)) {
$var_string = variable_get("islandora_ds_replace_exclude_enforced", "RELS-EXT,RELS-INT");
$replace_exclude = explode(",", $var_string);
if (!in_array($datastream->id, $replace_exclude)) {

Loading…
Cancel
Save