| 1 |
<?php
|
| 2 |
// $Id: taxonomy_access.install,v 1.8.4.5 2008/02/22 20:44:29 keve Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Implementations of hook_update (called by update.php)
|
| 6 |
*/
|
| 7 |
|
| 8 |
// Update#1: updating the tables to UTF-8
|
| 9 |
function taxonomy_access_update_1() {
|
| 10 |
return _system_update_utf8(array('term_access', 'term_access_defaults'));
|
| 11 |
}
|
| 12 |
|
| 13 |
// Update#2: adding field 'grant_list' to tables 'term_access' and 'term_access_defaults'.
|
| 14 |
function taxonomy_access_update_2() {
|
| 15 |
switch ($GLOBALS['db_type']) {
|
| 16 |
case 'pgsql':
|
| 17 |
// Checking if column 'grant_list' exists
|
| 18 |
if (db_result(db_query("SELECT a.attname FROM {pg_attribute} a LEFT JOIN {pg_class} c ON c.oid = a.attrelid WHERE c.relname = 'term_access' AND a.attname = 'grant_list'"))) {
|
| 19 |
drupal_set_message(t("Taxonomy Access - Update #2: No queries executed. Field 'grant_list' already exists in tables 'term_access'."), 'error');
|
| 20 |
$ret = array();
|
| 21 |
}
|
| 22 |
else {
|
| 23 |
$ret[] = update_sql("ALTER TABLE {term_access} ADD grant_list smallint");
|
| 24 |
$ret[] = update_sql("ALTER TABLE {term_access} ALTER COLUMN grant_list SET DEFAULT '0'");
|
| 25 |
$ret[] = update_sql("ALTER TABLE {term_access} ALTER COLUMN grant_list SET NOT NULL ");
|
| 26 |
$ret[] = update_sql("UPDATE {term_access} SET grant_list = grant_view");
|
| 27 |
$ret[] = update_sql("ALTER TABLE {term_access_defaults} ADD grant_list smallint");
|
| 28 |
$ret[] = update_sql("ALTER TABLE {term_access_defaults} ALTER COLUMN grant_list SET DEFAULT '0");
|
| 29 |
$ret[] = update_sql("ALTER TABLE {term_access_defaults} ALTER COLUMN grant_list SET NOT NULL ");
|
| 30 |
$ret[] = update_sql("UPDATE {term_access_defaults} SET grant_list = grant_view");
|
| 31 |
}
|
| 32 |
break;
|
| 33 |
|
| 34 |
case 'mysql':
|
| 35 |
case 'mysqli':
|
| 36 |
// Checking if column 'grant_list' exists
|
| 37 |
if (db_result(db_query("DESC {term_access} 'grant_list'"))) {
|
| 38 |
drupal_set_message(t("Taxonomy Access - Update #2: No queries executed. Field 'grant_list' already exists in tables 'term_access'."), 'error');
|
| 39 |
$ret = array();
|
| 40 |
}
|
| 41 |
else {
|
| 42 |
$ret[] = update_sql("ALTER TABLE {term_access} ADD grant_list TINYINT(1) UNSIGNED DEFAULT '0' NOT NULL");
|
| 43 |
$ret[] = update_sql("UPDATE {term_access} SET grant_list = grant_view");
|
| 44 |
$ret[] = update_sql("ALTER TABLE {term_access_defaults} ADD grant_list TINYINT(1) UNSIGNED DEFAULT '0' NOT NULL");
|
| 45 |
$ret[] = update_sql("UPDATE {term_access_defaults} SET grant_list = grant_view");
|
| 46 |
}
|
| 47 |
break;
|
| 48 |
}
|
| 49 |
|
| 50 |
return $ret;
|
| 51 |
}
|
| 52 |
|
| 53 |
function taxonomy_access_update_3() {
|
| 54 |
// new module weights in core: put taxonomy_access to the bottom (but before the very last ones) in the chain.
|
| 55 |
$ret[] = update_sql("UPDATE {system} SET weight = 9 WHERE name = 'taxonomy_access'");
|
| 56 |
return $ret;
|
| 57 |
}
|
| 58 |
|
| 59 |
// Update#4: Delete variable 'taxonomy_access_enabled'
|
| 60 |
function taxonomy_access_update_4() {
|
| 61 |
variable_del('taxonomy_access_enabled');
|
| 62 |
return array();
|
| 63 |
}
|
| 64 |
|
| 65 |
// Update#5: Move global default records from term_access to term_access defaults
|
| 66 |
function taxonomy_access_update_5() {
|
| 67 |
$result = db_query('SELECT rid, grant_view, grant_update, grant_delete, grant_create, grant_list FROM {term_access} WHERE tid=0');
|
| 68 |
while ($row = db_fetch_array($result)) {
|
| 69 |
if ($row['rid'] > 0) { // just in case we have a weird row with 0, 0
|
| 70 |
db_query('INSERT INTO {term_access_defaults} (vid, rid, grant_view, grant_update, grant_delete, grant_create, grant_list) VALUES(0, %d, %d, %d, %d, %d, %d)', $row);
|
| 71 |
}
|
| 72 |
}
|
| 73 |
db_query('DELETE FROM {term_access} WHERE tid=0');
|
| 74 |
return array();
|
| 75 |
}
|
| 76 |
/**
|
| 77 |
* Implementation of hook_install.
|
| 78 |
* Adding tables to database: 'term_access', 'term_access_defaults'
|
| 79 |
*/
|
| 80 |
function taxonomy_access_install() {
|
| 81 |
switch ($GLOBALS['db_type']) {
|
| 82 |
case 'pgsql':
|
| 83 |
/*
|
| 84 |
* Not using pg_version() because it is only available in PHP 5 and with
|
| 85 |
* PostgreSQL library: 7.4. More importantly, the 'server_version'
|
| 86 |
* is missing, at least in PHP 5.1.2.
|
| 87 |
*/
|
| 88 |
$row = db_fetch_object(db_query('SELECT version() AS version'));
|
| 89 |
$version = preg_replace('/^[^0-9]+([^ ]+).*/i', '\\1', $row->version);
|
| 90 |
|
| 91 |
if (version_compare($version, '8.0', '<')) {
|
| 92 |
// PRIOR TO POSTGRESQL 8.0: making a BIT_OR aggregate function
|
| 93 |
db_query("CREATE AGGREGATE BIT_OR (
|
| 94 |
basetype = smallint,
|
| 95 |
sfunc = int2or,
|
| 96 |
stype = smallint
|
| 97 |
);");
|
| 98 |
}
|
| 99 |
|
| 100 |
db_query("CREATE TABLE {term_access} (
|
| 101 |
tid integer NOT NULL default '0',
|
| 102 |
rid integer NOT NULL default '0',
|
| 103 |
grant_view smallint NOT NULL default '0',
|
| 104 |
grant_update smallint NOT NULL default '0',
|
| 105 |
grant_delete smallint NOT NULL default '0',
|
| 106 |
grant_create smallint NOT NULL default '0',
|
| 107 |
grant_list smallint NOT NULL default '0',
|
| 108 |
PRIMARY KEY (tid,rid)
|
| 109 |
);");
|
| 110 |
|
| 111 |
db_query("CREATE TABLE {term_access_defaults} (
|
| 112 |
vid integer NOT NULL default '0',
|
| 113 |
rid integer NOT NULL default '0',
|
| 114 |
grant_view smallint NOT NULL default '0',
|
| 115 |
grant_update smallint NOT NULL default '0',
|
| 116 |
grant_delete smallint NOT NULL default '0',
|
| 117 |
grant_create smallint NOT NULL default '0',
|
| 118 |
grant_list smallint NOT NULL default '0',
|
| 119 |
PRIMARY KEY (vid,rid)
|
| 120 |
);");
|
| 121 |
|
| 122 |
// new module weights in core: put taxonomy_access to the bottom (but before the very last ones) in the chain.
|
| 123 |
db_query("UPDATE {system} SET weight = 9 WHERE name = 'taxonomy_access'");
|
| 124 |
|
| 125 |
// default global perms for roles 1 and 2
|
| 126 |
db_query('INSERT INTO {term_access_defaults} (vid, rid, grant_view, grant_update, grant_delete, grant_create, grant_list) VALUES(0, 1, 1, 0, 0, 1, 1)');
|
| 127 |
db_query('INSERT INTO {term_access_defaults} (vid, rid, grant_view, grant_update, grant_delete, grant_create, grant_list) VALUES(0, 2, 1, 0, 0, 1, 1)');
|
| 128 |
|
| 129 |
|
| 130 |
$success = TRUE;
|
| 131 |
break;
|
| 132 |
|
| 133 |
case 'mysql':
|
| 134 |
case 'mysqli':
|
| 135 |
|
| 136 |
db_query("CREATE TABLE {term_access} (
|
| 137 |
tid int(10) unsigned NOT NULL default '0',
|
| 138 |
rid int(10) unsigned NOT NULL default '0',
|
| 139 |
grant_view tinyint(1) unsigned NOT NULL default '0',
|
| 140 |
grant_update tinyint(1) unsigned NOT NULL default '0',
|
| 141 |
grant_delete tinyint(1) unsigned NOT NULL default '0',
|
| 142 |
grant_create tinyint(1) unsigned NOT NULL default '0',
|
| 143 |
grant_list tinyint(1) unsigned NOT NULL default '0',
|
| 144 |
PRIMARY KEY (tid,rid)
|
| 145 |
) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
|
| 146 |
|
| 147 |
db_query("CREATE TABLE {term_access_defaults} (
|
| 148 |
vid int(10) unsigned NOT NULL default '0',
|
| 149 |
rid int(10) unsigned NOT NULL default '0',
|
| 150 |
grant_view tinyint(1) unsigned NOT NULL default '0',
|
| 151 |
grant_update tinyint(1) unsigned NOT NULL default '0',
|
| 152 |
grant_delete tinyint(1) unsigned NOT NULL default '0',
|
| 153 |
grant_create tinyint(1) unsigned NOT NULL default '0',
|
| 154 |
grant_list tinyint(1) unsigned NOT NULL default '0',
|
| 155 |
PRIMARY KEY (vid,rid)
|
| 156 |
) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
|
| 157 |
|
| 158 |
// new module weights in core: put taxonomy_access to the bottom (but before the very last ones) in the chain.
|
| 159 |
db_query("UPDATE {system} SET weight = 9 WHERE name = 'taxonomy_access'");
|
| 160 |
|
| 161 |
// default global perms for roles 1 and 2
|
| 162 |
db_query('INSERT INTO {term_access_defaults} (vid, rid, grant_view, grant_update, grant_delete, grant_create, grant_list) VALUES(0, 1, 1, 0, 0, 1, 1)');
|
| 163 |
db_query('INSERT INTO {term_access_defaults} (vid, rid, grant_view, grant_update, grant_delete, grant_create, grant_list) VALUES(0, 2, 1, 0, 0, 1, 1)');
|
| 164 |
|
| 165 |
$success = TRUE;
|
| 166 |
break;
|
| 167 |
} // End case
|
| 168 |
|
| 169 |
// Notify of changes
|
| 170 |
if ($success) {
|
| 171 |
drupal_set_message(t('Taxonomy Access module installed tables successfully.'));
|
| 172 |
}
|
| 173 |
else {
|
| 174 |
drupal_set_message(t('The installation of Taxonomy Access module was unsuccessful.'), 'error');
|
| 175 |
}
|
| 176 |
}
|
| 177 |
|
| 178 |
function taxonomy_access_uninstall() {
|
| 179 |
db_query('DROP TABLE {term_access}');
|
| 180 |
db_query('DROP TABLE {term_access_defaults}');
|
| 181 |
//variable_del('taxonomy_access_enabled');
|
| 182 |
drupal_set_message(t('Taxonomy Access have been successfully uninstalled.'));
|
| 183 |
}
|