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 paged datastream plugin #64

Open
wants to merge 5 commits into
base: 7.x
Choose a base branch
from
Open
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
72 changes: 72 additions & 0 deletions plugins/plugin_object_ds_paged.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

/**
* @file
* Plugin for the Islandora BagIt Drupal module.
*
* Registers all the datastreams in pages of an Islandora object so they are
* copied into the 'data' directory.
*/

/**
* Returns an array of source and destination file paths.
*
* @param object $islandora_object
* The Islandora object to create a Bag for.
*
* @param string $tmp_ds_directory
* The temporary directory where the datastream files have been downloaded.
*
* @return array|bool
* An array of source and destination file paths, or FALSE
* if no datastream files are present.
*/
function islandora_bagit_plugin_object_ds_paged_init($islandora_object, $tmp_ds_directory) {
// What Content Models have pages?
$supported_cmodels = array(
'islandora:manuscriptCModel',
'islandora:bookCModel',
'islandora:newspaperIssueCModel',
);
$found_cmodels = array_intersect($islandora_object->models, $supported_cmodels);
if (empty($found_cmodels)) {
return FALSE;
}
if (module_load_include('inc', 'islandora_paged_content', 'includes/utilities') === FALSE) {
return FALSE;
}
$files_to_add = array();
$pages = islandora_paged_content_get_pages($islandora_object);
$page_count = 0;
foreach ($pages as $page) {
$page_object = islandora_object_load($page['pid']);
$page_count++;
$tmp_ds_subdir = $tmp_ds_directory . DIRECTORY_SEPARATOR . 'p' . $page_count;
if (!file_exists($tmp_ds_subdir)) {
mkdir($tmp_ds_subdir, 0777, TRUE);
}
$ds_files = islandora_bagit_retrieve_datastreams($page_object, $tmp_ds_subdir);

// Add file source and dest paths for each datastream to the $files_to_add
// array. $files_to_add['dest'] must be relative to the Bag's data
// subdirectory.
foreach ($ds_files as $ds_filename) {
// Add each file in the directory to $files_to_add.
$source_file_to_add = $ds_filename;
if (file_exists($source_file_to_add) && is_file($source_file_to_add)) {
$files_to_add[] = array(
'source' => $source_file_to_add,
// Each page becomes a subdirectory in the Bag's 'data' directory.
'dest' => str_replace(array(':', '-'), '_', $page['pid']) . DIRECTORY_SEPARATOR . basename($ds_filename),
);
}
}
}

if (count($files_to_add)) {
return $files_to_add;
}
else {
return FALSE;
}
}