I need to change the revison uid of 7000 nodes on a site. So I am using Views Bulk Operations to perform this action, by publishing or saving the the 7000 nodes concerned. Then I use the hook_node_presave to update all contents. But unfortunately, the field revision_uid isn't properly updated. By cons the field log is properly updated..

$field_uid = field_get_items('node', $node, 'uid');
         $node->log = $node->uid;        
         $node->revision_uid = $node->uid;

The revision id is still the one I'm using to make this operation (1 to admin..). How can get around this problem??

2 Answers 2


You'll have to impersonate a user while performing your operation:

//Save current user data/session
global $user;
$original_user = $user;
$old_state = drupal_save_session(FALSE);

$field_uid = field_get_items('node', $node, 'uid');
         // Load new $user data
         $user = user_load($node->uid);

         $node->log = $node->uid;        
         $node->revision_uid = $user->uid;

// Fail safe - if your code fails session won't be saved
$user = $original_user;
//Rever to old user and save session


  • Thank you for your response. It seems correct. But actually I haven't tested it, because I solved my problem my using direct db_update..
    – 118218
    Commented Sep 18, 2012 at 23:39

I was able to solve my problem by using a direct db_update, here is my simple code:

function hook_node_update($node) {

  $node->log = $node->uid;
  $node->revision_uid = $node->uid;

  $revision_uid_updated = db_update('node_revision')
    'uid' => $node->uid,
  ->condition('nid', $node->nid, '=')


With this, I was able to reassign the revision ownership to the author of each content

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.