Skip to content

Commit f5d75fd

Browse files
committed
Merge pull request Islandora#115 from nhart/7.x-update-hook-bug
hack in temp ds if it doesnt exist. use rels-int ns
2 parents 7c56591 + b8e630c commit f5d75fd

File tree

1 file changed

+99
-3
lines changed

1 file changed

+99
-3
lines changed

api/islandora_xacml_api.install

+99-3
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ function islandora_xacml_api_update_7102(&$sandbox) {
112112
}
113113

114114
/**
115-
* Remove superfluous relationship from the RELS-INT.
115+
* Remove superfluous relationship from the RELS-INT in the RELS-EXT namespace.
116116
*
117117
* @see https://jira.duraspace.org/browse/ISLANDORA-1273
118118
*/
@@ -173,10 +173,106 @@ EOQ;
173173
$ds = $parts[1];
174174
$object_to_update = islandora_object_load($pid);
175175

176+
// Add temp ds to existing update because if the hook fails,
177+
// it's still pending.
178+
if (!isset($object_to_update[$ds])) {
179+
$temp_ds = $object_to_update->constructDatastream($ds);
180+
}
181+
else {
182+
$temp_ds = $object_to_update[$ds];
183+
}
184+
185+
$manageable_by_user = 'isManageableByUser';
186+
$manageable_by_role = 'isManageableByRole';
187+
$temp_ds->relationships->remove(ISLANDORA_RELS_EXT_URI, $manageable_by_user);
188+
$temp_ds->relationships->remove(ISLANDORA_RELS_EXT_URI, $manageable_by_role);
189+
watchdog('islandora_xacml_api', 'Removed superfluous RELS-INT relationship for @pid on the @ds datastream.', array(
190+
'@pid' => $pid,
191+
'@ds' => $ds,
192+
));
193+
194+
$sandbox['progress'] = min($sandbox['total'], $sandbox['progress'] + 1);
195+
$sandbox['#finished'] = $sandbox['progress'] / $sandbox['total'];
196+
if ($sandbox['#finished'] >= 1) {
197+
return t('Updated @count PID(s).', array(
198+
'@count' => $sandbox['total'],
199+
));
200+
}
201+
}
202+
203+
/**
204+
* Remove superfluous relationship from the RELS-INT in the RELS-INT namespace.
205+
*
206+
* @see https://jira.duraspace.org/browse/ISLANDORA-1273
207+
*/
208+
function islandora_xacml_api_update_7104(&$sandbox) {
209+
if (!variable_get('islandora_xacml_api_save_relationships', TRUE)) {
210+
return t('Relationships are disabled, nothing to do.');
211+
}
212+
drupal_load('module', 'islandora');
213+
$tuque = islandora_get_tuque_connection();
214+
$rels_int_uri = ISLANDORA_RELS_INT_URI;
215+
216+
$query = <<<EOQ
217+
SELECT DISTINCT ?ds FROM <#ri> WHERE {
218+
{
219+
{
220+
?ds <{$rels_int_uri}isManageableByRole> ?role
221+
}
222+
UNION {
223+
?ds <{$rels_int_uri}isManageableByUser> ?user
224+
}
225+
}
226+
?obj <fedora-view:disseminates> ?ds
227+
}
228+
EOQ;
229+
230+
if (!isset($sandbox['total'])) {
231+
$sandbox['progress'] = 0;
232+
$sandbox['total'] = $tuque->repository->ri->countQuery($query, 'sparql');
233+
if ($sandbox['total'] == 0) {
234+
// Nothing to process.
235+
$sandbox['#finished'] = 1;
236+
return t('Nothing to fix.');
237+
}
238+
$sandbox['result_stash'] = array();
239+
}
240+
241+
if (empty($sandbox['result_stash'])) {
242+
$offset = 100;
243+
$limited_query = $query . <<<EOQ
244+
LIMIT $offset
245+
EOQ;
246+
247+
$sandbox['result_stash'] = $tuque->repository->ri->sparqlQuery($limited_query);
248+
if (empty($sandbox['result_stash'])) {
249+
// Ran out of items early?
250+
$sandbox['#finished'] = 1;
251+
return t('Updated @count PID(s) and ran out of items early... Somebody manually updated a document?', array(
252+
'@count' => $sandbox['total'],
253+
));
254+
}
255+
}
256+
257+
$result = array_pop($sandbox['result_stash']);
258+
$datastream_uri = $result['ds']['value'];
259+
260+
$parts = explode('/', $datastream_uri);
261+
$pid = $parts[0];
262+
$ds = $parts[1];
263+
$object_to_update = islandora_object_load($pid);
264+
265+
if (!isset($object_to_update[$ds])) {
266+
$temp_ds = $object_to_update->constructDatastream($ds);
267+
}
268+
else {
269+
$temp_ds = $object_to_update[$ds];
270+
}
271+
176272
$manageable_by_user = 'isManageableByUser';
177273
$manageable_by_role = 'isManageableByRole';
178-
$object_to_update[$ds]->relationships->remove(ISLANDORA_RELS_EXT_URI, $manageable_by_user);
179-
$object_to_update[$ds]->relationships->remove(ISLANDORA_RELS_EXT_URI, $manageable_by_role);
274+
$temp_ds->relationships->remove(ISLANDORA_RELS_INT_URI, $manageable_by_user);
275+
$temp_ds->relationships->remove(ISLANDORA_RELS_INT_URI, $manageable_by_role);
180276
watchdog('islandora_xacml_api', 'Removed superfluous RELS-INT relationship for @pid on the @ds datastream.', array(
181277
'@pid' => $pid,
182278
'@ds' => $ds,

0 commit comments

Comments
 (0)