0 AND ISNULL(td.tid)'); db_query('DELETE tad FROM {ogmy_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 {ogmy_term_access} ta LEFT JOIN {role} r ON ta.rid = r.rid WHERE ISNULL(r.rid)'); db_query('DELETE tad FROM {ogmy_term_access_defaults} tad LEFT JOIN {role} r ON tad.rid = r.rid WHERE ISNULL(r.rid)'); break; case 'pgsql': db_query('DELETE FROM {ogmy_term_access} ta LEFT JOIN {term_data} td ON ta.tid = td.tid WHERE ta.tid <> 0 AND ISNULL(td.tid)'); db_query('DELETE FROM {ogmy_term_access_defaults} tad LEFT JOIN {vocabulary} v ON tad.vid = v.vid WHERE tad.vid <> 0 AND ISNULL(v.vid)'); db_query('DELETE FROM {ogmy_term_access} ta LEFT JOIN {role} r ON ta.rid = r.rid WHERE ISNULL(r.rid)'); db_query('DELETE FROM {ogmy_term_access_defaults} tad LEFT JOIN {role} r ON tad.rid = r.rid WHERE ISNULL(r.rid)'); break; } node_access_rebuild(); } /** * Implementation of hook_taxonomy * Hook_taxonomy is called when changes are made to the taxonomy structure **/ function og_my_taxonomy($op, $type, $array = NULL) { if ($type == 'term') { switch ($op) { case 'delete': // delete everything from term_access and node_access // issue #167977 - klance $affected_nodes = _og_my_get_nodes_for_term($array['tid']); db_query('DELETE FROM {ogmy_term_access} WHERE tid = %d', $array['tid']); // issue #167977 - klance _og_my_node_access_update($affected_nodes); //node_access_rebuild(); break; } } if ($type == 'vocabulary') { switch ($op) { case 'delete': // delete vocabulary from table 'ogmy_term_access_defaults' // issue #167977 - klance $affected_nodes = _og_my_get_nodes_for_vocabulary($array['vid'], NULL); db_query('DELETE FROM {ogmy_term_access_defaults} WHERE vid = %d', $array['vid']); // issue #167977 - klance _og_my_node_access_update($affected_nodes); // TODO: need rebuild here? can we avoid multiple rebuilds on large vocab delete? break; } } return; } /** * Provide default values for term_access_defaults */ function _og_my_defaults($vid, $rid) { if ($rid == 1 || $rid == 2) return array($vid, $rid, 1, 0, 0, 1, 1); else return array($vid, $rid, 0, 0, 0, 0, 0); } /** * Implementation of hook_db_rewrite_sql() */ function og_my_db_rewrite_sql($query, $table, $field) { // se administrator, give all access if (!user_access('administer taxonomy') && ($field =='vid' || $field =='tid')) { global $user; $op = (arg(0) == 'node' && (arg(1) == 'add' || arg(2) == 'edit')) ? 'create' : 'list'; // let's cache static $og_my_sql_clause; $clause = array(); if (!isset($og_my_sql_clause)) { $og_my_sql_clause = array(); } if (!isset($og_my_sql_clause[$op][$field])) { if (isset($user) && is_array($user->roles)) { $rids = array_keys($user->roles); } else { $rids[] = 1; } $sql = db_query('SELECT t.tid AS tid, t.vid AS vid FROM {term_data} t INNER JOIN {ogmy_term_access_defaults} tdg ON tdg.vid=0 LEFT JOIN {ogmy_term_access_defaults} td ON td.vid=t.vid AND td.rid=tdg.rid LEFT JOIN {ogmy_term_access} ta ON ta.tid=t.tid AND ta.rid=tdg.rid WHERE tdg.rid IN ('. implode(',', $rids) .") GROUP BY t.tid, t.vid HAVING BIT_OR(COALESCE(ta.grant_$op, td.grant_$op, tdg.grant_$op)) > 0"); // issue #172675 - Ddaffyd // GROUP BY t.tid HAVING BIT_OR(COALESCE(ta.grant_$op, td.grant_$op, tdg.grant_$op))"); while ($result = db_fetch_object($sql)) { $tids[]= $result->tid; $vids[$result->vid]= $result->vid; } // Insert required vocabularies to avoid skipping of validation at node submission if ($op == 'create') { $sql = db_query('SELECT vid FROM {vocabulary} WHERE required = 1 OR tags = 1'); while ($row = db_fetch_array($sql)) { $vids[$row['vid']] = $row['vid']; } } $clause[$op]['tid'] = isset($tids) ? implode("','", $tids) : ''; $clause[$op]['vid'] = isset($vids) ? implode("','", $vids) : ''; $og_my_sql_clause = $clause; } else { $clause[$op][$field] = $og_my_sql_clause[$op][$field]; } $return['where'] = ($clause[$op][$field]) ? "$table.$field IN ('". $clause[$op][$field] ."')" : "$table.$field IS NULL"; return $return; } else { return array(); } }