| 1 |
<?php
|
| 2 |
|
| 3 |
// $Id: userprotect.install,v 1.15 2009/10/31 21:27:25 thehunmonkgroup Exp $
|
| 4 |
|
| 5 |
/**
|
| 6 |
* @file
|
| 7 |
* Install, update and uninstall functions for the userprotect module.
|
| 8 |
*/
|
| 9 |
|
| 10 |
/**
|
| 11 |
* Implement hook_update_last_removed().
|
| 12 |
*/
|
| 13 |
function userprotect_update_last_removed() {
|
| 14 |
return 6001;
|
| 15 |
}
|
| 16 |
|
| 17 |
/**
|
| 18 |
* Implement hook_install().
|
| 19 |
*/
|
| 20 |
function userprotect_install() {
|
| 21 |
|
| 22 |
// Default protections.
|
| 23 |
db_insert('userprotect')
|
| 24 |
->fields(array(
|
| 25 |
'uid' => 0,
|
| 26 |
'up_name' => 0,
|
| 27 |
'up_mail' => 0,
|
| 28 |
'up_pass' => 0,
|
| 29 |
'up_status' => 0,
|
| 30 |
'up_roles' => 0,
|
| 31 |
'up_cancel' => 1,
|
| 32 |
'up_edit' => 1,
|
| 33 |
'up_type' => 'user',
|
| 34 |
'up_openid' => 1,
|
| 35 |
))->execute();
|
| 36 |
db_insert('userprotect')
|
| 37 |
->fields(array(
|
| 38 |
'uid' => 1,
|
| 39 |
'up_name' => 0,
|
| 40 |
'up_mail' => 0,
|
| 41 |
'up_pass' => 0,
|
| 42 |
'up_status' => 0,
|
| 43 |
'up_roles' => 0,
|
| 44 |
'up_cancel' => 1,
|
| 45 |
'up_edit' => 1,
|
| 46 |
'up_type' => 'user',
|
| 47 |
'up_openid' => 1,
|
| 48 |
))->execute();
|
| 49 |
|
| 50 |
// Default administrator bypass.
|
| 51 |
db_insert('userprotect')
|
| 52 |
->fields(array(
|
| 53 |
'uid' => 1,
|
| 54 |
'up_name' => 1,
|
| 55 |
'up_mail' => 1,
|
| 56 |
'up_pass' => 1,
|
| 57 |
'up_status' => 1,
|
| 58 |
'up_roles' => 1,
|
| 59 |
'up_cancel' => 1,
|
| 60 |
'up_edit' => 1,
|
| 61 |
'up_type' => 'admin',
|
| 62 |
'up_openid' => 1,
|
| 63 |
))->execute();
|
| 64 |
|
| 65 |
//Default permissions for authenticated users.
|
| 66 |
$permissions = array(
|
| 67 |
'change own e-mail',
|
| 68 |
'change own password',
|
| 69 |
'change own openid',
|
| 70 |
);
|
| 71 |
foreach ($permissions as $permission) {
|
| 72 |
db_insert('role_permission')
|
| 73 |
->fields(array(
|
| 74 |
'rid' => DRUPAL_AUTHENTICATED_RID,
|
| 75 |
'permission' => $permission,
|
| 76 |
))->execute();
|
| 77 |
}
|
| 78 |
}
|
| 79 |
|
| 80 |
/**
|
| 81 |
* Implement hook_schema().
|
| 82 |
*/
|
| 83 |
function userprotect_schema() {
|
| 84 |
$schema['userprotect'] = array(
|
| 85 |
'description' => 'Stores information about administer protections for users.',
|
| 86 |
'fields' => array(
|
| 87 |
'uid' => array(
|
| 88 |
'description' => 'User ID.',
|
| 89 |
'type' => 'int',
|
| 90 |
'not null' => TRUE,
|
| 91 |
'default' => 0,
|
| 92 |
),
|
| 93 |
'up_name' => array(
|
| 94 |
'type' => 'int',
|
| 95 |
'size' => 'small',
|
| 96 |
'not null' => TRUE,
|
| 97 |
'default' => 0,
|
| 98 |
'description' => 'Name protection.',
|
| 99 |
),
|
| 100 |
'up_mail' => array(
|
| 101 |
'type' => 'int',
|
| 102 |
'size' => 'small',
|
| 103 |
'not null' => TRUE,
|
| 104 |
'default' => 0,
|
| 105 |
'description' => 'E-mail protection.',
|
| 106 |
),
|
| 107 |
'up_pass' => array(
|
| 108 |
'type' => 'int',
|
| 109 |
'size' => 'small',
|
| 110 |
'not null' => TRUE,
|
| 111 |
'default' => 0,
|
| 112 |
'description' => 'Password protection.',
|
| 113 |
),
|
| 114 |
'up_status' => array(
|
| 115 |
'type' => 'int',
|
| 116 |
'size' => 'small',
|
| 117 |
'not null' => TRUE,
|
| 118 |
'default' => 0,
|
| 119 |
'description' => 'Status protection.',
|
| 120 |
),
|
| 121 |
'up_roles' => array(
|
| 122 |
'type' => 'int',
|
| 123 |
'size' => 'small',
|
| 124 |
'not null' => TRUE,
|
| 125 |
'default' => 0,
|
| 126 |
'description' => 'Role protection.',
|
| 127 |
),
|
| 128 |
'up_cancel' => array(
|
| 129 |
'type' => 'int',
|
| 130 |
'size' => 'small',
|
| 131 |
'not null' => TRUE,
|
| 132 |
'default' => 0,
|
| 133 |
'description' => 'Cancellation protection.',
|
| 134 |
),
|
| 135 |
'up_edit' => array(
|
| 136 |
'type' => 'int',
|
| 137 |
'size' => 'small',
|
| 138 |
'not null' => TRUE,
|
| 139 |
'default' => 0,
|
| 140 |
'description' => 'All edits protection.',
|
| 141 |
),
|
| 142 |
'up_type' => array(
|
| 143 |
'type' => 'char',
|
| 144 |
'length' => 20,
|
| 145 |
'not null' => TRUE,
|
| 146 |
'default' => '',
|
| 147 |
'description' => 'Protection type.',
|
| 148 |
),
|
| 149 |
'up_openid' => array(
|
| 150 |
'type' => 'int',
|
| 151 |
'size' => 'small',
|
| 152 |
'not null' => TRUE,
|
| 153 |
'default' => 0,
|
| 154 |
'description' => 'OpenID protection.',
|
| 155 |
),
|
| 156 |
),
|
| 157 |
'unique keys' => array('uid_up_type' => array('uid', 'up_type')),
|
| 158 |
'foreign keys' => array(
|
| 159 |
'uid' => array('user' => 'uid'),
|
| 160 |
),
|
| 161 |
);
|
| 162 |
|
| 163 |
return $schema;
|
| 164 |
}
|
| 165 |
|
| 166 |
/**
|
| 167 |
* Change up_delete to up_cancel, in line with core's change from user delete
|
| 168 |
* to user cancel.
|
| 169 |
*/
|
| 170 |
function userprotect_update_7000() {
|
| 171 |
$spec = array(
|
| 172 |
'type' => 'int',
|
| 173 |
'size' => 'small',
|
| 174 |
'not null' => TRUE,
|
| 175 |
'default' => 0,
|
| 176 |
'description' => 'Cancellation protection.',
|
| 177 |
);
|
| 178 |
db_change_field('userprotect', 'up_delete', 'up_cancel', $spec);
|
| 179 |
}
|
| 180 |
/**
|
| 181 |
* Implement hook_uninstall().
|
| 182 |
*/
|
| 183 |
function userprotect_uninstall() {
|
| 184 |
|
| 185 |
// Drop variables.
|
| 186 |
$variables = array(
|
| 187 |
'userprotect_protection_defaults',
|
| 188 |
'userprotect_autoprotect',
|
| 189 |
'userprotect_administrator_bypass_defaults',
|
| 190 |
'userprotect_role_protections',
|
| 191 |
);
|
| 192 |
foreach ($variables as $variable) {
|
| 193 |
variable_del($variable);
|
| 194 |
}
|
| 195 |
}
|