Browse Source

Merge pull request #285 from nigelgbanks/7.x-collection-changes

7.x collection changes
pull/288/merge
Danny Joris 12 years ago
parent
commit
c60a5e8acb
  1. 35
      includes/ingest.form.inc
  2. 65
      includes/utilities.inc

35
includes/ingest.form.inc

@ -31,9 +31,16 @@
* The form definition of the current step.
*/
function islandora_ingest_form(array $form, array &$form_state, array $configuration) {
try {
islandora_ingest_form_init_form_state_storage($form_state, $configuration);
return islandora_ingest_form_execute_step($form, $form_state);
}
catch(Exception $e) {
drupal_set_message($e->getMessage(), 'error');
return array(array(
'#markup' => l(t('Back'), 'javascript:window.history.back();', array('external' => TRUE))));
}
}
/**
* Validates the given ingest configuration.
@ -42,21 +49,16 @@ function islandora_ingest_form(array $form, array &$form_state, array $configura
*
* @todo Add hook for manipulating/validating the configuration.
*
* @see islandora_ingest_form()
*
* @throws InvalidArgumentException
*
* @param array $configuration
* The key value pairs that are used to build the multi-paged ingest process.
*
* @see islandora_ingest_form()
*
* @return bool
* TRUE if the configuration is valid, FALSE otherwise.
*/
function islandora_ingest_form_validiate_configuration(array $configuration) {
function islandora_ingest_form_validate_configuration(array $configuration) {
if (empty($configuration['models'])) {
$message = t('Ingest configuration not vaild, no models were given');
drupal_set_message($message, 'error');
throw new InvalidArgumentException($message);
throw new InvalidArgumentException('Ingest configuration not vaild, no models were given');
}
}
@ -71,8 +73,8 @@ function islandora_ingest_form_validiate_configuration(array $configuration) {
*/
function islandora_ingest_form_init_form_state_storage(array &$form_state, array $configuration) {
if (empty($form_state['islandora'])) {
// Validate the configuration before using it.
islandora_ingest_form_validiate_configuration($configuration);
// Validate the configuration before we use it.
islandora_ingest_form_validate_configuration($configuration);
$object = islandora_ingest_form_prepare_new_object($configuration);
$form_state['islandora'] = array(
'step_id' => NULL,
@ -233,12 +235,19 @@ function islandora_ingest_form_decrement_step(array &$form_state) {
* The list of key/value pairs of configuration.
*/
function islandora_ingest_get_approximate_steps(array $configuration) {
$fake_form_state = array(
try {
islandora_ingest_form_validate_configuration($configuration);
}
catch(InvalidArgumentException $e) {
// Don't log or display exception.
return array();
}
$stubbed_form_state = array(
'islandora' => array(
'shared_storage' => $configuration,
),
);
$steps = islandora_ingest_form_get_steps($fake_form_state);
$steps = islandora_ingest_form_get_steps($stubbed_form_state);
drupal_static_reset('islandora_ingest_form_get_steps');
return $steps;
}

65
includes/utilities.inc

@ -79,6 +79,19 @@ function islandora_is_valid_pid($pid) {
return drupal_strlen(trim($pid)) <= 64 && preg_match('/^([A-Za-z0-9]|-|\.)+:(([A-Za-z0-9])|-|\.|~|_|(%[0-9A-F]{2}))+$/', trim($pid));
}
/**
* Checks if the given namespace is valid.
*
* @param string $namespace
* The namespace to check without the ":" character.
*
* @return bool
* TRUE if valid, FALSE otherwise.
*/
function islandora_is_valid_namespace($namespace) {
return drupal_strlen(trim($namespace)) <= 64 && preg_match('/^([A-Za-z0-9]|-|\.)+$/', trim($namespace));
}
/**
* Checks if the given datastream id is valid.
*
@ -673,3 +686,55 @@ function islandora_user_access_any(array $perms, $account = NULL) {
}
return FALSE;
}
/**
* Gets the list of allowed namespaces as defined by 'islandora_pids_allowed'.
*
* @return array
* The list of namespaces striped of trailing ":" characters.
*/
function islandora_get_allowed_namespaces() {
$matches = array();
$allowed_namespaces = variable_get('islandora_pids_allowed', 'default: demo: changeme: islandora:');
preg_match_all('/([A-Za-z0-9-\.]+):/', $allowed_namespaces, $matches);
return $matches[1];
}
/**
* Gets a list of all existing content models.
*
* If 'islandora_namespace_restriction_enforced' is set to true only return
* content models in the allowed namespace.
*
* @param bool $ignore_system_namespace
* Ignore content models in the 'fedora-system' namespace.
*
* @return array
* An associative array of all existing content models.
* - pid: The PID of the content model object.
* - pid: The PID of the content model object.
* - label: The label of the content model object.
*/
function islandora_get_content_models($ignore_system_namespace = TRUE) {
module_load_include('inc', 'islandora', 'includes/utilities');
$tuque = islandora_get_tuque_connection();
$query = 'select $object $label from <#ri>
where ($object <fedora-model:label> $label
and ($object <fedora-model:hasModel> <info:fedora/fedora-system:ContentModel-3.0>
or $object <fedora-rels-ext:isMemberOfCollection> <info:fedora/islandora:ContentModelsCollection>)
and $object <fedora-model:state> <info:fedora/fedora-system:def/model#Active>)
order by $label';
$content_models = array();
$results = $tuque->repository->ri->itqlQuery($query, 'unlimited');
foreach ($results as $result) {
$content_model = $result['object']['value'];
$label = $result['label']['value'];
$namespace = islandora_get_namespace($content_model);
$ignore = $ignore_system_namespace && $namespace == 'fedora-system';
$ignore |= !islandora_namespace_accessible($namespace);
if (!$ignore) {
$content_models[$content_model] = array('pid' => $content_model, 'label' => $label);
}
}
return $content_models;
}

Loading…
Cancel
Save