Programically update node when visited by 'editor' role My goal is to have promote-node-when-visited-by-editor feature. This is code from MYMODULE using hook_node_view:

function MYMODULE_node_view($node, $view_mode, $langcode) {
    // 'promote-node-when-visited-by-editor' (roles[6]) feature
    if ($node-&gt;type == 'blog') {
        if (empty($node-&gt;promote)) {
            if ($view_mode == 'full') {
                global $user;
                if (isset($user-&gt;roles[6])) {
                    $node_data = node_load($node-&gt;nid);
                    $node_data-&gt;promote = '1';
                    node_save($node_data);
                }
            }
        }
    }
}


When all IFs are met, I get this error in execution part with hook_node_view:

Recoverable fatal error: Argument 1 passed to drupal_attributes()
must be of the type array, null given, called in /includes/common.inc
on line 2534 and defined in drupal_attributes() (line 2426
of /includes/common.inc).


What's the right hook when I want programically update node when (after, right before...) visited by editor role. For example rules have content is viewed event.
I have replaced these 3 lines 

            $node_data = node_load($node-&gt;nid);
            $node_data-&gt;promote = '1';
            node_save($node_data);


with

            db_update('node')
                    -&gt;fields(array(
                        'promote' =&gt; '1',
                    ))
                    -&gt;condition('nid', $node-&gt;nid)
                    -&gt;execute();
            db_update('node_revision')
                    -&gt;fields(array(
                        'promote' =&gt; '1',
                    ))
                    -&gt;condition('nid', $node-&gt;nid)
                    -&gt;execute();
            db_query('DELETE FROM cache_entity_node WHERE cache_entity_node.cid = :nid', array ( ':nid' =&gt; $node-&gt;nid));


and it seems working :)