Commit 2cac9b95 authored by Mark Jordan's avatar Mark Jordan
Browse files

Cleanup; added three submodules.

parent af399982
......@@ -59,7 +59,9 @@ function islandora_bagit_light_create_bag($pid) {
// Create a new bag.
$bag = new BagIt($bag_output_path, TRUE, TRUE, FALSE, $bag_info);
if ($files_to_add = islandora_bagit_light_ds_basic($islandora_object, $tmp_ds_directory)) {
$files_to_add = module_invoke_all('islandora_bagit_get_files', $islandora_object, $tmp_ds_directory);
if (count($files_to_add)) {
// Generate octetstream sum.
if (variable_get('islandora_bagit_payload_octetstream_sum', 0)) {
$sum = islandora_bagit_light_get_octetstream_sum($files_to_add);
......@@ -74,7 +76,7 @@ function islandora_bagit_light_create_bag($pid) {
}
else {
drupal_set_message(t('There are no files to add to the Bag.'), 'warning');
watchdog('bagit', 'BagIt Bag not created for !object: plugins found no files.',
watchdog('bagit', 'BagIt Bag not created for !object: no files found.',
array('!object' => $islandora_object->id));
return '';
}
......@@ -142,44 +144,26 @@ function islandora_bagit_light_create_bag($pid) {
}
/**
* Returns an array of source and destination file paths.
*
* @param object $islandora_object
* The Islandora object to create a Bag for.
* Gets a file extension based on a Mimetype.
*
* @param string $tmp_ds_directory
* The temporary directory where the datastream files have been downloaded.
* @param string $dsid
* The DSID of the datastream.
* @param string $mimetype
* The MimeType of the datastream.
*
* @return array|bool
* An array of source and destination file paths, or FALSE
* if no datastream files are present.
* @return string
* The extension to assign to the datastream's file, without the period.
*/
function islandora_bagit_light_ds_basic($islandora_object, $tmp_ds_directory) {
$files_to_add = array();
$ds_files = islandora_bagit_light_retrieve_datastreams($islandora_object, $tmp_ds_directory);
// 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,
// We use basename here since there are no subdirectories in the Bag's
// 'data' directory.
'dest' => basename($ds_filename),
);
}
}
if (count($files_to_add)) {
return $files_to_add;
function islandora_bagit_light_get_extension($dsid, $mimetype) {
if ($dsid == 'DC') {
// To prevent getting .bin.
$extension = 'xml';
}
else {
return FALSE;
$mime_detect = new MimeDetect();
$extension = $mime_detect->getExtension($mimetype);
}
return $extension;
}
/**
......@@ -200,12 +184,11 @@ function islandora_bagit_light_ds_basic($islandora_object, $tmp_ds_directory) {
*/
function islandora_bagit_light_retrieve_datastreams($islandora_object, $tmp_ds_directory, $datastreams = array()) {
$ds_files = array();
$mime_detect = new MimeDetect();
foreach ($islandora_object as $ds) {
if (islandora_datastream_access(ISLANDORA_VIEW_OBJECTS, $islandora_object[$ds->id])) {
// If $datastreams is empty, retrieve all datastreams.
if ((count($datastreams) == 0) || in_array($ds->id, $datastreams)) {
$extension = $mime_detect->getExtension($ds->mimetype);
$extension = islandora_bagit_light_get_extension($ds->id, $ds->mimetype);
$ds_content_file_path = $tmp_ds_directory . DIRECTORY_SEPARATOR . $ds->id . '.' .
$extension;
// Only get the datastream if its file doesn't already exist.
......@@ -224,7 +207,7 @@ function islandora_bagit_light_retrieve_datastreams($islandora_object, $tmp_ds_d
}
else {
// If the file already exists, add its path to the return array so it
// will be registered with the plugin.
// will be registered.
if (strlen($ds_content_file_path)) {
if (!in_array($ds_content_file_path, $ds_files)) {
$ds_files[] = $ds_content_file_path;
......
<?php
/**
* @file
* Documents the hooks this module defines.
*/
/**
* 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 or other files have been downloaded.
*
* @return array
* An array of source and destination file paths, which should be
* if no files are availale or present. The destination file path
* should be relative to the Bag's /data directory.
*/
function hook_islandora_bagit_get_files($islandora_object, $tmp_ds_directory) {
$files_to_add = array();
$my_file_path = $tmp_ds_directory . DIRECTORY_SEPARATOR . 'myfile.txt';
file_put_contents($my_file_path, "Hi, I'm the content of a file to add.");
$files_to_add[] = array(
'source' => $my_file_path,
'dest' => 'myfile.txt',
);
return $files_to_add;
}
name = Islandora BagIt Light
description = Creats BagIt Bags from Islandora objects.
description = Creates BagIt Bags from Islandora objects.
version = 7.x-dev
core = 7.x
package = Islandora Tools
......
name = Islandora BagIt All Datastreams
description = Writes out all datastream files for an object in preparation for creating a Bag.
version = 7.x-dev
core = 7.x
package = Islandora Tools
dependencies[] = libraries
dependencies[] = islandora
dependencies[] = islandora_bagit_light
<?php
/**
* @file
*/
/**
* Implements islandora_bagit_get_files().
*
* Writes out a file for each datastream, and returns an array of
* their paths.
*/
function islandora_bagit_all_ds_islandora_bagit_get_files($islandora_object, $tmp_ds_directory) {
$files_to_add = array();
module_load_include('inc', 'islandora_bagit_light', 'includes/utilities');
$ds_files = islandora_bagit_light_retrieve_datastreams($islandora_object, $tmp_ds_directory);
// 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,
// We use basename here since there are no subdirectories in the Bag's
// /data directory.
'dest' => basename($ds_filename),
);
}
}
return $files_to_add;
}
name = Islandora BagIt FOXML
description = Writes out the FOXML for an object in preparation for creating a Bag.
version = 7.x-dev
core = 7.x
package = Islandora Tools
dependencies[] = libraries
dependencies[] = islandora
dependencies[] = islandora_bagit_light
<?php
/**
* @file
*/
/**
* Implements islandora_bagit_get_files().
*
* Writes out the FOXML for the object, and returns its path.
*/
function islandora_bagit_foxml_islandora_bagit_get_files($islandora_object, $tmp_ds_directory) {
// We don't call islandora_bagit_light_retrieve_datastreams() here because this
// plugin doesn't add any datastreams.
$files_to_add = array();
// Use the Tuque API-M to export the FOXML for the object.
global $user;
$fedora_url = variable_get('islandora_base_url', 'http://localhost:8080/fedora');
$connection = islandora_get_tuque_connection($user, $fedora_url);
// Export the FOXML. Documentation on the 'context' parameter is available at
// https://wiki.duraspace.org/display/FEDORA37/REST+API#RESTAPI-export.
// Note: Using the 'archive' context with Fedora up to and including version
// 3.8.0 is not recommended due to
// https://jira.duraspace.org/browse/FCREPO-1384.
$foxml = $connection->api->m->export($islandora_object->id,
array(
'format' => 'info:fedora/fedora-system:FOXML-1.1',
'context' => 'migrate',
'encoding' => 'UTF-8',
)
);
$foxml_path = $tmp_ds_directory . DIRECTORY_SEPARATOR . 'foxml.xml';
file_put_contents($foxml_path, $foxml);
$files_to_add[] = array(
'source' => $foxml_path,
'dest' => 'foxml.xml',
);
return $files_to_add;
}
name = Islandora BagIt PREMIS
description = Writes out the PREMIS XML file for an object in preparation for creating a Bag.
version = 7.x-dev
core = 7.x
package = Islandora Tools
dependencies[] = libraries
dependencies[] = islandora
dependencies[] = islandora_premis
dependencies[] = islandora_bagit_light
<?php
/**
* @file
*/
/**
* Implements islandora_bagit_get_files().
*
* Writes out the PREMIS file for the object and returns its path.
*/
function islandora_bagit_premis_islandora_bagit_get_files($islandora_object, $tmp_ds_directory) {
$files_to_add = array();
if (module_exists('islandora_premis')) {
module_load_include('inc', 'islandora_premis', 'includes/utilities');
$premis_xml = islandora_premis_transform_foxml_to_premis($islandora_object);
}
else {
return array();
}
$premis_file_path = $tmp_ds_directory . DIRECTORY_SEPARATOR . 'premis.xml';
file_put_contents($premis_file_path, $premis_xml);
$files_to_add[] = array(
'source' => $premis_file_path,
'dest' => 'PREMIS.xml',
);
return $files_to_add;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment