Last active
July 14, 2016 07:22
-
-
Save mjordan/6274428fe7d90397ec51f3af939a8e11 to your computer and use it in GitHub Desktop.
Writing out derivatives for use in another Islandora
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This simple module: | |
<?php | |
/** | |
* Implements hook_islandora_object_ingested(). | |
*/ | |
function islandora_derivative_factory_islandora_object_ingested(AbstractObject $object) { | |
$base_output_dir = '/tmp/derivativefactoryoutput'; | |
foreach ($object as $ds) { | |
if ($ds->id != 'RELS-EXT') { | |
$mime_detect = new MimeDetect(); | |
$extension = $mime_detect->getExtension($ds->mimetype); | |
$filename = $ds->id . '.' . $extension; | |
$object_dir_name = preg_replace('/:/', '_', $object->id); | |
$output_dir = $base_output_dir . '/' . $object_dir_name; | |
if (!file_exists($output_dir)) { | |
mkdir($output_dir, 0700); | |
} | |
$ds_output_path = $output_dir . '/' . $object_dir . '/' . $filename; | |
$ds->getContent($ds_output_path); | |
} | |
} | |
} | |
/** | |
* Implements hook_islandora_datastream_ingested(). | |
*/ | |
function islandora_derivative_factory_islandora_datastream_ingested(AbstractObject $object, AbstractDatastream $datastream) { | |
if ($datastream->id == 'RELS-EXT') { | |
return; | |
} | |
$base_output_dir = '/tmp/derivativefactoryoutput'; | |
$mime_detect = new MimeDetect(); | |
$extension = $mime_detect->getExtension($datastream->mimetype); | |
$filename = $datastream->id . '.' . $extension; | |
$object_dir_name = preg_replace('/:/', '_', $object->id); | |
$output_dir = $base_output_dir . '/' . $object_dir_name; | |
if (!file_exists($output_dir)) { | |
mkdir($output_dir, 0700); | |
} | |
$ds_output_path = $output_dir . '/' . $object_dir . '/' . $filename; | |
$datastream->getContent($ds_output_path); | |
} | |
// End of module | |
will write out the following files if you batch ingest three simple image objects: | |
/tmp/derivativefactoryoutput | |
├── testing_55 | |
│ ├── DC.xml | |
│ ├── MEDIUM_SIZE.jpg | |
│ ├── MODS.xml | |
│ ├── OBJ.jpg | |
│ ├── TECHMD.xml | |
│ └── TN.jpg | |
├── testing_56 | |
│ ├── DC.xml | |
│ ├── MEDIUM_SIZE.jpg | |
│ ├── MODS.xml | |
│ ├── OBJ.jpg | |
│ ├── TECHMD.xml | |
│ └── TN.jpg | |
└── testing_57 | |
├── DC.xml | |
├── MEDIUM_SIZE.jpg | |
├── MODS.xml | |
├── OBJ.jpg | |
├── TECHMD.xml | |
└── TN.jpg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment