Browse Source

Converted migrate and delete function to use new API

pull/112/head
rwincewicz 13 years ago
parent
commit
520386fdbb
  1. 110
      islandora_basic_collection/includes/CollectionManagerTable.inc
  2. 38
      islandora_basic_collection/includes/DeleteCollection.inc
  3. 28
      islandora_basic_collection/includes/MoveCollection.inc
  4. 68
      islandora_basic_collection/islandora_basic_collection.module

110
islandora_basic_collection/includes/CollectionManagerTable.inc

@ -6,73 +6,56 @@
* @param string $collection_pid
* @return array
*/
function islandora_collection_table($collection_pid) {
module_load_include('inc', 'fedora_repository', 'api/fedora_utils');
$query = "select \$object \$title from <#ri>
where (\$object <info:fedora/fedora-system:def/relations-external#isMemberOf> <info:fedora/$collection_pid>
or \$object <info:fedora/fedora-system:def/relations-external#isMemberOfCollection> <info:fedora/$collection_pid>)
and \$object <dc:title> \$title";
$query = htmlentities(urlencode($query));
$content = '';
$url = variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch');
$url .= "?type=tuples&flush=TRUE&format=csv&limit=$limit&offset=$offset&lang=itql&stream=on&query=" . $query;
$content .= do_curl($url);
$results = explode("\n", $content);
$lines = preg_replace('/info:fedora\/|"object","title"/', '', $results);
$lines = array_values(array_filter($lines));
module_load_include('inc', 'islandora', 'RestConnection');
require_once 'sites/all/libraries/tuque/RepositoryQuery.php';
$restConnection = new RestConnection();
$query = 'select $object $title from <#ri>
where ($object <info:fedora/fedora-system:def/relations-external#isMemberOf> <info:fedora/' . $collection_pid . '>
or $object <info:fedora/fedora-system:def/relations-external#isMemberOfCollection> <info:fedora/' . $collection_pid . '>)
and $object <dc:title> $title';
$results = $restConnection->repository->ri->itqlQuery($query, 'unlimited', '0');
$keys = array();
$object = array();
foreach ($lines as $line) {
$line_parts = explode(',', $line);
$objects = array();
foreach ($results as $result) {
$objects[$result['object']['value']] = $result['title']['value'];
$keys[] = $result['object']['value'];
}
$objects[$line_parts[0]] = $line_parts[1];
$keys[] = $line_parts[0];
foreach ($objects as $key => $object) {
$rows[$key] = array(
'#pid' => $key,
'pid' => array('#value' => l($key, 'islandora/object/' . $key)),
'title' => array(
'data' => array(
'#type' => 'link',
'#title' => $object,
'#href' => 'islandora/object/' . $key,
),
),
);
}
$form['list'] = array(
'#value' => $list,
$header = array(
'title' => array('data' => t('Title')),
);
$table = array(
'#header' => array(theme('table_select_header_cell'), t('Select All'), ''),
'#theme' => 'islandora_collection_management_form_table',
'#tree' => TRUE,
'rows' => array(),
'selections' => array(
'#type' => 'checkboxes',
'#options' => array_fill_keys($keys, ''),
),
);
$rows = &$table['rows'];
if(empty($objects)){
return;
}
foreach ($objects as $key => $object) {
$rows[] = array(
'#pid' => $key,
'pid' => array('#value' => l($key, 'fedora/repository/' . $key)),
'title' => array('#value' => $object),
'#type' => 'tableselect',
'#header' => $header,
'#options' => $rows,
);
}
return $table;
}
/**
* themes the form table.
*
* @param array $element Drupal Form Element.
* @return string
*/
function theme_islandora_collection_management_form_table(array $element) {
function theme_islandora_basic_collection_management_form_table(array $element) {
$rows = array();
foreach (element_children($element['rows']) as $child) {
$setting = $element['rows'][$child];
@ -92,3 +75,34 @@ function theme_islandora_collection_management_form_table(array $element) {
$attributes = isset($element['#id']) ? array('id' => $element['#id']) : NULL;
return theme_table($element['#header'], $rows, $attributes);
}
function get_collections_as_option_array() {
module_load_include('inc', 'islandora', 'RestConnection');
require_once 'sites/all/libraries/tuque/RepositoryQuery.php';
$restricted = variable_get('fedora_namespace_restriction_enforced', TRUE);
$allowed_string = variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora:');
$namespaces = explode(':', $allowed_string);
$restConnection = new RestConnection();
$query = 'select $object $title from <#ri>
where ($object <fedora-model:label> $title
and $object <info:fedora/fedora-system:def/model#hasModel> <info:fedora/islandora:collectionCModel>
and $object <fedora-model:state> <info:fedora/fedora-system:def/model#Active>)
order by $title';
$results = $restConnection->repository->ri->itqlQuery($query, 'unlimited', '0');
foreach ($namespaces as $namespace) {
$trimmed_names[] = trim($namespace);
}
$options = array();
foreach ($results as $item) { //removes blanks
// var_dump($item['object']['value']);
$namespace = explode(':', $item['object']['value']);
$namespace = trim($namespace[0]);
if (!$restricted || in_array($namespace, $trimmed_names)) {
$options[$item['object']['value']] = $item['title']['value'];
}
}
unset($options['islandora:ContentModelCollection']);
return $options;
}

38
islandora_basic_collection/includes/DeleteCollection.inc

@ -7,22 +7,14 @@
*
* @return string
*/
function islandora_collection_deletion_form(&$form_state, $pid) {
module_load_include('inc', 'fedora_repository', 'api/fedora_utils');
module_load_include('inc', 'islandora_collection_manager', 'CollectionManagerTable');
function islandora_collection_deletion_form($form, &$form_state, $pid) {
module_load_include('inc', 'islandora_basic_collection', 'CollectionManagerTable');
$potential_collections = get_collections_as_option_array();
$table = islandora_collection_table($pid);
$deletion_message = ($table) ? "Delete Members of this Collection" : "Delete Collection";
$submit_text_message = ($table) ? "Delete Selected Objects" : "Delete Collection";
$form = array();
$form['collection_delete'] = array(
'#title' => $deletion_message,
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
if ($table) {
$form['collection_delete']['table'] = array(
@ -48,25 +40,30 @@ function islandora_collection_deletion_form(&$form_state, $pid) {
$form['collection_delete']['submit'] = array(
'#type' => 'submit',
'#description' => t("This action is permanant and cannot be undone."),
'#value' => t($submit_text_message),
'#value' => t('@message', array('@message' => $submit_text_message)),
);
if (user_access('delete entire collections')) {
return $form;
}
}
function islandora_collection_deletion_form_submit($form, &$form_state) {
global $user;
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
module_load_include('inc', 'fedora_repository', 'api/fedora_collection');
$collection_pid = $form_state['values']['current'];
$parents = Islandora_collections_get_collection_from_pid($collection_pid);
// module_load_include('inc', 'fedora_repository', 'api/fedora_item');
// module_load_include('inc', 'fedora_repository', 'api/fedora_collection');
module_load_include('inc', 'islandora', 'RestConnection');
$restConnection = new RestConnection();
$collection_pid = $form_state['values']['current'];
$fedora_object = new FedoraObject($collection_pid, $restConnection->repository);
$parents = $fedora_object->relationships->get(NULL, 'isMemberOfCollection');
var_dump($parents);
// exit;
// $parents = Islandora_collections_get_collection_from_pid($collection_pid);
// $collection_pid = $form_state['values']['current'];
if ($form_state['values']['delete_root'] == 1) {
delete_root_collection($collection_pid);
drupal_goto("fedora/repository/" .$parents[0]);
drupal_goto("islandora/" . $parents[0]);
}
$child_collections = get_child_collections($collection_pid);
@ -94,10 +91,9 @@ function islandora_collection_deletion_form_submit($form, &$form_state) {
$pids_to_delete = array_diff($pids, $populated_child_collections);
foreach ($pids_to_delete as $pid_to_delete) {
$item = new Fedora_Item($pid_to_delete);
$item->purge("Purged by " . $user->name);
$restConnection->repository->purgeObject($pid_to_delete);
}
drupal_goto("fedora/repository/" .$parents[0]);
drupal_goto("islandora/" . $parents[0]);
}
function delete_root_collection($pid) {

28
islandora_basic_collection/includes/MoveCollection.inc

@ -7,21 +7,15 @@
*
* @return string
*/
function islandora_collection_migrate_form(&$form_state, $pid) {
module_load_include('inc', 'fedora_repository', 'api/fedora_utils');
module_load_include('inc', 'islandora_collection_manager', 'CollectionManagerTable');
function islandora_collection_migrate_form($form, &$form_state, $pid) {
module_load_include('inc', 'islandora_basic_collection', 'CollectionManagerTable');
$potential_collections = get_collections_as_option_array();
$table = islandora_collection_table($pid);
if (!$table) {
return;
}
$form = array();
$form['migrate'] = array(
'#title' => "Migrate Members",
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['migrate']['new_collection'] = array(
'#title' => t('New Collection'),
'#description' => t("All content will be migrated from $pid to the selected collection"),
@ -29,9 +23,7 @@ function islandora_collection_migrate_form(&$form_state, $pid) {
'#options' => $potential_collections,
);
$form['migrate']['table'] = array(
'table' => $table,
);
$form['migrate']['table'] = $table;
$form['current'] = array(
'#type' => 'hidden',
@ -50,13 +42,15 @@ function islandora_collection_migrate_form(&$form_state, $pid) {
}
function islandora_collection_migrate_form_submit($form, &$form_state) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$pids = array_filter($form_state['values']['table']['selections']);
module_load_include('inc', 'islandora', 'RestConnection');
$restConnection = new RestConnection();
$pids = array_filter($form_state['values']['table']);
$new_collection = $form_state['values']['new_collection'];
$current = $form_state['values']['current'];
foreach ($pids as $pid) {
$item = new Fedora_Item($pid);
$item->add_relationship('isMemberOfCollection', $new_collection, RELS_EXT_URI);
$item->purge_relationship('isMemberOfCollection', $current);
$fedora_object = new FedoraObject($pid, $restConnection->repository);
$fedora_object->relationships->remove(NULL, 'isMemberOfCollection', NULL);
$fedora_object->relationships->add(FEDORA_RELS_EXT_URI, 'isMemberOfCollection', $new_collection);
}
}

68
islandora_basic_collection/islandora_basic_collection.module

@ -71,82 +71,62 @@ function islandora_basic_collection_manage_object($object_id) {
module_load_include('inc', 'islandora_basic_collection', 'includes/CollectionManagerTable');
module_load_include('inc', 'islandora_basic_collection', 'includes/DeleteCollection');
module_load_include('inc', 'islandora_basic_collection', 'includes/MoveCollection');
drupal_add_library('system', 'drupal.vertical-tabs');
drupal_load_stylesheet('misc/vertical-tabs-rtl.css');
$form['additional_settings'] = array(
'#type' => 'vertical_tabs',
'#weight' => 99,
);
$form = array();
$form['collection_manager'] = array(
'#type' => 'fieldset',
);
$form['create_child_collection'] = array(
$form['collection_manager']['create_child_collection'] = array(
'#type' => 'fieldset',
'#title' => t('Create Child Collection'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#group' => 'additional_settings',
'#tree' => TRUE,
'#weight' => -2,
'#collapsed' => TRUE,
);
$form['create_child_collection']['form'] = array(
// '#content' => drupal_get_form('collection_management_form', $object_id),
$form['collection_manager']['create_child_collection']['form'] = array(
// '#markup' => drupal_get_form('collection_management_form', $object_id),
);
$form['manage_policies'] = array(
$form['collection_manager']['manage_policies'] = array(
'#type' => 'fieldset',
'#title' => t('Manage Collection Policies'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#group' => 'additional_settings',
'#tree' => TRUE,
'#weight' => -3,
'#collapsed' => TRUE,
);
$form['manage_policies']['form'] = array(
$form['collection_manager']['manage_policies']['form'] = array(
// '#content' => drupal_get_form($form_id),
);
$form['change_content_models'] = array(
$form['collection_manager']['change_content_models'] = array(
'#type' => 'fieldset',
'#title' => t('Change Content Models'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#group' => 'additional_settings',
'#tree' => TRUE,
'#weight' => -3,
'#collapsed' => TRUE,
);
$form['change_content_models']['form'] = array(
$form['collection_manager']['change_content_models']['form'] = array(
// '#content' => drupal_get_form($form_id),
);
$form['migrate_members'] = array(
$form['collection_manager']['migrate_members'] = array(
'#type' => 'fieldset',
'#title' => t('Migrate Members'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#group' => 'additional_settings',
'#tree' => TRUE,
'#weight' => -3,
'#collapsed' => TRUE,
);
$form['migrate_members']['form'] = array(
'#content' => drupal_get_form('islandora_collection_migrate_form', $object_id),
);
$form['collection_manager']['migrate_members']['form'] = drupal_get_form('islandora_collection_migrate_form', $object_id);
$form['delete_members'] = array(
$form['collection_manager']['delete_members'] = array(
'#type' => 'fieldset',
'#title' => t('Delete Members of this Collection'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#group' => 'additional_settings',
'#tree' => TRUE,
'#weight' => -3,
'#collapsed' => TRUE,
);
$form['delete_members']['form'] = array(
'#content' => drupal_get_form('islandora_collection_deletion_form', $object_id),
);
$form['collection_manager']['delete_members']['form'] = drupal_get_form('islandora_collection_deletion_form', $object_id);
return $form;
@ -196,7 +176,11 @@ function islandora_basic_collection_theme($existing, $type, $theme, $path) {
// and templates will be able to have have a pid appended to the template name to overide a template on a per object basis
//an example template would be named islandora-basic-image--islandora-27.tpl.phps
'variables' => array('islandora_object' => NULL),
)
),
'islandora_basic_collection_management_form_table' => array(
'arguments' => array('element' => NULL),
'file' => 'includes/CollectionManagerTable.inc',
),
);
}

Loading…
Cancel
Save