| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Implementation of hook_install().
|
| 6 |
*/
|
| 7 |
function password_reset_install() {
|
| 8 |
switch ($GLOBALS['db_type']) {
|
| 9 |
case 'mysql':
|
| 10 |
case 'mysqli':
|
| 11 |
db_query("CREATE TABLE {password_reset} (
|
| 12 |
qid int UNSIGNED NOT NULL auto_increment,
|
| 13 |
question varchar(255) NOT NULL default '',
|
| 14 |
PRIMARY KEY (qid)
|
| 15 |
) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
|
| 16 |
db_query("CREATE TABLE {password_reset_users} (
|
| 17 |
uid int UNSIGNED NOT NULL default 0,
|
| 18 |
qid int UNSIGNED NOT NULL default 0,
|
| 19 |
answer varchar(255) NOT NULL default '',
|
| 20 |
PRIMARY KEY (uid),
|
| 21 |
KEY qid (qid)
|
| 22 |
) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
|
| 23 |
break;
|
| 24 |
case 'pgsql':
|
| 25 |
// pgSQL is not really supported as there are a couple of REPLACE queries
|
| 26 |
// in the module.
|
| 27 |
db_query("CREATE TABLE {password_reset} (
|
| 28 |
qid serial CHECK (qid >= 0),
|
| 29 |
question varchar(255) NOT NULL default '',
|
| 30 |
PRIMARY KEY (qid)
|
| 31 |
)");
|
| 32 |
db_query("CREATE TABLE {password_reset_users} (
|
| 33 |
uid int UNSIGNED NOT NULL default 0,
|
| 34 |
qid int UNSIGNED NOT NULL default 0,
|
| 35 |
answer varchar(255) NOT NULL default '',
|
| 36 |
PRIMARY KEY (uid)
|
| 37 |
)");
|
| 38 |
db_query("CREATE INDEX {password_reset_users}_qid_idx ON {password_reset_users} (qid)");
|
| 39 |
break;
|
| 40 |
}
|
| 41 |
|
| 42 |
// Insert demo question.
|
| 43 |
db_query("INSERT INTO {password_reset} (question) VALUES ('What is your library card number?')");
|
| 44 |
|
| 45 |
$salt = 'ertertertdsfg';
|
| 46 |
// Initialise existing accounts with generated answers.
|
| 47 |
db_query("INSERT INTO {password_reset_users} (uid, qid, answer) SELECT u.uid, 1, MD5(u.pass + '". $salt ."') FROM {users} u WHERE u.uid > 0");
|
| 48 |
|
| 49 |
drupal_set_message(t('password_reset module: Installation script complete.'));
|
| 50 |
}
|
| 51 |
|
| 52 |
/**
|
| 53 |
* Implementation of hook_uninstall().
|
| 54 |
*/
|
| 55 |
function password_reset_uninstall() {
|
| 56 |
db_query('DROP TABLE {password_reset}');
|
| 57 |
db_query('DROP TABLE {password_reset_users}');
|
| 58 |
drupal_set_message(t('password_reset module: Uninstallation script complete.'));
|
| 59 |
}
|