Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
My dg7.module implementation of hook_islandora_multi_importer_remote_file_get to retrive content from a mounted file system when "local*" option is selected.
* Implements hook_islandora_multi_importer_remote_file_get for and
* @param $url
* Path to the file to be fetched. Default behavior strips the 'basename' from $url and looks
* for that file somewhere in $target.
* @return array
* On error or failure an empty array is returned.
* On success, a single array element LOCAL path like /mnt/storage/exmample.xml
* Important! This function requires that your target directory of files be mounted to
* the HOST server, or your Apache container in the case of ISLE, as $target (see below).
* The mount statement should look something like this:
* sudo mount -t cifs -o username=mcfatem // /mnt/storage
* And in an ISLE environment, you need an additonal Volume/bind-mount statement in your
* docker-compose.yml, or a suitable override, like so:
* apache:
* volumes:
* - /host/path/to/object/files:/mnt/storage
* See for more detail.
function dg7_islandora_multi_importer_remote_file_get($url) {
if ($url === '') { return array(); } // return an empty array if $url is blank
$parsed_url = parse_url($url);
// Assumes the file is somewhere in the /mnt/storage path
$target = "/mnt/storage";
$basename = drupal_basename($parsed_url['path']);
$pattern = "/" . preg_quote($basename) . "/";
$options['key'] = 'filename';
$file = file_scan_directory($target, $pattern, $options);
$msg = "IMI hook " . __FUNCTION__ . " was invoked ";
// Nothing and return an empty array.
if (empty($file)) {
$msg .= "and was unable to find a file matching '$basename' in '$target' for ingest. ";
$msg .= "Make sure that you have mounted your files as '$target', and that they can be read by 'www-data'! ";
$msg .= "See for additional details.";
drupal_set_message($msg, 'warning');
watchdog('Islandora Multi Importer', $msg);
return array();
// File found! Report and send back the URI in an array.
else {
$uri = $file[$basename]->uri;
$msg .= "and found file '$uri' in '$target' for ingest.";
drupal_set_message($msg, 'status');
return array($uri);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment