@@ -112,7 +112,7 @@ function islandora_xacml_api_update_7102(&$sandbox) {
112
112
}
113
113
114
114
/**
115
- * Remove superfluous relationship from the RELS-INT.
115
+ * Remove superfluous relationship from the RELS-INT in the RELS-EXT namespace .
116
116
*
117
117
* @see https://jira.duraspace.org/browse/ISLANDORA-1273
118
118
*/
@@ -173,10 +173,106 @@ EOQ;
173
173
$ds = $parts[1];
174
174
$object_to_update = islandora_object_load($pid);
175
175
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
+
176
272
$manageable_by_user = 'isManageableByUser';
177
273
$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);
180
276
watchdog('islandora_xacml_api', 'Removed superfluous RELS-INT relationship for @pid on the @ds datastream.', array(
181
277
'@pid' => $pid,
182
278
'@ds' => $ds,
0 commit comments