function taxonomy_access_enable in Taxonomy Access Control 6
Same name and namespace in other branches
- 5.2 taxonomy_access.module \taxonomy_access_enable()
- 5 taxonomy_access.module \taxonomy_access_enable()
- 7 taxonomy_access.install \taxonomy_access_enable()
Implements hook_enable().
Housekeeping: while we were away, did you delete any terms/vocabs/roles? 1: delete ta rows for missing terms 2: delete tad rows for missing vocabs 3: delete ta, tad rows for missing roles 4: rebuild node_access
File
- ./
taxonomy_access.module, line 46 - Allows administrators to specify how each category (in the taxonomy) can be used by various roles.
Code
function taxonomy_access_enable() {
global $db_type;
switch ($db_type) {
case 'mysql':
case 'mysqli':
/**
* @todo
* Test our PostgreSQL code with MySQL and replace this DB-specific
* code with it, if it works.
*/
db_query('DELETE ta FROM {term_access} ta LEFT JOIN {term_data} td ON ta.tid = td.tid WHERE ta.tid <> 0 AND ISNULL(td.tid)');
db_query('DELETE tad FROM {term_access_defaults} tad LEFT JOIN {vocabulary} v ON tad.vid = v.vid WHERE tad.vid <> 0 AND ISNULL(v.vid)');
db_query('DELETE ta FROM {term_access} ta LEFT JOIN {role} r ON ta.rid = r.rid WHERE ISNULL(r.rid)');
db_query('DELETE tad FROM {term_access_defaults} tad LEFT JOIN {role} r ON tad.rid = r.rid WHERE ISNULL(r.rid)');
break;
case 'pgsql':
$queries = array(
'tax' => "SELECT ta.tid,ta.rid FROM {term_access} ta LEFT JOIN {term_data} td ON ta.tid = td.tid WHERE ta.tid <> 0 AND td.tid IS NULL",
'tadx' => "SELECT tad.vid,tad.rid FROM {term_access_defaults} tad LEFT JOIN {vocabulary} v ON tad.vid = v.vid WHERE tad.vid <> 0 AND v.vid IS NULL",
'tar' => "SELECT ta.tid,ta.rid FROM {term_access} ta LEFT JOIN {role} r ON ta.rid = r.rid WHERE r.rid IS NULL",
'tadr' => "SELECT tad.vid,tad.rid FROM {term_access_defaults} tad LEFT JOIN {role} r ON tad.rid = r.rid WHERE r.rid IS NULL",
);
foreach ($queries as $type => $sql) {
$result = db_query($sql);
while ($args = db_fetch_array($result)) {
if ($args) {
if ($type == 'tax' || $type == 'tar') {
db_query("DELETE FROM {term_access} WHERE tid = %d AND rid = %d", $args);
}
else {
db_query("DELETE FROM {term_access_defaults} WHERE vid = %d AND rid = %d", $args);
}
}
}
}
break;
}
}