function taxonomy_access_install in Taxonomy Access Control 5.2
Same name and namespace in other branches
- 5 taxonomy_access.install \taxonomy_access_install()
- 6 taxonomy_access.install \taxonomy_access_install()
- 7 taxonomy_access.install \taxonomy_access_install()
Implementation of hook_install. Adding tables to database: 'term_access', 'term_access_defaults'
File
- ./
taxonomy_access.install, line 79
Code
function taxonomy_access_install() {
switch ($GLOBALS['db_type']) {
case 'pgsql':
/*
* Not using pg_version() because it is only available in PHP 5 and with
* PostgreSQL library: 7.4. More importantly, the 'server_version'
* is missing, at least in PHP 5.1.2.
*/
$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', '<')) {
// PRIOR TO POSTGRESQL 8.0: making a BIT_OR aggregate function
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 );");
// new module weights in core: put taxonomy_access to the bottom (but before the very last ones) in the chain.
db_query("UPDATE {system} SET weight = 9 WHERE name = 'taxonomy_access'");
// default global perms for roles 1 and 2
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 */;");
// new module weights in core: put taxonomy_access to the bottom (but before the very last ones) in the chain.
db_query("UPDATE {system} SET weight = 9 WHERE name = 'taxonomy_access'");
// default global perms for roles 1 and 2
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;
}
// End case
// Notify of changes
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');
}
}