Commit 1a780a73 authored by Mark Jordan's avatar Mark Jordan
Browse files

Initial commit.

parents
This diff is collapsed.
# Islandora Log Ingest
## Overview
This utility module logs identifier information on objects as they are ingested into an Islandora repository. It writes a tab-(or other delimiter)-separated log file that contains the following:
```
[prefix] identifiers PID
```
* Prefix is an optional string that is configured using the module's admin settings form. This string can be used to identify a batch load, for example.
* Identifiers is a sting containing all of the values of the dc:identifier elemements in an object's DC datastream. If the DC datastream contains more than one dc:identifier element, the values from all dc:identifier elements are concatenated using a delimiter defined in the admin settings.
* PID is the PID of the object being ingested.
Its purpose it to provide a simple way of relating PIDs to identifiers defined in incoming objects' metadata datastreams.
## Usage
Install and enable the module. To add your own log entry prefix or to change the default log file location from [Drupal install directory]/sites/default/files/islandora_log_ingest.txt, visit admin/islandora/tools/log_ingest.
## Maintainer
* [Mark Jordan](https://github.com/mjordan)
## Feature requests
This module was written as part of a large migration to Islandora from another repository platform. It wasn't intended to be extensible or terribly flexible. So feel free to fork the Github repo and modify it to suit your needs. That said, if enough people +1 a featue identified in the issue queue or on the Islandora email lists, we can look at how we can develop the module further.
name = "Islandora Log Ingest"
description = "Logs ingesting of objects."
package = Islandora Tools
dependencies[] = islandora
core = 7.x
configure = admin/islandora/tools/log_ingest
<?php
/**
* @file
* Defines all the hooks this module implements, and some other functions.
*/
/**
* Implements hook_menu().
*/
function islandora_log_ingest_menu() {
$items = array();
$items['admin/islandora/tools/log_ingest'] = array(
'title' => 'Islandora Log Ingest',
'description' => 'Configure Islandora Log Ingest.',
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_log_ingest_admin_settings'),
'access arguments' => array('administer site configuration'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
/**
* Admin settings form builder.
*/
function islandora_log_ingest_admin_settings() {
$default_log_path = drupal_realpath(file_default_scheme() . '://');
$default_log_path .= '/islandora_log_ingest.txt';
$form['islandora_log_ingest_log_file_path'] = array(
'#title' => t('Log file path'),
'#type' => 'textfield',
'#size' => 60,
'#default_value' => variable_get('islandora_log_ingest_log_file_path', $default_log_path),
'#description' => t("Absolute file system path to where the log file."),
'#maxlength' => 255,
);
$form['islandora_log_ingest_entry_prefix'] = array(
'#title' => t('Log entry prefix'),
'#type' => 'textfield',
'#size' => 60,
'#default_value' => variable_get('islandora_log_ingest_entry_prefix', ''),
'#description' => t("String that is placed in the first position of the
each log entry, to identify a batch load, for example."),
'#maxlength' => 255,
);
$form['islandora_log_ingest_entry_delimiter'] = array(
'#title' => t('Log entry delimiter'),
'#type' => 'textfield',
'#size' => 5,
'#default_value' => variable_get('islandora_log_ingest_entry_delimiter', ''),
'#description' => t("String used to separate parts of the log entry. Leave
blank to use \\t (tab)."),
'#maxlength' => 255,
);
$form['islandora_log_ingest_id_delimiter'] = array(
'#title' => t('Repeated dc:identifier delimiter'),
'#type' => 'textfield',
'#size' => 5,
'#default_value' => variable_get('islandora_log_ingest_id_delimiter', ';'),
'#description' => t("String used to separate repeated dc:identifier values."),
'#maxlength' => 255,
);
return system_settings_form($form);
}
/**
* Implements hook_islandora_object_ingested().
*/
function islandora_log_ingest_islandora_object_ingested(FedoraObject $islandora_object) {
$identifiers = islandora_log_ingest_get_identifer($islandora_object['DC'], $islandora_object->id);
$prefix = variable_get('islandora_log_ingest_entry_prefix', '');
$log_path = variable_get('islandora_log_ingest_log_file_path', '/tmp/islanodra_log_ingest.txt');
$enty = array();
$delimiter = variable_get('islandora_log_ingest_entry_delimiter', '');
if (strlen($prefix)) {
$entry[] = $prefix;
}
$entry[] = $identifiers;
$entry[] = $islandora_object->id;
if (!strlen($delimiter)) {
$entry_string = implode("\t", $entry) . "\n";
}
else {
$entry_string = implode($delimiter, $entry) . "\n";
}
file_put_contents($log_path, $entry_string, FILE_APPEND);
}
/**
* Parses an object's dc:identifier elements and returns their values.
*
* @param string $dc
* The content of the 'DC' datastream.
*
* @param string $pid
* The PID of the Islandora object just ingested.
*
* return string
* A string listing the values in dc:identifier, concatenated
* by a delimter if there are more than one dc:identifier.
*/
function islandora_log_ingest_get_identifer($dc, $pid) {
$id_delim = variable_get('islandora_log_ingest_id_delimiter', ';');
$identifiers = array();
$dom = new DOMDocument();
$dom->loadXML($dc->content);
foreach ($dom->getElementsByTagNameNS('http://purl.org/dc/elements/1.1/', 'identifier') as $element) {
$identifier = trim($element->nodeValue);
if ($identifier != $pid) {
$identifiers[] = $identifier;
}
}
if (!count($identifiers)) {
$identifiers = array('');
}
return implode($id_delim, $identifiers);
}
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