I'm trying to write a module that update a cck field value, on nodeapi in $op(view)

the update goes fine, but it being cached or something, it is fine in database,
when I do Empty cache "with devel module", the changes happen to the node .

it is something like this :

function hook_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL){
switch($op){
case 'view':
$result = db_query("UPDATE `content_type_page` SET `field_viscount_value` = (`field_viscount_value`+1) WHERE `content_type_page`.`nid` = %d;", $node->nid);
break;
}
}

Thanks.

Comments

drupaul.z’s picture

add drupal_flush_all_caches(), if it not works, put your table to hook_flush_caches()

Eng_A_Moktar’s picture

Do I have to flush all cache ?

nevets’s picture

There is nothing in that snippet to suggest it would ever be reflected in the node, the code only updates a database table. Our you trying to track how many times the node has been viewed using one of it's own fields?

Eng_A_Moktar’s picture

I'm trying to track node views times, I've to use a cck field to store data there, so I can use it later with views, Please, don't suggest me another model, it has to be this way .
thanks

Eng_A_Moktar’s picture

not solved yet

petermilad’s picture

content_update($node);

OR

 /* this one works better for me than the first line, a fast way to clear the cache of your content by one node so you won't have to flush all the caches which is a bad way and makes your website not responding for a couple of seconds. 
 */
cache_clear_all('content:'. $node->nid .':'. $node->vid, content_cache_tablename());

Peter Aziz

Jaypan’s picture

As nevets said:

There is nothing in that snippet to suggest it would ever be reflected in the node

RoloDMonkey’s picture

Two things:

  1. Is there a reason why you don't want to use the Drupal core node_counter?
  2. You should always be careful when querying the content_type_* tables directly. If you have to do that, you should make sure that you are only updating the record with the correct version id (vid) and you might have to check access permissions by hand.

--

Read more at iRolo.net