-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuofm_batch_index.module
55 lines (51 loc) · 1.5 KB
/
uofm_batch_index.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
/**
* @file
* Queue information and functions
*/
define('UOFM_BATCH_INDEX_QUEUE', 'uofm_batch_reindex');
/**
* Implements hook_cron_queue_info().
*/
function uofm_batch_index_cron_queue_info() {
$queues[UOFM_BATCH_INDEX_QUEUE] = array(
'worker callback' => 'uofm_batch_index_process',
'time' => 180,
);
return $queues;
}
/**
* Initiate a re-index of the object.
*/
function uofm_batch_index_process($object) {
$obj = FALSE;
if (is_string($object)) {
module_load_include('inc', 'islandora', 'includes/utilities');
if (islandora_is_valid_pid($object)) {
$obj = islandora_object_load($object);
}
}
if (is_a($object, 'AbstractObject')) {
$obj = $object;
}
if ($obj) {
$url = variable_get('islandora_collection_search_gsearch_endpoint', 'http://localhost:8080/fedoragsearch/rest');
$user = variable_get('islandora_collection_search_gsearch_user', NULL);
$passwd = variable_get('islandora_collection_search_gsearch_password', NULL);
$ch = curl_init();
$params = array(
"operation" => "updateIndex",
"action" => "fromPid",
"value" => $object,
);
curl_setopt($ch, CURLOPT_URL, $url . "?" . http_build_query($params));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERPWD, "$user:$passwd");
$res = curl_exec($ch);
curl_close($ch);
if ($res === FALSE) {
watchdog('uofm_batch_index', 'Error re-indexing @o', array('@o' => $object));
}
}
}