| 1 |
<?php
|
| 2 |
/**
|
| 3 |
*$Id$
|
| 4 |
*@package AccountTypes
|
| 5 |
*@category NeighborForge
|
| 6 |
*/
|
| 7 |
|
| 8 |
/**
|
| 9 |
* Implementation of hook_install().
|
| 10 |
*/
|
| 11 |
function accounttypes_install() {
|
| 12 |
switch ($GLOBALS['db_type']) {
|
| 13 |
case 'mysql':
|
| 14 |
case 'mysqli':
|
| 15 |
$query1 = db_query("CREATE TABLE {accounttypes} (
|
| 16 |
atid int unsigned NOT NULL auto_increment,
|
| 17 |
name varchar(64) NOT NULL default '',
|
| 18 |
PRIMARY KEY (atid),
|
| 19 |
UNIQUE KEY (name)
|
| 20 |
) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
|
| 21 |
$query2 = db_query("CREATE TABLE {accounttypes_roles} (
|
| 22 |
atid int(10) unsigned NOT NULL default '0',
|
| 23 |
rid int(10) unsigned NOT NULL default '0',
|
| 24 |
initial tinyint(1) unsigned NOT NULL default '0',
|
| 25 |
PRIMARY KEY atrid (atid, rid)
|
| 26 |
) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
|
| 27 |
$query3 = db_query("CREATE TABLE {accounttypes_users} (
|
| 28 |
uid int(10) unsigned NOT NULL default '0',
|
| 29 |
atid int(10) unsigned NOT NULL default '0',
|
| 30 |
PRIMARY KEY (uid)
|
| 31 |
) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
|
| 32 |
break;
|
| 33 |
case 'pgsql':
|
| 34 |
//I don't really know what I'm doing here, so if I screwed up the pgsql, let me know how to fix it.
|
| 35 |
$query1 = db_query("CREATE TABLE {accounttypes} (
|
| 36 |
atid SERIAL PRIMARY KEY,
|
| 37 |
name varchar(64) NOT NULL,
|
| 38 |
UNIQUE (name)
|
| 39 |
)");
|
| 40 |
$query2 = db_query("CREATE TABLE {accounttypes_roles} (
|
| 41 |
atid int NOT NULL default '0',
|
| 42 |
rid int NOT NULL default '0',
|
| 43 |
initial smallint NOT NULL default '0',
|
| 44 |
PRIMARY KEY (atid, rid)
|
| 45 |
)");
|
| 46 |
$query3 = db_query("CREATE TABLE {accounttypes_users} (
|
| 47 |
uid int NOT NULL default '0',
|
| 48 |
atid int NOT NULL default '0',
|
| 49 |
PRIMARY KEY (uid)
|
| 50 |
)");
|
| 51 |
break;
|
| 52 |
}
|
| 53 |
|
| 54 |
$query4 = db_query("INSERT INTO {accounttypes} (name) VALUES ('basic')");
|
| 55 |
$query5 = db_query("INSERT INTO {accounttypes_roles} (atid, rid) VALUES ('1', '2')");
|
| 56 |
|
| 57 |
if ($query1 && $query2 && $query3 && $query4 && $query5) {
|
| 58 |
drupal_set_message('The Account Types module was installed successfully. Tables were added to the database.');
|
| 59 |
}
|
| 60 |
else {
|
| 61 |
drupal_set_message('There was an error installing the Account Types database tables.', 'error');
|
| 62 |
}
|
| 63 |
}
|
| 64 |
|
| 65 |
/**
|
| 66 |
* Implementation of hook_install().
|
| 67 |
*/
|
| 68 |
function accounttypes_update_1() {
|
| 69 |
$ret = array();
|
| 70 |
switch ($GLOBALS['db_type']) {
|
| 71 |
case 'mysql':
|
| 72 |
case 'mysqli':
|
| 73 |
$ret[] = update_sql("ALTER TABLE {accounttypes_roles} ADD initial tinyint(1) unsigned default '0' NOT NULL");
|
| 74 |
break;
|
| 75 |
case 'pgsql':
|
| 76 |
db_add_column($ret[], 'accounttypes_roles', 'initial', 'smallint', array('default' => 0, 'not null' => TRUE));
|
| 77 |
break;
|
| 78 |
}
|
| 79 |
return $ret;
|
| 80 |
}
|
| 81 |
|
| 82 |
/**
|
| 83 |
* Implementation of hook_uninstall().
|
| 84 |
*/
|
| 85 |
function accounttypes_uninstall() {
|
| 86 |
$vardel = FALSE;
|
| 87 |
$query1 = db_query('DROP TABLE {accounttypes}');
|
| 88 |
$query2 = db_query('DROP TABLE {accounttypes_roles}');
|
| 89 |
$query3 = db_query('DROP TABLE {accounttypes_users}');
|
| 90 |
//TODO unset $account->selectAT for all users
|
| 91 |
if(variable_del('accounttypes_default')) {
|
| 92 |
$vardel = TRUE;
|
| 93 |
}
|
| 94 |
|
| 95 |
if ($query1 && $query2 && $query3 && $vardel) {
|
| 96 |
drupal_set_message('The Account Types module was uninstalled successfully.');
|
| 97 |
}
|
| 98 |
else {
|
| 99 |
drupal_set_message('There was an error removing the Account Types database tables.', 'error');
|
| 100 |
}
|
| 101 |
|
| 102 |
}
|