[development] Overriding node_db_rewrite_sql()

Ron Parker sysop at scbbs.com
Thu Jul 26 07:06:26 UTC 2007

Currently, I patch the node.module's node_db_rewrite_sql() function.  
What I would like to do is take this functionality and put it into a 
separate custom module so that I don't have to patch the core module.

I was advised to take the code, place it in my custom module, and weight 
my custom module heavier than the node module.  Tried that, but I'm 
getting some serious errors.

Here is essentially what I'm trying:  Taking the same 
node_db_rewrite_sql() code and placing it in my custom module:

function og_user_roles_db_rewrite_sql($query, $primary_table, 
$primary_field) {

    if ($primary_field == 'nid' && !node_access_view_all_nodes()) {
      $return['join'] = og_user_roles_node_access_join_sql($primary_table);
      $return['where'] = og_user_roles_node_access_where_sql();
      $return['distinct'] = 1;
      return $return;
function og_user_roles_node_access_join_sql($node_alias = 'n', 
$node_access_alias = 'naa') {
  if (user_access('administer nodes')) {
    return '';
     $return = 'INNER JOIN {node_access} '. $node_access_alias .' ON '. 
$node_access_alias .'.nid = '. $node_alias .'.nid ';
     ... my customizations follow ...

This actually appears to work for normal authenticated users.  However, 
user #1 is getting ALL nodes listed in every view everywhere. 

The second problem I've run into is that for certain users, they now get 
"access denied" error when trying to access content they should have 
access to.  It's like my permissions table got screwed up somehow, but I 
don't know how to fix it.

Help, please!


Ron Parker
Software Creations               http://www.scbbs.com
Self-Administration Web Site     http://saw.scbbs.com
SDSS Subscription Mgmt Service   http://sdss.scbbs.com
Central Ave Dance Ensemble       http://www.centralavedance.com
R & B Salsa                      http://www.randbsalsa.com

More information about the development mailing list