Drupal 8 - Changing the Author for a Node

The Drupal 8 Views Bulk Operations plugin is still in development at the time of this article.

Option 1: Use Actions Module

This approach updates the author on the node but not on revisions.  Inspect the database node_field_data table and uid column to get a better idea of what it does.

  1. Enable Actions core module using "Extend" admin option (admin/modules)
  2. From /admin/config/system/actions,  Select "Change the author of content" from the "Create an Advanced Action" dropdown (at bottom of page) and press "Create"
  3. Configure the new change author action by setting the new author in the Username field.
  4. From /admin/content, select the nodes to update after choosing "Change the author of content" in the bulk action dropdown.
  5. Click "Apply to selected items"

Option 2: MySQL (command line)

Updating the database directly allows you to update history so things like "submitted by" show new author.  Note that I did not research all the database relationships but it worked for me and the modules I have installed. ***NOT FOR PRODUCTION*** Do not try this unless you have a good understanding of queries and updates

  1. Log in to database and query for the author name and uid values.  In my case it is in a docker container...
    # this is Docker specific (just use ssh on a normal server)
    docker ps
    ubuntu@ec2:~$ docker exec -it drupal8_mysql_1 /bin/bash
    
    # Connect to mysql using same user as configured in drupal 
    root@08f9c5f267a2:/# mysql -u drupal -p
    Enter password:
    MariaDB [(none)]> use drupal;
    MariaDB [drupal]> select name, uid from users_field_data;
    
  2. Query for revisions based on the old author UID from step 1
    desc node_field_revision;
    desc node_field_data;
    
    -- In my case, I am changing drupaladmin (uid=1) to a user with uid=8
    select nfr.nid, nfr.vid, nfr.title, nfd.type, nfr.uid from node_field_revision nfr, node_field_data nfd where nfr.uid = nfd.uid and nfd.uid = 1;  
    
  3. Update specific revisions and nodes based on prior query. This example will update all revisions matching a specific title. You could add "and nfr.vid = {specific revision #}" if you only wanted to update a single revision
    -- New user id is 8 in example below
    update node_field_revision set uid = 8 where title like 'Ubuntu Dynamic%';
    update node_field_data set uid = 8 where title like 'Ubuntu Dynamic%';
  4. Also update node_revison uid
    select nr.nid, nr.vid, nfr.title, nfr.uid from node_revision nr, node_field_revision nfr where nr.revision_uid = nfr.uid and nr.vid = nfr.vid and nfr.uid = 1 and nfr.title like 'Ubuntu Dynamic%';
    update node_revision nr inner join node_field_revision nfr on nr.revision_uid = nfr.uid and nr.vid = nfr.vid and nfr.uid = 1 and nfr.title like 'Ubuntu Dynamic%' set nr.revision_uid = 8;
  5. From /admin/config/development/performance,  "Clear all caches" and inspect some pages.
Tags