-
Notifications
You must be signed in to change notification settings - Fork 12
/
zmt_core.install
81 lines (71 loc) · 1.82 KB
/
zmt_core.install
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
<?php
/**
* Implements hook_install().
*/
function zmt_core_install() {
zmt_add_role();
}
/**
* Implements hook_uninstall().
*/
function zmt_core_uninstall() {
$zimbra_rid = (int) variable_get('zmt_zimbra_role_id', 0);
$tenant_rid = (int) variable_get('zmt_tenant_role_id', 0);
$domain_rid = (int) variable_get('zmt_domain_role_id', 0);
$group_rid = (int) variable_get('zmt_group_role_id', 0);
user_role_delete($zimbra_rid);
user_role_delete($tenant_rid);
user_role_delete($domain_rid);
user_role_delete($group_rid);
variable_del('zmt_zimbra_role_id');
variable_del('zmt_tenant_role_id');
variable_del('zmt_domain_role_id');
variable_del('zmt_group_role_id');
}
/**
* Define user roles.
*/
function zmt_add_role(){
$zimbra_role = 'Zmt Zimbra';
$tenant_role = 'Zmt Tenant';
$domain_role = 'Zmt Domain';
$group_role = 'Zmt Group';
$new_roles = array(
$zimbra_role,
$tenant_role,
$domain_role,
$group_role,
);
$roles = user_roles();
foreach ($new_roles as $role) {
if(!in_array($role, $roles)) {
$add_role = new stdClass();
$add_role->name = $role;
user_role_save($add_role);
}
}
$roles = user_roles();
$zimbra_rid = 0;
$tenant_rid = 0;
$domain_rid = 0;
$group_rid = 0;
foreach ($roles as $key => $role) {
if ($role == $zimbra_role) {
$zimbra_rid = $key;
}
if ($role == $tenant_role) {
$tenant_rid = $key;
}
if ($role == $domain_role) {
$domain_rid = $key;
}
if ($role == $group_role) {
$group_rid = $key;
}
}
user_role_change_permissions($zimbra_rid, array('administer zmt' => 1));
variable_set('zmt_zimbra_role_id', $zimbra_rid);
variable_set('zmt_tenant_role_id', $tenant_rid);
variable_set('zmt_domain_role_id', $domain_rid);
variable_set('zmt_group_role_id', $group_rid);
}