-
Notifications
You must be signed in to change notification settings - Fork 2
/
cwrc_entities.drush.inc
147 lines (116 loc) · 3.63 KB
/
cwrc_entities.drush.inc
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
/**
* @file
* Custom CWRC drush scripts.
*/
/**
* Implements hook_drush_command().
*/
function cwrc_entities_drush_command()
{
$items = array();
$items['cwrc_entities_test'] = array(
'description' => 'Test',
'examples' => array(
'drush -u 1 cwrc_entities_test'
),
'bootstrap' => DRUSH_BOOTSTRAP_MAX
);
$items['cwrc_entities_add_missing_stubs'] = array(
'description' => 'Add missing stub entities for external URIs',
'examples' => array(
'drush -u 1 --uri=http://example.com cwrc_entities_add_missing_stubs'
),
'bootstrap' => DRUSH_BOOTSTRAP_MAX
);
$items['cwrc_entities_add_missing_stubs_from_pid'] = array(
'description' => 'Add missing stub entities for external URIs by PID',
'examples' => array(
'drush -u 1 cwrc_entities_add_missing_stubs_from_pid PID'
),
'arguments' => array(
'pid' => "FedoraCommons Object PID",
),
'bootstrap' => DRUSH_BOOTSTRAP_MAX
);
$items['cwrc_entities_eap_test'] = array(
'description' => 'Test the Entity Aggregation Page using a give URI',
'examples' => array(
'drush -u 1 --uri=http://example.com cwrc_entities_eap_test URI'
),
'arguments' => array(
'uri' => "Entity URI",
),
'bootstrap' => DRUSH_BOOTSTRAP_MAX
);
return $items;
}
/**
* Test the entities stub building code
*/
function drush_cwrc_entities_test()
{
drush_print("Extract, lookup, and create stubs for external entities");
// Include modules.
module_load_include('inc', 'cwrc_entities', 'includes/external_entities');
/*
cwrc_entities_traverse_xml('
<x ref="http://viaf.org/viaf/147166987">
<x ref="http://www.geonames.org/6106437"></x>
<x ref="http://viaf.org/viaf/29547910"></x>
<x ref="http://viaf.org/viaf/219468490/"></x>
<x ref="https://www.google.ca/maps/place/Carmel-By-The-Sea,%20CA%2093923,%20USA"></x>
</x>');
*/
cwrc_entities_traverse_xml(
//'<x ref="http://viaf.org/viaf/174618349"></x>'
'<x ref="http://www.geonames.org/6148428"></x>'
);
}
/**
* entities stub building code
*/
function drush_cwrc_entities_add_missing_stubs()
{
drush_print("Add missing stub entities for external URIs");
// Include modules.
module_load_include('inc', 'cwrc_entities', 'includes/external_entities');
module_load_include('inc', 'islandora_cwrc_basexdb', 'includes/xmldb_endpoints');
$keyValue = array();
$tmp = islandora_cwrc_exec_xquery(ISLANDORA_EAP_EXTERNAL_MISSING_STUBS, $keyValue);
$tmp = json_decode($tmp, TRUE);
foreach ( array_unique($tmp['missingStubs']) as $uri )
{
print($uri."\n");
cwrc_entities_handle_external_by_uri($uri);
}
}
/**
* entities stub building code
*/
function drush_cwrc_entities_add_missing_stubs_from_pid($pid='')
{
drush_print("Add missing stub entities within a given PID");
//$pid = drush_get_option('pid');
// Include modules.
module_load_include('inc', 'cwrc_entities', 'includes/external_entities');
print($pid."\n");
cwrc_entities_handle_external_by_pid($pid);
print($pid."\n");
}
/**
* Test the Entity Aggregation Page using a give URI
*/
function drush_cwrc_entities_eap_test($uri='')
{
drush_print("Build Entity Aggregation Page JSON for a given URI");
// Include modules.
module_load_include('inc', 'islandora_cwrc_basexdb', 'includes/xmldb_endpoints');
print($uri."\n");
$json_results = "";
if ($uri) {
$pidKeyValue = array("ENTITY_URI" => "$uri");
$json_results = islandora_cwrc_exec_xquery(ISLANDORA_EAP_XQUERY_ID, $pidKeyValue);
}
print($json_results."\n");
}