From 7e6aaecedb9b0e54445f321658085267fc396d29 Mon Sep 17 00:00:00 2001 From: mroy Date: Tue, 7 Dec 2010 13:16:28 -0600 Subject: [PATCH] Added a workflow client plugin for running exiftool. --- workflow_client/plugins/exif.inc | 72 ++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 workflow_client/plugins/exif.inc diff --git a/workflow_client/plugins/exif.inc b/workflow_client/plugins/exif.inc new file mode 100644 index 00000000..5a1ba414 --- /dev/null +++ b/workflow_client/plugins/exif.inc @@ -0,0 +1,72 @@ + 0) { + $this->setMessage(t('Missing parameter(s) "%params" for exif process on "%pid"', array('%params' => join(',', $missing_params), '%pid' => $pid))); + return FALSE; + } + + module_load_include('inc', 'fedora_repository', 'api/fedora_item'); + module_load_include('inc', 'fedora_repository', 'ObjectHelper'); + + $item = new fedora_item($pid); + $dslist = $item->get_datastreams_list_as_array(); + if (!isset($dslist[$parameters['dsid']])) { + $this->setMessage(t('Datastream "%dsid" could not be found for exif process on "%pid"', array('%dsid' => $parameters['dsid'], '%pid' => $pid))); + return FALSE; + } + + $ds = $dslist[$parameters['dsid']]; + $file = '/tmp/'. $ds['label']; + $dest_ds = isset($parameters['dest_ds']) ? $parameters['dest_ds'] : 'EXIF'; + + $objectHelper = new ObjectHelper(); + $objectHelper->makeObject($pid, $parameters['dsid'], FALSE, NULL, $file); + + if (!file_exists($file)) { + $this->setMessage('couldnt get datastream '. $parameters['dsid'] .' as '. $file); + return FALSE; + } + + $system = getenv('System'); + $returnValue=TRUE; + $output=array(); + + $command = '/usr/local/exif/exiftool -X '. $file; + exec($command, $output, $returnValue); + + if (!file_exists($file . $file_suffix)) { + $this->setMessage('command failed: '. htmlentities($command ."\n" . join("\n", $output) ."\n return value: $returnValue")); + @unlink($file); + return FALSE; + } + + if ($returnValue == '0') { + if (isset($dslist[$dest_ds])) { + $item->purge_datastream($dest_ds); + } + + $ret = $item->add_datastream_from_string(join("\n",$output), $dest_ds, $ds['label'] . $file_suffix, 'text/xml', 'X','Added by workflow process EXIF.'); + @unlink($file); + @unlink($file . $file_suffix); + + if (!$ret) { + $this->setMessage(t('Unable to add datastream "%dsid" to "%pid".', array('%dsid' => $dest_ds, '%pid' => $pid))); + return FALSE; + } + + return TRUE; + + } + } +}