hook_after_update() work around

hook_after_update() work around

The Drupal node hooks does not include an after_update like the user hooks do. This would be handy, particularly given that the hook_update and hook_insert call your custom hooks before the node is written to the database. There is a work around. It is a bit hackish but it works. You can put in the hook_load() hook a check to see if the user matches the node owner and then implement what you would need to go into the after_update. The only real draw back to this approach is that it may be a little hard to find and might need extra processing since it is run anytime a node user is viewing that node type.

example

function example_load($node) { $ret = db_fetch_object(db_query('SELECT * FROM {example} WHERE vid = %d',$node->vid)); global $user; if($user->uid == $node->uid) { static $filepath; if(!$filepath) { $sql = 'SELECT filepath FROM {files} WHERE nid=%d'; $filepath = db_result(db_query($sql,$node->nid)); if($filepath != $user->picture) { $sql = 'UPDATE {users} SET picture="'.$filepath.'" WHERE uid='.$node->uid; db_query($sql); } } } return $ret; }

Related Posts

The Do's and Don't's of Emailing at Work

Kristin Yang
Read more

Work Smarter, Not Harder to Link Build

Erin Tuohy
Read more

Twitter Recap of our Webinar: Work Smarter & Get Results: Introducing Open Enterprise Intel™

Felipa Villegas
Read more

Build a Positive Team Environment while Increasing Work Output

Erin Tuohy
Read more

Apps: Making Drupal Distributions Work

Tom McCracken
Read more

10 Ways to Use Body Language to be a Rock Star at Work (or Anywhere Else)

Kristin Yang
Read more