Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add option to resume incomplete exports #68

Open
wants to merge 1 commit into
base: 7.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ Bags can be created for individual Islandora objects or for all objects in a giv

where UID is the user ID or user name of the fedoraAdmin user (or equivalent), 'object' or 'collection' indicates whether you want to create a Bag for a single object or a Bag for every member of a collection, and PID is the PID of the Islandora object or collection.

By default, the `create-islandora-bag` command will overwrite existing bags with the same name. An option `--resume` is available which will instead accept the existing bags as-is, and resume processing with the next incomplete bag.

### Permissions and security

This module is intended for users who have a fairly high level of permissions on a Drupal site. Because the goal is to package up all or some of the datastreams in an Islandora object, users who can create and download Bags should have access to those datastreams. However, the module does check the current users' access to a datastream before adding it to the Bag.
Expand Down
8 changes: 7 additions & 1 deletion islandora_bagit.drush.inc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ function islandora_bagit_drush_command() {
'Standard example (for collection)' => 'drush --user=fedoraAdmin create-islandora-bag collection islandora:sp_basic_image_collection',
'Alias example' => 'drush --user=fedoraAdmin cib object islandora:190',
),
'options' => array(
'resume' => array(
'description' => 'Resume a prior incomplete operation, retaining completed content.',
),
),
'aliases' => array('cib'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_LOGIN,
);
Expand Down Expand Up @@ -89,7 +94,8 @@ function drush_islandora_bagit_create_islandora_bag($type = 'object', $pid = NUL
foreach ($objects_to_bag as $object_to_bag_pid) {
try {
$islandora_object = islandora_object_load($object_to_bag_pid);
islandora_bagit_create_bag($islandora_object);
$resume = (bool) drush_get_option('resume');
islandora_bagit_create_bag($islandora_object, $resume);
}
catch (Exception $e) {
drush_print("Sorry, Islandora cannot create the Bag: " . $e->getMessage());
Expand Down
20 changes: 15 additions & 5 deletions islandora_bagit.module
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,14 @@ function islandora_bagit_admin_settings() {
*
* @param object $islandora_object
* The Islandora object to create a Bag for.
* @param boolean $resume
* Whether to resume a prior failed process, skipping the delete for already serialized bags
*
* @return string|array
* Either an empty array, a blank string, or a string containing
* a link to 'Download the Bag.'
*/
function islandora_bagit_create_bag($islandora_object) {
function islandora_bagit_create_bag($islandora_object, $resume = false) {
// First, check to see if the object is a collection, and if it is,
// reroute to the relevant batch function.
foreach ($islandora_object as $ds) {
Expand Down Expand Up @@ -352,6 +354,18 @@ function islandora_bagit_create_bag($islandora_object) {
$bag_output_path = variable_get('islandora_bagit_bag_output_dir', '/tmp') .
DIRECTORY_SEPARATOR . $bag_file_name;

$serialized_bag_path = variable_get('islandora_bagit_bag_output_dir', '/tmp') .
DIRECTORY_SEPARATOR . $bag_file_name;
$compression_type = variable_get('islandora_bagit_compression_type', 'tgz');
if ($resume && file_exists($serialized_bag_path . '.' . $compression_type)) {
if (variable_get('islandora_bagit_show_messages', 1)) {
drupal_set_message(t("Skipping existing Bag at %path", array(
'%path' => $serialized_bag_path,
)));
}
return array();
}

// Because the BagItPHP library does some things by default if the bag output
// directory already exists (like read the fetch.txt file), we always need to
// delete the directory if it exists.
Expand Down Expand Up @@ -410,10 +424,6 @@ function islandora_bagit_create_bag($islandora_object) {
drupal_alter('islandora_bagit', $bag, $islandora_object);

// Write out the serialized (i.e., compressed) Bag.
$serialized_bag_path = variable_get('islandora_bagit_bag_output_dir', '/tmp') .
DIRECTORY_SEPARATOR . $bag_file_name;
$compression_type = variable_get('islandora_bagit_compression_type', 'tgz');

if (file_exists($serialized_bag_path . '.' . $compression_type)) {
unlink($serialized_bag_path . '.' . $compression_type);
}
Expand Down