function taxonomy_access_install in Taxonomy Access Control 6
Same name and namespace in other branches
- 5.2 taxonomy_access.install \taxonomy_access_install()
- 5 taxonomy_access.install \taxonomy_access_install()
- 7 taxonomy_access.install \taxonomy_access_install()
Implements hook_install(). Adds tables to database: 'term_access', 'term_access_defaults'
File
- ./
taxonomy_access.install, line 50 - Install, update, and uninstall functions for Taxonomy Access Control.
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 );");
}
break;
}
// Use Schema API to install tables.
$status = drupal_install_schema('taxonomy_access');
// drupal_install_schema() returns an array of the results of each query;
// each entry includes 'status' which is 0 for failure or 1 for success.
$success = 1;
foreach ($status as $s) {
$success = $success * $s['success'];
}
// Default global perms for roles 1 (anonymous) and 2 (authenticated).
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, 0, 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, 0, 1)');
// Weight taxonomy_access below most modules, but above the very last ones.
db_query("UPDATE {system} SET weight = 9 WHERE name = 'taxonomy_access'");
// Notify user of status.
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');
}
}