Browse Source

Merge pull request #316 from adam-vessey/7.x

Code standards in comments and translatability.
pull/317/merge
Jonathan Green 12 years ago
parent
commit
5caa3bc4e0
  1. 115
      includes/solution_packs.inc
  2. 58
      includes/utilities.inc
  3. 2
      tests/islandora_manage_permissions.test

115
includes/solution_packs.inc

@ -187,30 +187,48 @@ function islandora_solution_pack_form_submit(array $form, array &$form_state) {
*/ */
function islandora_solution_pack_batch_operation_reingest_object(NewFedoraObject $object, array &$context) { function islandora_solution_pack_batch_operation_reingest_object(NewFedoraObject $object, array &$context) {
$existing_object = islandora_object_load($object->id); $existing_object = islandora_object_load($object->id);
$deleted = FALSE;
if ($existing_object) { if ($existing_object) {
$deleted = islandora_delete_object($existing_object); $deleted = islandora_delete_object($existing_object);
if (!$deleted) { if (!$deleted) {
$object_link = l($existing_object->label, "islandora/object/{$existing_object->id}"); $object_link = l($existing_object->label, "islandora/object/{$existing_object->id}");
drupal_set_message(t('Failed to purge existing object !object_link.', array( drupal_set_message(filter_xss(t('Failed to purge existing object !object_link.', array(
'!object_link' => $object_link, '!object_link' => $object_link,
)), 'error'); ))), 'error');
// Failed to purge don't attempt to ingest. // Failed to purge don't attempt to ingest.
return; return;
} }
} }
// Object was deleted or did not exist. // Object was deleted or did not exist.
$pid = $object->id; $pid = $object->id;
$label = $object->label; $label = $object->label;
$action = $deleted ? 'reinstalled' : 'installed';
$object_link = l($label, "islandora/object/{$pid}"); $object_link = l($label, "islandora/object/{$pid}");
$object = islandora_add_object($object); $object = islandora_add_object($object);
$msg = $object ? "Successfully $action !object_link." : "Failed to $action @label identified by @pid."; $params = array(
'@pid' => $pid,
'@label' => $label,
'!object_link' => $object_link,
);
$msg = '';
if ($object) {
if ($deleted) {
$msg = t('Successfully reinstalled !object_link.', $params);
}
else {
$msg = t('Successfully installed !object_link.', $params);
}
}
elseif ($deleted) {
$msg = t('Failed to reinstall @label, identified by @pid.', $params);
}
else {
$msg = t('Failed to install @label, identified by @pid.', $params);
}
$status = $object ? 'status' : 'error'; $status = $object ? 'status' : 'error';
drupal_set_message(t($msg, array( drupal_set_message(filter_xss($msg), $status);
'@pid' => $pid,
'@label' => $label,
'!object_link' => $object_link,
)), $status);
} }
/** /**
@ -237,33 +255,37 @@ function islandora_install_solution_pack($module, $op = 'install') {
islandora_uninstall_solution_pack($module); islandora_uninstall_solution_pack($module);
return; return;
} }
$t = get_t();
// Some general replacements.
$admin_link = l($t('Solution Pack admin'), 'admin/islandora/solution_packs');
$config_link = l($t('Islandora configuration'), 'admin/islandora/configure');
$t_params = array(
'@module' => $module,
'!config_link' => $config_link,
'!admin_link' => $admin_link,
);
module_load_include('module', 'islandora', 'islandora'); module_load_include('module', 'islandora', 'islandora');
module_load_include('inc', 'islandora', 'includes/utilities'); module_load_include('inc', 'islandora', 'includes/utilities');
module_load_include('module', $module, $module); module_load_include('module', $module, $module);
$info_file = drupal_get_path('module', $module) . "/{$module}.info"; $info_file = drupal_get_path('module', $module) . "/{$module}.info";
$info_array = drupal_parse_info_file($info_file); $info_array = drupal_parse_info_file($info_file);
$module_name = $info_array['name']; $module_name = $info_array['name'];
$admin_link = l(t('Solution Pack admin'), 'admin/islandora/solution_packs');
$config_link = l(t('Islandora configuration'), 'admin/islandora/configure');
if (!islandora_describe_repository()) { if (!islandora_describe_repository()) {
$msg = '@module: Did not install any objects. Could not connect to the '; $msg = $t('@module: Did not install any objects. Could not connect to the repository. Please check the settings on the !config_link page and install the required objects manually on the !admin_link page.', $t_params);
$msg .= 'repository. Please check the settings on the !config_link page '; drupal_set_message(filter_xss($msg), 'error');
$msg .= 'and install the required objects manually on the !admin_link page.';
drupal_set_message(st($msg, array(
'@module' => $module_name,
'!config_link' => $config_link,
'@admin_link' => $admin_link,
)), 'error');
return; return;
} }
$connection = islandora_get_tuque_connection(); $connection = islandora_get_tuque_connection();
$required_objects = module_invoke($module, 'islandora_required_objects', $connection); $required_objects = module_invoke($module, 'islandora_required_objects', $connection);
$objects = $required_objects[$module]['objects']; $objects = $required_objects[$module]['objects'];
$status_messages = array( $status_messages = array(
'up_to_date' => 'The object already exists and is up-to-date', 'up_to_date' => $t('The object already exists and is up-to-date.', $t_params),
'missing_datastream' => 'The object already exists but is missing a datastream. Please reinstall the object on the !admin_link page', 'missing_datastream' => $t('The object already exists but is missing a datastream. Please reinstall the object on the !admin_link page.', $t_params),
'out_of_date' => 'The object already exists but is out-of-date. Please update the object on the !admin_link page', 'out_of_date' => $t('The object already exists but is out-of-date. Please update the object on the !admin_link page.', $t_params),
'modified_datastream' => 'The object already exists but datastreams are modified. Please reinstall the object on the !admin_link page', 'modified_datastream' => $t('The object already exists but datastreams are modified. Please reinstall the object on the !admin_link page.', $t_params),
); );
foreach ($objects as $object) { foreach ($objects as $object) {
$query = $connection->api->a->findObjects('query', 'pid=' . $object->id); $query = $connection->api->a->findObjects('query', 'pid=' . $object->id);
@ -272,26 +294,25 @@ function islandora_install_solution_pack($module, $op = 'install') {
$object_link = l($label, "islandora/object/{$object->id}"); $object_link = l($label, "islandora/object/{$object->id}");
if ($already_exists) { if ($already_exists) {
$object_status = islandora_check_object_status($object); $object_status = islandora_check_object_status($object);
$status_msg = $status_messages[$object_status['status']]; $here_params = array(
drupal_set_message(st("@module: Did not install !object_link. $status_msg.", array( '!summary' => $t("@module: Did not install !object_link.", array(
'@module' => $module_name,
'!object_link' => $object_link, '!object_link' => $object_link,
'!admin_link' => $admin_link, ) + $t_params),
)), 'warning'); '!description' => $status_messages[$object_status['status']],
);
drupal_set_message(filter_xss(format_string('!summary !description', $here_params)), 'warning');
} }
else { else {
$object = islandora_add_object($object); $object = islandora_add_object($object);
if ($object) { if ($object) {
drupal_set_message(t('@module: Successfully installed. !object_link.', array( drupal_set_message(filter_xss($t('@module: Successfully installed. !object_link.', array(
'@module' => $module_name,
'!object_link' => $object_link, '!object_link' => $object_link,
)), 'status'); ) + $t_params)), 'status');
} }
else { else {
drupal_set_message(t('@module: Failed to install. @label.', array( drupal_set_message($t('@module: Failed to install. @label.', array(
'@module' => $module_name,
'@label' => $label, '@label' => $label,
)), 'warning'); ) + $t_params), 'warning');
} }
} }
} }
@ -307,21 +328,20 @@ function islandora_install_solution_pack($module, $op = 'install') {
* directly for each solution pack. * directly for each solution pack.
*/ */
function islandora_uninstall_solution_pack($module) { function islandora_uninstall_solution_pack($module) {
$t = get_t();
module_load_include('module', 'islandora', 'islandora'); module_load_include('module', 'islandora', 'islandora');
module_load_include('inc', 'islandora', 'includes/utilities'); module_load_include('inc', 'islandora', 'includes/utilities');
module_load_include('module', $module, $module); module_load_include('module', $module, $module);
$config_link = l(t('Islandora configuration'), 'admin/islandora/configure'); $config_link = l($t('Islandora configuration'), 'admin/islandora/configure');
$info_file = drupal_get_path('module', $module) . "/{$module}.info"; $info_file = drupal_get_path('module', $module) . "/{$module}.info";
$info_array = drupal_parse_info_file($info_file); $info_array = drupal_parse_info_file($info_file);
$module_name = $info_array['name']; $module_name = $info_array['name'];
if (!islandora_describe_repository()) { if (!islandora_describe_repository()) {
$msg = '@module: Did not uninstall any objects. Could not connect to the '; $msg = $t('@module: Did not uninstall any objects. Could not connect to the repository. Please check the settings on the !config_link page and uninstall the required objects manually if necessary.', array(
$msg .= 'repository. Please check the settings on the !config_link page '; '@module' => $module_name,
$msg .= 'and uninstall the required objects manually if necessary.'; '!config_link' => $config_link,
drupal_set_message(st($msg, array( ));
'@module' => $module_name, drupal_set_message(filter_xss($msg), 'error');
'!config_link' => $config_link,
)), 'error');
return; return;
} }
$connection = islandora_get_tuque_connection(); $connection = islandora_get_tuque_connection();
@ -334,12 +354,13 @@ function islandora_uninstall_solution_pack($module) {
}; };
$existing_objects = array_filter($objects, $filter); $existing_objects = array_filter($objects, $filter);
foreach ($existing_objects as $object) { foreach ($existing_objects as $object) {
$msg = '@module: Did not remove !object_link. It may be used by other sites.';
$object_link = l($object->label, "islandora/object/{$object->id}"); $object_link = l($object->label, "islandora/object/{$object->id}");
drupal_set_message(st($msg, array( $msg = $t('@module: Did not remove !object_link. It may be used by other sites.', array(
'!object_link' => $object_link, '!object_link' => $object_link,
'@module' => $module_name, '@module' => $module_name,
)), 'warning'); ));
drupal_set_message(filter_xss($msg), 'warning');
} }
} }

