-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoda.deploy.php
46 lines (44 loc) · 1.18 KB
/
oda.deploy.php
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
<?php
/**
* @file
* Contains oda_deploy.install.
*/
/**
* Add role name to oda_access_control terms.
*/
function oda_deploy_10000_accesscontrol() {
$terms = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadTree('oda_access_control');
$oda_access_terms = [];
foreach ($terms as $term) {
$query = \Drupal::database()->select('permissions_by_term_role', 'p');
$query->fields('p', ['rid']);
$query->condition('p.tid', $term->tid);
$query->condition('p.rid', 'oit_oda%', 'LIKE');
$results = $query->execute()->fetchAll();
$term_name = $term->name;
$tid = $term->tid;
if ($tid == 1229) {
$key = 'anonymous';
}
elseif ($tid == 1228) {
$key = 'authenticated';
}
elseif ($tid == 1227) {
$key = 'dl_student';
}
else {
$key = $results[0]->rid;
}
$oda_access_terms[$term_name] = [
'role' => $key,
'tid' => $tid,
];
}
foreach ($oda_access_terms as $term_name => $term) {
$tid = $term['tid'];
$role = $term['role'];
$term = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->load($tid);
$term->field_oda_role_machine_name->value = $role;
$term->save();
}
}