Browse Source

This commit is bananas. B A N A N A S.

7.x-2.x
Daniel Lamb 9 years ago
parent
commit
ffa687da2b
  1. 4
      islandora/include/rdf_mapping.inc
  2. 28
      islandora_collection/islandora_collection.module
  3. 42
      islandora_delete_by_fedora_uri_service/include/islandora_delete_by_fedora_uri_service.inc
  4. 6
      islandora_delete_by_fedora_uri_service/islandora_delete_by_fedora_uri_service.info
  5. 48
      islandora_delete_by_fedora_uri_service/islandora_delete_by_fedora_uri_service.module

4
islandora/include/rdf_mapping.inc

@ -42,11 +42,11 @@ function islandora_get_default_rdf_mapping($bundle, array $rdf_types) {
),
ISLANDORA_FEDORA_HAS_PARENT_FIELD => array(
'predicates' => array('fedora:hasParent'),
'datatype' => 'xsd:string',
'type' => 'rel',
),
ISLANDORA_PCDM_HAS_MEMBER_FIELD => array(
'predicates' => array('pcdm:hasMember'),
'datatype' => 'xsd:string',
'type' => 'rel',
),
),
),

28
islandora_collection/islandora_collection.module

@ -71,7 +71,8 @@ function islandora_collection_node_postinsert($node) {
}
$node = array_pop($nodes);
httprl_request("http://localhost:8080/islandora-services/rest/collection",
// Don't forget the trailing slash.
httprl_request("http://localhost:8181/islandora/rest/collection/",
array(
'method' => 'POST',
'data' => json_encode($node),
@ -80,7 +81,7 @@ function islandora_collection_node_postinsert($node) {
}
/**
* Implements hook_update().
* Implements hook_node_postupdate().
*/
function islandora_collection_node_postupdate($node) {
if (isset($_SERVER['HTTP_IGNORE_HOOKS']) && strcmp(strtolower($_SERVER['HTTP_IGNORE_HOOKS']), "true") == 0) {
@ -105,10 +106,31 @@ function islandora_collection_node_postupdate($node) {
$node = array_pop($nodes);
$uuid = $node->uuid;
httprl_request("http://localhost:8080/islandora-services/rest/collection/$uuid",
httprl_request("http://localhost:8181/islandora/rest/collection/$uuid",
array(
'method' => 'PUT',
'data' => json_encode($node),
));
$response = httprl_send_request();
}
/**
* Implements hook_node_postdelete().
*/
function islandora_collection_node_postdelete($node) {
if (isset($_SERVER['HTTP_IGNORE_HOOKS']) && strcmp(strtolower($_SERVER['HTTP_IGNORE_HOOKS']), "true") == 0) {
return;
}
// Exit early if it's not a collection.
if (strcmp($node->type, ISLANDORA_COLLECTION_CONTENT_TYPE) != 0) {
return;
}
$uuid = $node->uuid;
httprl_request("http://localhost:8181/islandora/rest/collection/$uuid",
array(
'method' => 'DELETE',
));
$response = httprl_send_request();
}

42
islandora_delete_by_fedora_uri_service/include/islandora_delete_by_fedora_uri_service.inc

@ -0,0 +1,42 @@
<?php
/**
* @file
* Provides the callback implementations for the service.
*/
/**
* The POST callback for the deletion by Fedora URI service.
*
* @param array $args
* JSON encoded arguments to delete function.
*
* @return array
* JSON encoded response message.
*/
function islandora_delete_by_fedora_uri_service_delete(array $args) {
// Hack the Fedora path out of the POST data.
$fedora_uri = $args['fedoraUri'];
// Get entities identified by Fedora path.
$query = new EntityFieldQuery();
$results = $query->fieldCondition('field_fedora_path', 'value', $fedora_uri)
->execute();
// Delete 'em all.
foreach ($results as $entity_type => $entities) {
$ids = array_keys($entities);
if (entity_delete_multiple($entity_type, $ids) === FALSE) {
$response[] = "Could not delete any $entity_type identified by $fedora_uri.";
}
else {
$response[] = "Deleted entities of type $entity_type with ids " . implode(', ', $ids) . ".";
}
}
if (!isset($response)) {
$response[] = "Could not find any entities identified by $fedora_uri.";
}
return $response;
}

6
islandora_delete_by_fedora_uri_service/islandora_delete_by_fedora_uri_service.info

@ -0,0 +1,6 @@
name = Islandora Delete By Fedora URI Service
description = "Deletes Drupal nodes by Fedora URI. Needed for Sync to handle delete events that don't originate from Drupal."
package = Islandora
version = 7.x-dev
core = 7.x
dependencies[] = rest_server

48
islandora_delete_by_fedora_uri_service/islandora_delete_by_fedora_uri_service.module

@ -0,0 +1,48 @@
<?php
/**
* @file
* Provides a service for deleting Drupal nodes by Fedora path.
*/
/**
* Implements hook_permission().
*/
function islandora_delete_by_fedora_uri_service_permission() {
return array(
'islandora delete by fedora uri' => array(
'title' => t('Delete by Fedora URI.'),
'description' => t('Allows external sources to delete Drupal nodes by Fedora URI.'),
),
);
}
/**
* Implements hook_services_resources().
*/
function islandora_delete_by_fedora_uri_service_services_resources() {
return array(
'delete_by_fedora_uri' => array(
'create' => array(
'help' => t('Deletes a Drupal node by the Fedora URI supplied in the POST data.'),
'file' => array(
'type' => 'inc',
'module' => 'islandora_delete_by_fedora_uri_service',
'name' => 'include/islandora_delete_by_fedora_uri_service',
),
'callback' => 'islandora_delete_by_fedora_uri_service_delete',
'access callback' => 'user_access',
'access arguments' => array('islandora delete by fedora uri'),
'args' => array(
array(
'name' => 'args',
'type' => 'array',
'description' => t("JSON data containing arguments to the delete function (e.g. the Fedora URI)"),
'source' => 'data',
'optional' => FALSE,
),
),
),
),
);
}
Loading…
Cancel
Save