58
includes/utilities.inc

@ -380,18 +380,13 @@ function islandora_get_datastreams_requirements_from_models(array $models) {
* determine what datastreams are required. * determine what datastreams are required.
* *
* @return array * @return array
* The DS-COMPOSITE-MODEL defined datastreams that are required for the given * An associative array mapping datastream IDs to associative arrays
* object. * containing the values parsed from the DS-COMPOSITE-MODEL on the given
* * object--of the form:
* @code * - DSID: A datastream ID being described.
* array( * - "id": A string containing ID of the datastream.
* 'DC' => array( * - "mime": A array containing MIME-types the stream may have.
* 'id' => 'DC', * - "optional": A boolean indicating if the given stream is optional.
* 'mime' => 'text/xml',
* 'optional' => FALSE,
* )
* )
* @endcode
*/ */
function islandora_get_datastreams_requirements_from_content_model(FedoraObject $object) { function islandora_get_datastreams_requirements_from_content_model(FedoraObject $object) {
if (empty($object[DS_COMP_STREAM])) { if (empty($object[DS_COMP_STREAM])) {
@ -621,33 +616,24 @@ function islandora_system_settings_form_default_value($name, $default_value, arr
/** /**
* Returns basic information about DS-COMPOSITE-MODEL. * Returns basic information about DS-COMPOSITE-MODEL.
* *
* @deprecated
* The pre-existing--and more flexible--
* islandora_get_datastreams_requirements_from_content_model() should be
* preferred, as it addresses the case where a stream can be allowed to have
* one of a set of mimetypes (this functions appears to only return the last
* declared mimetype for a given datastream).
*
* @param string $pid * @param string $pid
* PID of content model containing DS_COMP stream. * The PID of content model containing DS_COMP stream.
* *
* @return array * @return array
* array of values in the following form * An associative array mapping datastream IDs to an associative array
* * representing the parsed DS-COMPOSITE-MODEL of the form:
* [DC] => Array * - DSID: A string containing the datastream ID.
* ( * - "mimetype": A string containing the last mimetype declared for the
* [mimetype] => text/xml * given datastream ID.
* ) * - "optional": An optional boolean indicating that the given datastream
* * is optional.
* [MODS] => Array
* (
* [optional] => true
* [mimetype] => text/xml
* )
*
* [RELS-EXT] => Array
* (
* [mimetype] => application/rdf+xml
* )
*
* [RELS-INT] => Array
* (
* [optional] => true
* [mimetype] => application/rdf+xml
* )
*/ */
function islandora_get_comp_ds_mappings($pid) { function islandora_get_comp_ds_mappings($pid) {
$cm_object = islandora_object_load($pid); $cm_object = islandora_object_load($pid);

2
tests/islandora_manage_permissions.test

@ -90,7 +90,7 @@ class IslandoraPermissionsTestCase extends IslandoraWebTestCase {
*/ */
public function testAccessFunctions() { public function testAccessFunctions() {
$object = islandora_object_load(variable_get('islandora_repository_pid', 'islandora:root')); $object = islandora_object_load(variable_get('islandora_repository_pid', 'islandora:root'));
// Test islandora_user_access(); // Test islandora_user_access().
// Test no object/permissions. // Test no object/permissions.
$ret = islandora_user_access(NULL, array()); $ret = islandora_user_access(NULL, array());
$this->assertFalse($ret, 'User access denied when no object/permissions are provided.'); $this->assertFalse($ret, 'User access denied when no object/permissions are provided.');

Loading…
Cancel
Save