Something is wrong in the nodeapi hook when updating a node. Using the devel module I've seen the following query:

SELECT rid, BIT_OR(grant_view) AS grant_view, BIT_OR(grant_update) AS grant_update, BIT_OR(grant_delete) AS grant_delete FROM drupal_term_access WHERE tid IN ('Array') GROUP BY rid

Note te condition is wrong: IN ('Array'). This is build using the following code:

$result = db_query("SELECT rid, BIT_OR(grant_view) AS grant_view, BIT_OR(grant_update) AS grant_update, BIT_OR(grant_delete) AS grant_delete FROM {term_access} WHERE tid IN ('".implode("','",array_values($tids))."') GROUP BY rid");

So it seems array_values($tids) returns an Array? Not sure how, since $tids is defined a dew lines before from $node->taxonomy.

Sorry, I've been unable to see more than that.

Comments

markus_petrux’s picture

Looking at taxonomy_nodeapi, it calls the following when inserting/updating nodes:

taxonomy_node_save($node->nid, $node->taxonomy);

At the end of this function there is the following code snippet:

  if (is_array($terms)) {
    foreach ($terms as $term) {
      if (is_array($term)) {
        foreach ($term as $tid) {
          if ($tid) {
            db_query('INSERT INTO {term_node} (nid, tid) VALUES (%d, %d)', $nid, $tid);
          }
        }
      }
      else if ($term) {
        db_query('INSERT INTO {term_node} (nid, tid) VALUES (%d, %d)', $nid, $term);
      }
    }
  }

So, yes. It seems $node->taxonomy may be nothing, an array of integers, or an array of arrays of integers, which is the case that leads to the problem I'm having here.

markus_petrux’s picture

Status: Active » Reviewed & tested by the community
StatusFileSize
new1009 bytes

ok, I finally managed to find the fix. Please, see attached patch.

Cheers

markus_petrux’s picture

StatusFileSize
new1.37 KB

Updated the patch, to remove an unnecessary DELETE done at insert node time. Note that for updates, that exact same DELETE statement was already done.

keve’s picture

Status: Reviewed & tested by the community » Fixed
StatusFileSize
new1.88 KB

Many thanks for the patch.
This is a good catch. I might never notice this :)
I rather remove DELETE statement from 'update' nodeapi. Since there is a fallthrough from 'insert' to 'update', and it should be done in both cases.

I also put a check for is_array($node->taxonomy)

Anonymous’s picture

Status: Fixed » Closed (fixed)