Correct way to massively change node author I want to change all the nodes where $user1 is author and set $user2 as author.
I use this PHP Code and it works, but is it the correct way to do it?
Or should I use a batch process and load each node to change the author?

   $num_updated = db_update('node')
      -&gt;fields(array(
        'uid' =&gt; $user2-&gt;uid,
      ))
      -&gt;condition('uid', $user1-&gt;uid, '=')
      -&gt;execute();
It sounds like your Administering a Drupal site (not just a content moderator) -- but a site administration / developer.

Your code is fine. I recommend using Drush and calling your code as $ drush php-script massively-change-node-author.php from the command line. This way there is no timeout issues and you don't need to worry about using the Batch API and stuff like that.

Running code from php-script and drush performs a FULL BOOTSTRAP of drupal by default, and if needed you can pass a user argument to run the script as (faking a logged in user of $user) by using --user=1 for instance. For example: $ drush php-script --user=1 massively-change-node-author.php.

EDIT:

To avoid out-of-sync errors between node and node_revision table it's recommend to use node_load() and node_save() on the Nodes you want to update. Eg,

global $user;
foreach ($node_ids as $nid) {
  $node = node_load($nid);
  $node-&gt;uid = $user-&gt;uid;
  node_save($node);
}


Getting the list of node ids you want to affect, I leave as a task for you. The issues such as timeouts, using batch api etc -- are all still gone when using Drush. The logic is very similiar just using the better drupal API rather than direct database updates.