Newer
Older
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<?php
/**
* @file
* masquerade.install
*
* Install, uninstall and update hooks for the Masquarade module.
*/
/**
* Implements hook_schema().
*
* @return array
*/
function masquerade_schema() {
return array(
'masquerade' => array(
'description' => 'Each masquerading user has their session recorded into the masquerade table. Each record represents a masquerading user.',
'fields' => array(
'sid' => array(
'description' => 'The current session for this masquerading user corresponding to their {sessions}.sid.',
'type' => 'varchar',
'length' => '64',
'not null' => TRUE,
'default' => ''),
'uid_from' => array(
'description' => 'The {users}.uid corresponding to a session.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'disp-width' => '10'),
'uid_as' => array(
'description' => 'The {users}.uid this session is masquerading as.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'disp-width' => '10'),
),
'indexes' => array(
'sid' => array('sid', 'uid_from'),
'sid_2' => array('sid', 'uid_as'),
),
),
'masquerade_users' => array(
'description' => 'Per-user permission table granting permissions to switch as a specific user.',
'fields' => array(
'uid_from' => array(
'description' => 'The {users}.uid that can masquerade as {masquerade_users}.uid_to.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'disp-width' => 10,
),
'uid_to' => array(
'description' => 'The {users}.uid that {masquerade_users}.uid_from can masquerade as.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'disp-width' => 10,
),
),
'primary key' => array('uid_from', 'uid_to'),
),
);
}
/**
* Implements hook_install().
*/
function masquerade_install() {
db_update('system')
->fields(array('weight' => -10))
->condition('name', 'masquerade')
->execute();
}
/**
* Implements hook_uninstall().
*/
function masquerade_uninstall() {
variable_del('masquerade_test_user');
variable_del('masquerade_admin_roles');
variable_del('masquerade_quick_switches');
}
/**
* Reformat variable value.
*/
function masquerade_update_6001() {
variable_set('masquerade_quick_switches', implode(',', variable_get('masquerade_quick_switches', array())));
}
/**
* Make the sid column match the length of the core sessions table (64 characters).
*/
function masquerade_update_6002() {
db_drop_index('masquerade', 'sid');
db_drop_index('masquerade', 'sid_2');
db_change_field('masquerade', 'sid', 'sid', array(
'type' => 'varchar',
'length' => '64',
'not null' => TRUE,
'default' => '')
);
db_add_index('masquerade', 'sid', array('sid', 'uid_from'));
db_add_index('masquerade', 'sid_2', array('sid', 'uid_as'));
}
/**
* Change masquerade_quick_switches variable to store a serialized array of
* user ID's. Reverts update 6001.
*/
function masquerade_update_6003() {
$users = variable_get('masquerade_quick_switches', NULL);
if (!empty($users)) {
$user_ids = drupal_explode_tags($users);
if (!empty($user_ids)) {
variable_set('masquerade_quick_switches', $user_ids);
}
}
else {
variable_del('masquerade_quick_switches');
}
}
/**
* Set the weight of the masquerade module to -10, but only if it hasn't
* previously been changed.
*/
function masquerade_update_6004() {
db_update('system')
->fields(array('weight' => -10))
->condition('name', 'masquerade')
->execute();
}
/**
* Add a table storing specific user pairings a user can masquerade as.
*/
function masquerade_update_6005() {
$schema = array(
'masquerade_users' => array(
'fields' => array(
'uid_from' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'disp-width' => 10,
),
'uid_to' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'disp-width' => 10,
),
),
'primary key' => array('uid_from', 'uid_to'),
)
);
db_create_table('masquerade_users', $schema['masquerade_users']);
}
/**
* Update masquerade block delta.
*/
function masquerade_update_7000() {
db_update('block')
->fields(array('delta' => 'masquerade'))
->condition('module', 'masquerade')
->condition('delta', 0)
->execute();
}
/**
* Update masquerade block caching.
*/
function masquerade_update_7001() {
db_update('block')
->fields(array('cache' => DRUPAL_NO_CACHE))
->condition('module', 'masqurade')
->condition('delta', 'masquerade')
->execute();
}