View source
<?php
function taxonomy_access_update_1() {
return _system_update_utf8(array(
'term_access',
'term_access_defaults',
));
}
function taxonomy_access_update_2() {
switch ($GLOBALS['db_type']) {
case 'pgsql':
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'"))) {
drupal_set_message(t("Taxonomy Access - Update #2: No queries executed. Field 'grant_list' already exists in tables 'term_access'."), 'error');
$ret = array();
}
else {
$ret[] = update_sql("ALTER TABLE {term_access} ADD grant_list smallint");
$ret[] = update_sql("ALTER TABLE {term_access} ALTER COLUMN grant_list SET DEFAULT '0'");
$ret[] = update_sql("ALTER TABLE {term_access} ALTER COLUMN grant_list SET NOT NULL ");
$ret[] = update_sql("UPDATE {term_access} SET grant_list = grant_view");
$ret[] = update_sql("ALTER TABLE {term_access_defaults} ADD grant_list smallint");
$ret[] = update_sql("ALTER TABLE {term_access_defaults} ALTER COLUMN grant_list SET DEFAULT '0");
$ret[] = update_sql("ALTER TABLE {term_access_defaults} ALTER COLUMN grant_list SET NOT NULL ");
$ret[] = update_sql("UPDATE {term_access_defaults} SET grant_list = grant_view");
}
break;
case 'mysql':
case 'mysqli':
if (db_result(db_query("DESC {term_access} 'grant_list'"))) {
drupal_set_message(t("Taxonomy Access - Update #2: No queries executed. Field 'grant_list' already exists in tables 'term_access'."), 'error');
$ret = array();
}
else {
$ret[] = update_sql("ALTER TABLE {term_access} ADD grant_list TINYINT(1) UNSIGNED DEFAULT '0' NOT NULL");
$ret[] = update_sql("UPDATE {term_access} SET grant_list = grant_view");
$ret[] = update_sql("ALTER TABLE {term_access_defaults} ADD grant_list TINYINT(1) UNSIGNED DEFAULT '0' NOT NULL");
$ret[] = update_sql("UPDATE {term_access_defaults} SET grant_list = grant_view");
}
break;
}
return $ret;
}
function taxonomy_access_update_3() {
$ret[] = update_sql("UPDATE {system} SET weight = 9 WHERE name = 'taxonomy_access'");
return $ret;
}
function taxonomy_access_update_4() {
variable_del('taxonomy_access_enabled');
return array();
}
function taxonomy_access_update_5() {
$result = db_query('SELECT rid, grant_view, grant_update, grant_delete, grant_create, grant_list FROM {term_access} WHERE tid=0');
while ($row = db_fetch_array($result)) {
if ($row['rid'] > 0) {
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);
}
}
db_query('DELETE FROM {term_access} WHERE tid=0');
return array();
}
function taxonomy_access_install() {
switch ($GLOBALS['db_type']) {
case 'pgsql':
$row = db_fetch_object(db_query('SELECT version() AS version'));
$version = preg_replace('/^[^0-9]+([^ ]+).*/i', '\\1', $row->version);
if (version_compare($version, '8.0', '<')) {
db_query("CREATE AGGREGATE BIT_OR (\n basetype = smallint,\n sfunc = int2or,\n stype = smallint\n );");
}
db_query("CREATE TABLE {term_access} (\n tid integer NOT NULL default '0',\n rid integer NOT NULL default '0',\n grant_view smallint NOT NULL default '0',\n grant_update smallint NOT NULL default '0',\n grant_delete smallint NOT NULL default '0',\n grant_create smallint NOT NULL default '0',\n grant_list smallint NOT NULL default '0',\n PRIMARY KEY (tid,rid)\n );");
db_query("CREATE TABLE {term_access_defaults} (\n vid integer NOT NULL default '0',\n rid integer NOT NULL default '0',\n grant_view smallint NOT NULL default '0',\n grant_update smallint NOT NULL default '0',\n grant_delete smallint NOT NULL default '0',\n grant_create smallint NOT NULL default '0',\n grant_list smallint NOT NULL default '0',\n PRIMARY KEY (vid,rid)\n );");
db_query("UPDATE {system} SET weight = 9 WHERE name = 'taxonomy_access'");
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)');
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)');
$success = TRUE;
break;
case 'mysql':
case 'mysqli':
db_query("CREATE TABLE {term_access} (\n tid int(10) unsigned NOT NULL default '0',\n rid int(10) unsigned NOT NULL default '0',\n grant_view tinyint(1) unsigned NOT NULL default '0',\n grant_update tinyint(1) unsigned NOT NULL default '0',\n grant_delete tinyint(1) unsigned NOT NULL default '0',\n grant_create tinyint(1) unsigned NOT NULL default '0',\n grant_list tinyint(1) unsigned NOT NULL default '0',\n PRIMARY KEY (tid,rid)\n ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
db_query("CREATE TABLE {term_access_defaults} (\n vid int(10) unsigned NOT NULL default '0',\n rid int(10) unsigned NOT NULL default '0',\n grant_view tinyint(1) unsigned NOT NULL default '0',\n grant_update tinyint(1) unsigned NOT NULL default '0',\n grant_delete tinyint(1) unsigned NOT NULL default '0',\n grant_create tinyint(1) unsigned NOT NULL default '0',\n grant_list tinyint(1) unsigned NOT NULL default '0',\n PRIMARY KEY (vid,rid)\n ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
db_query("UPDATE {system} SET weight = 9 WHERE name = 'taxonomy_access'");
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)');
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)');
$success = TRUE;
break;
}
if ($success) {
drupal_set_message(t('Taxonomy Access module installed tables successfully.'));
}
else {
drupal_set_message(t('The installation of Taxonomy Access module was unsuccessful.'), 'error');
}
}
function taxonomy_access_uninstall() {
db_query('DROP TABLE {term_access}');
db_query('DROP TABLE {term_access_defaults}');
drupal_set_message(t('Taxonomy Access have been successfully uninstalled.'));
}