Fastest Way To Batch Change Authors On Drupal 7

Step 1.

import ‘batch_change_content_author’ view from here, or cut and paste the code below. Required modules are Views and Views Bulk Operations:

$view = new view();
 $view->name = 'batch_change_content_author';
 $view->description = '';
 $view->tag = 'default';
 $view->base_table = 'node';
 $view->human_name = 'Batch change content author';
 $view->core = 7;
 $view->api_version = '3.0';
 $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
 /* Display: Master */
 $handler = $view->new_display('default', 'Master', 'default');
 $handler->display->display_options['title'] = 'Batch change content author';
 $handler->display->display_options['use_more_always'] = FALSE;
 $handler->display->display_options['access']['type'] = 'perm';
 $handler->display->display_options['cache']['type'] = 'none';
 $handler->display->display_options['query']['type'] = 'views_query';
 $handler->display->display_options['exposed_form']['type'] = 'basic';
 $handler->display->display_options['pager']['type'] = 'full';
 $handler->display->display_options['pager']['options']['items_per_page'] = '50';
 $handler->display->display_options['style_plugin'] = 'table';
 /* Relationship: Content: Author */
 $handler->display->display_options['relationships']['uid']['id'] = 'uid';
 $handler->display->display_options['relationships']['uid']['table'] = 'node';
 $handler->display->display_options['relationships']['uid']['field'] = 'uid';
 /* Field: Bulk operations: Content */
 $handler->display->display_options['fields']['views_bulk_operations_1']['id'] = 'views_bulk_operations_1';
 $handler->display->display_options['fields']['views_bulk_operations_1']['table'] = 'node';
 $handler->display->display_options['fields']['views_bulk_operations_1']['field'] = 'views_bulk_operations';
 $handler->display->display_options['fields']['views_bulk_operations_1']['label'] = '';
 $handler->display->display_options['fields']['views_bulk_operations_1']['element_label_colon'] = FALSE;
 $handler->display->display_options['fields']['views_bulk_operations_1']['vbo_settings']['display_type'] = '1';
 $handler->display->display_options['fields']['views_bulk_operations_1']['vbo_settings']['enable_select_all_pages'] = 1;
 $handler->display->display_options['fields']['views_bulk_operations_1']['vbo_settings']['force_single'] = 0;
 $handler->display->display_options['fields']['views_bulk_operations_1']['vbo_settings']['entity_load_capacity'] = '10';
 $handler->display->display_options['fields']['views_bulk_operations_1']['vbo_operations'] = array(
 'action::node_assign_owner_action' => array(
 'selected' => 1,
 'postpone_processing' => 0,
 'skip_confirmation' => 0,
 'override_label' => 0,
 'label' => '',
 ),
 'action::views_bulk_operations_delete_item' => array(
 'selected' => 0,
 'postpone_processing' => 0,
 'skip_confirmation' => 0,
 'override_label' => 0,
 'label' => '',
 ),
 'action::views_bulk_operations_delete_revision' => array(
 'selected' => 0,
 'postpone_processing' => 0,
 'skip_confirmation' => 0,
 'override_label' => 0,
 'label' => '',
 ),
 'action::views_bulk_operations_script_action' => array(
 'selected' => 0,
 'postpone_processing' => 0,
 'skip_confirmation' => 0,
 'override_label' => 0,
 'label' => '',
 ),
 'action::flag_node_action' => array(
 'selected' => 0,
 'postpone_processing' => 0,
 'skip_confirmation' => 0,
 'override_label' => 0,
 'label' => '',
 ),
 'action::node_make_sticky_action' => array(
 'selected' => 0,
 'postpone_processing' => 0,
 'skip_confirmation' => 0,
 'override_label' => 0,
 'label' => '',
 ),
 'action::node_make_unsticky_action' => array(
 'selected' => 0,
 'postpone_processing' => 0,
 'skip_confirmation' => 0,
 'override_label' => 0,
 'label' => '',
 ),
 'action::views_bulk_operations_modify_action' => array(
 'selected' => 0,
 'postpone_processing' => 0,
 'skip_confirmation' => 0,
 'override_label' => 0,
 'label' => '',
 'settings' => array(
 'show_all_tokens' => 1,
 'display_values' => array(
 '_all_' => '_all_',
 ),
 ),
 ),
 'action::views_bulk_operations_argument_selector_action' => array(
 'selected' => 0,
 'skip_confirmation' => 0,
 'override_label' => 0,
 'label' => '',
 'settings' => array(
 'url' => '',
 ),
 ),
 'action::node_promote_action' => array(
 'selected' => 0,
 'postpone_processing' => 0,
 'skip_confirmation' => 0,
 'override_label' => 0,
 'label' => '',
 ),
 'action::node_publish_action' => array(
 'selected' => 0,
 'postpone_processing' => 0,
 'skip_confirmation' => 0,
 'override_label' => 0,
 'label' => '',
 ),
 'action::node_unpromote_action' => array(
 'selected' => 0,
 'postpone_processing' => 0,
 'skip_confirmation' => 0,
 'override_label' => 0,
 'label' => '',
 ),
 'rules_component::scheduler_remove_publish_date_component' => array(
 'selected' => 0,
 'postpone_processing' => 0,
 'skip_confirmation' => 0,
 'override_label' => 0,
 'label' => '',
 ),
 'rules_component::scheduler_remove_unpublish_date_component' => array(
 'selected' => 0,
 'postpone_processing' => 0,
 'skip_confirmation' => 0,
 'override_label' => 0,
 'label' => '',
 ),
 'action::node_save_action' => array(
 'selected' => 0,
 'postpone_processing' => 0,
 'skip_confirmation' => 0,
 'override_label' => 0,
 'label' => '',
 ),
 'action::system_send_email_action' => array(
 'selected' => 0,
 'postpone_processing' => 0,
 'skip_confirmation' => 0,
 'override_label' => 0,
 'label' => '',
 ),
 'rules_component::scheduler_set_publish_date_component' => array(
 'selected' => 0,
 'postpone_processing' => 0,
 'skip_confirmation' => 0,
 'override_label' => 0,
 'label' => '',
 ),
 'rules_component::scheduler_set_unpublish_date_component' => array(
 'selected' => 0,
 'postpone_processing' => 0,
 'skip_confirmation' => 0,
 'override_label' => 0,
 'label' => '',
 ),
 'action::node_unpublish_action' => array(
 'selected' => 0,
 'postpone_processing' => 0,
 'skip_confirmation' => 0,
 'override_label' => 0,
 'label' => '',
 ),
 'action::node_unpublish_by_keyword_action' => array(
 'selected' => 0,
 'postpone_processing' => 0,
 'skip_confirmation' => 0,
 'override_label' => 0,
 'label' => '',
 ),
 'action::pathauto_node_update_action' => array(
 'selected' => 0,
 'postpone_processing' => 0,
 'skip_confirmation' => 0,
 'override_label' => 0,
 'label' => '',
 ),
 );
 /* Field: Content: Title */
 $handler->display->display_options['fields']['title']['id'] = 'title';
 $handler->display->display_options['fields']['title']['table'] = 'node';
 $handler->display->display_options['fields']['title']['field'] = 'title';
 $handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE;
 $handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;
 /* Field: User: Name */
 $handler->display->display_options['fields']['name']['id'] = 'name';
 $handler->display->display_options['fields']['name']['table'] = 'users';
 $handler->display->display_options['fields']['name']['field'] = 'name';
 $handler->display->display_options['fields']['name']['relationship'] = 'uid';
 $handler->display->display_options['fields']['name']['label'] = 'Current author';
 /* Sort criterion: Content: Post date */
 $handler->display->display_options['sorts']['created']['id'] = 'created';
 $handler->display->display_options['sorts']['created']['table'] = 'node';
 $handler->display->display_options['sorts']['created']['field'] = 'created';
 $handler->display->display_options['sorts']['created']['order'] = 'DESC';
 /* Filter criterion: Content: Published */
 $handler->display->display_options['filters']['status']['id'] = 'status';
 $handler->display->display_options['filters']['status']['table'] = 'node';
 $handler->display->display_options['filters']['status']['field'] = 'status';
 $handler->display->display_options['filters']['status']['value'] = 1;
 $handler->display->display_options['filters']['status']['group'] = 1;
 $handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
 /* Filter criterion: Content: Author uid */
 $handler->display->display_options['filters']['uid']['id'] = 'uid';
 $handler->display->display_options['filters']['uid']['table'] = 'node';
 $handler->display->display_options['filters']['uid']['field'] = 'uid';
 $handler->display->display_options['filters']['uid']['value'] = '';
 $handler->display->display_options['filters']['uid']['exposed'] = TRUE;
 $handler->display->display_options['filters']['uid']['expose']['operator_id'] = 'uid_op';
 $handler->display->display_options['filters']['uid']['expose']['label'] = 'Filter by author';
 $handler->display->display_options['filters']['uid']['expose']['operator'] = 'uid_op';
 $handler->display->display_options['filters']['uid']['expose']['identifier'] = 'uid';
 $handler->display->display_options['filters']['uid']['expose']['remember_roles'] = array(
 2 => '2',
 1 => 0,
 4 => 0,
 3 => 0,
 17 => 0,
 7 => 0,
 6 => 0,
 8 => 0,
 9 => 0,
 10 => 0,
 11 => 0,
 12 => 0,
 13 => 0,
 14 => 0,
 15 => 0,
 16 => 0,
 );
 /* Display: Page */
 $handler = $view->new_display('page', 'Page', 'page');
 $handler->display->display_options['path'] = 'admin/content/batch-change-author';
 $handler->display->display_options['menu']['type'] = 'normal';
 $handler->display->display_options['menu']['title'] = 'Batch change content author';
 $handler->display->display_options['menu']['name'] = 'management';
 $translatables['batch_change_content_author'] = array(
 t('Master'),
 t('Batch change content author'),
 t('more'),
 t('Apply'),
 t('Reset'),
 t('Sort by'),
 t('Asc'),
 t('Desc'),
 t('Items per page'),
 t('- All -'),
 t('Offset'),
 t('« first'),
 t('‹ previous'),
 t('next ›'),
 t('last »'),
 t('author'),
 t('- Choose an operation -'),
 t('Title'),
 t('Current author'),
 t('Filter by author'),
 t('Page'),
 );

To import a new view, go to ‘/admin/structure/views/import‘, enter any view name and paste the code above.

1

Once imported you will now have the new view.

2

Step 2.

Just visit the path indicated in the Page Settings, which would be admin/content/batch-change-author.

Step 3.

Perform the steps as needed to change the author of your content.

3z

Notes:

  • Views Bulk Operations (VBO) along with Views are required modules for above operation to work.
  • Changing authors en masse is a crucial step if you are removing users from your Drupal website. You can individually remove users via admin > People > Cancel > Delete, however that can be taxing if you are removing a lot of users.
  • Drush User Cancel (drush ucan) is a good alternative to removing users albeit one by one although it will not let you choose what will happen to orphaned nodes. By default any nodes authored by the canceled user will be changed to ‘anonymous’.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.