Projet

Général

Profil

Paste
Télécharger (4,76 ko) Statistiques
| Branche: | Révision:

root / htmltest / sites / all / modules / masquerade / masquerade.install @ a5572547

1
<?php
2

    
3
/**
4
 * @file
5
 * masquerade.install
6
 *
7
 * Install, uninstall and update hooks for the Masquarade module.
8
 */
9

    
10
/**
11
 * Implements hook_schema().
12
 *
13
 * @return array
14
 */
15
function masquerade_schema() {
16
  return array(
17
    'masquerade' => array(
18
      'description' => 'Each masquerading user has their session recorded into the masquerade table. Each record represents a masquerading user.',
19
      'fields' => array(
20
        'sid' => array(
21
          'description' => 'The current session for this masquerading user corresponding to their {sessions}.sid.',
22
          'type' => 'varchar',
23
          'length' => '64',
24
          'not null' => TRUE,
25
          'default' => ''),
26
        'uid_from' => array(
27
          'description' => 'The {users}.uid corresponding to a session.',
28
          'type' => 'int',
29
          'not null' => TRUE,
30
          'default' => 0,
31
          'disp-width' => '10'),
32
        'uid_as' => array(
33
          'description' => 'The {users}.uid this session is masquerading as.',
34
          'type' => 'int',
35
          'not null' => TRUE,
36
          'default' => 0,
37
          'disp-width' => '10'),
38
      ),
39
      'indexes' => array(
40
        'sid' => array('sid', 'uid_from'),
41
        'sid_2' => array('sid', 'uid_as'),
42
      ),
43
    ),
44
    'masquerade_users' => array(
45
      'description' => 'Per-user permission table granting permissions to switch as a specific user.',
46
      'fields' => array(
47
        'uid_from' => array(
48
          'description' => 'The {users}.uid that can masquerade as {masquerade_users}.uid_to.',
49
          'type' => 'int',
50
          'not null' => TRUE,
51
          'default' => 0,
52
          'disp-width' => 10,
53
        ),
54
        'uid_to' => array(
55
          'description' => 'The {users}.uid that {masquerade_users}.uid_from can masquerade as.',
56
          'type' => 'int',
57
          'not null' => TRUE,
58
          'default' => 0,
59
          'disp-width' => 10,
60
        ),
61
      ),
62
      'primary key' => array('uid_from', 'uid_to'),
63
    ),
64
  );
65
}
66

    
67
/**
68
 * Implements hook_install().
69
 */
70
function masquerade_install() {
71
  db_update('system')
72
    ->fields(array('weight' => -10))
73
    ->condition('name', 'masquerade')
74
    ->execute();
75
}
76

    
77
/**
78
 * Implements hook_uninstall().
79
 */
80
function masquerade_uninstall() {
81
  variable_del('masquerade_test_user');
82
  variable_del('masquerade_admin_roles');
83
  variable_del('masquerade_quick_switches');
84
}
85

    
86
/**
87
 * Reformat variable value.
88
 */
89
function masquerade_update_6001() {
90
  variable_set('masquerade_quick_switches', implode(',', variable_get('masquerade_quick_switches', array())));
91
}
92

    
93
/**
94
 * Make the sid column match the length of the core sessions table (64 characters).
95
 */
96
function masquerade_update_6002() {
97
  db_drop_index('masquerade', 'sid');
98
  db_drop_index('masquerade', 'sid_2');
99
  db_change_field('masquerade', 'sid', 'sid', array(
100
    'type' => 'varchar',
101
    'length' => '64',
102
    'not null' => TRUE,
103
    'default' => '')
104
  );
105
  db_add_index('masquerade', 'sid', array('sid', 'uid_from'));
106
  db_add_index('masquerade', 'sid_2', array('sid', 'uid_as'));
107
}
108

    
109
/**
110
 * Change masquerade_quick_switches variable to store a serialized array of
111
 * user ID's. Reverts update 6001.
112
 */
113
function masquerade_update_6003() {
114
  $users = variable_get('masquerade_quick_switches', NULL);
115
  if (!empty($users)) {
116
    $user_ids = drupal_explode_tags($users);
117
    if (!empty($user_ids)) {
118
      variable_set('masquerade_quick_switches', $user_ids);
119
    }
120
  }
121
  else {
122
    variable_del('masquerade_quick_switches');
123
  }
124
}
125

    
126
/**
127
 * Set the weight of the masquerade module to -10, but only if it hasn't
128
 * previously been changed.
129
 */
130
function masquerade_update_6004() {
131
  db_update('system')
132
    ->fields(array('weight' => -10))
133
    ->condition('name', 'masquerade')
134
    ->execute();
135
}
136

    
137
/**
138
 * Add a table storing specific user pairings a user can masquerade as.
139
 */
140
function masquerade_update_6005() {
141
  $schema = array(
142
    'masquerade_users' => array(
143
      'fields' => array(
144
        'uid_from' => array(
145
          'type' => 'int',
146
          'not null' => TRUE,
147
          'default' => 0,
148
          'disp-width' => 10,
149
        ),
150
        'uid_to' => array(
151
          'type' => 'int',
152
          'not null' => TRUE,
153
          'default' => 0,
154
          'disp-width' => 10,
155
        ),
156
      ),
157
      'primary key' => array('uid_from', 'uid_to'),
158
    )
159
  );
160
  db_create_table('masquerade_users', $schema['masquerade_users']);
161
}
162

    
163
/**
164
 * Update masquerade block delta.
165
 */
166
function masquerade_update_7000() {
167
  db_update('block')
168
    ->fields(array('delta' => 'masquerade'))
169
    ->condition('module', 'masquerade')
170
    ->condition('delta', 0)
171
    ->execute();
172
}
173

    
174
/**
175
 * Update masquerade block caching.
176
 */
177
function masquerade_update_7001() {
178
  db_update('block')
179
    ->fields(array('cache' => DRUPAL_NO_CACHE))
180
    ->condition('module', 'masqurade')
181
    ->condition('delta', 'masquerade')
182
    ->execute();
183
}