Browse Source

Basic implentation of other hooks and XPath Rules condition.

pull/558/head
Adam Vessey 10 years ago
parent
commit
03ca4ac116
  1. 4
      includes/tuque_wrapper.inc
  2. 8
      islandora.module
  3. 92
      islandora.rules.inc

4
includes/tuque_wrapper.inc

@ -228,6 +228,10 @@ class IslandoraFedoraObject extends FedoraObject {
if ($this->state == 'D') {
islandora_invoke_object_hooks(ISLANDORA_OBJECT_PURGED_HOOK, $this->models, $this->id);
}
// Fire of event if rules is enabled.
if (module_exists('rules')) {
rules_invoke_event('islandora_object_modified', $object);
}
}
catch (Exception $e) {
watchdog('islandora', 'Failed to modify object: @pid</br>code: @code<br/>message: @msg', array(

8
islandora.module

@ -1762,6 +1762,10 @@ function islandora_islandora_object_ingested(AbstractObject $object) {
* equal to the current ingested datastream's id.
*/
function islandora_islandora_datastream_ingested(AbstractObject $object, AbstractDatastream $datastream) {
if (module_exists('rules')) {
rules_invoke_event('islandora_datastream_ingested', $object, $datastream->id);
}
module_load_include('inc', 'islandora', 'includes/derivatives');
// Defer derivatives if necessary.
if (islandora_get_defer_derivatives_flag($object)) {
@ -1778,6 +1782,10 @@ function islandora_islandora_datastream_ingested(AbstractObject $object, Abstrac
* existing derivatives will be updated to reflect the change in the source.
*/
function islandora_islandora_datastream_modified(AbstractObject $object, AbstractDatastream $datastream) {
if (module_exists('rules')) {
rules_invoke_event('islandora_datastream_modified', $object, $datastream->id);
}
module_load_include('inc', 'islandora', 'includes/derivatives');
$logging_results = islandora_do_derivatives($object, array(
'source_dsid' => $datastream->id,

92
islandora.rules.inc

@ -21,6 +21,49 @@ function islandora_rules_event_info() {
),
),
),
'islandora_datastream_ingested' => array(
'group' => t('Islandora'),
'label' => t('Datastream ingested'),
'variables' => array(
'object' => array(
'type' => 'islandora_object',
'label' => t('The ingested object'),
'description' => t('A Tuque object for the Fedora object on which the datastream exists, as an entity.'),
),
'datastream' => array(
'type' => 'text',
'label' => t('Datastream ID'),
'description' => t('The ID of the ingested datastream.'),
),
),
),
'islandora_object_modified' => array(
'group' => t('Islandora'),
'label' => t('Object modified'),
'variables' => array(
'object' => array(
'type' => 'islandora_object',
'label' => t('The modified object'),
'description' => t('A Tuque object for the modified Fedora object, as an entity.'),
),
),
),
'islandora_datastream_modified' => array(
'group' => t('Islandora'),
'label' => t('Datastream modified'),
'variables' => array(
'object' => array(
'type' => 'islandora_object',
'label' => t('The modified object'),
'description' => t('A Tuque object for the Fedora object on which the datastream exists, as an entity.'),
),
'datastream' => array(
'type' => 'text',
'label' => t('Datastream ID'),
'description' => t('The ID of the ingested datastream.'),
),
),
),
);
}
@ -60,6 +103,32 @@ function islandora_rules_relationship_parameter_array() {
);
}
function islandora_rules_base_xpath_parameters() {
return array(
'object' => array(
'type' => 'islandora_object',
'label' => t('Object'),
'description' => t('The object in which to check the XPath.'),
),
'datastream' => array(
'type' => 'text',
'label' => t('Datastream ID'),
'description' => t('The ID of the XML datastream to check.'),
),
'xpath' => array(
'type' => 'text',
'label' => t('XPath'),
'description' => t('An XPath to evaluate.'),
),
'xpath_namespaces' => array(
'type' => 'taxonomy_vocabulary',
'label' => t('XPath Namespace Taxonomy'),
'description' => t('A flat taxonomy of which the terms are namespace prefixes and the description contains the URI for the namespace.')
),
);
}
/**
* Implements hook_rules_condition_info().
*/
@ -71,6 +140,11 @@ function islandora_rules_condition_info() {
'group' => t('Islandora'),
'parameter' => islandora_rules_relationship_parameter_array(),
);
$cond['islandora_rules_datastream_has_xpath'] = array(
'label' => t('Check for an XPath match in an XML datastream'),
'group' => t('Islandora'),
'parameter' => islandora_rules_base_xpath_parameters(),
);
return $cond;
}
@ -92,6 +166,7 @@ function islandora_rules_action_info() {
'group' => t('Islandora'),
'parameter' => islandora_rules_relationship_parameter_array(),
);
return $cond;
}
/**
@ -133,3 +208,20 @@ function islandora_object_remove_relationship($sub, $pred_uri, $pred, $object, $
function islandora_object_add_relationship($sub, $pred_uri, $pred, $object, $type) {
$sub->relationships->add($pred_uri, $pred, $object, $type);
}
function islandora_rules_datastream_has_xpath(AbstractObject $object, $datastream_id, $search_xpath, $xpath_vocab) {
if (!isset($object[$datastream_id])) {
// Datastream does no exists... No match.
return FALSE;
}
$datastream = $object[$datastream_id];
$doc = new DOMDocument();
$doc->loadXML($datastream->content);
$xpath = new DOMXPath($doc);
foreach (taxonomy_get_tree($xpath_vocab->vid, 0, 1, FALSE) as $term) {
$xpath->registerNamespace($term->name, $term->description);
}
$result = $xpath->query($search_xpath);
return $result->length > 0;
}

Loading…
Cancel
Save