You are here

function drush_entityreference_migration_references in Reference to EntityReference Field Migration 7

Same name and namespace in other branches
  1. 7.2 entityreference_migration.drush.inc \drush_entityreference_migration_references()

Convert the references fields to entityreference.

1 string reference to 'drush_entityreference_migration_references'
entityreference_migration_drush_command in ./entityreference_migration.drush.inc
Implementation of hook_drush_command().

File

./entityreference_migration.drush.inc, line 34

Code

function drush_entityreference_migration_references($field_name = '') {
  $field_infos = array();

  // Read the singular field.
  if (!empty($field_name)) {
    $field_infos = field_read_fields(array(
      'field_name' => $field_name,
    ), array(
      'include_inactive' => TRUE,
      'include_deleted' => TRUE,
    ));
  }
  else {

    // Load all references fields.
    $node_field_infos = field_read_fields(array(
      'type' => 'node_reference',
    ), array(
      'include_inactive' => TRUE,
      'include_deleted' => TRUE,
    ));
    $user_field_infos = field_read_fields(array(
      'type' => 'user_reference',
    ), array(
      'include_inactive' => TRUE,
      'include_deleted' => TRUE,
    ));
    $field_infos = $node_field_infos + $user_field_infos;
  }
  $batch = array(
    'operations' => array(),
    'finished' => '_drush_entityreference_migration_batches_finished',
    'title' => dt('Start migrating reference fields.'),
    'init_message' => dt('Preparing to migrate reference fields.'),
    'progress_message' => dt('Migrating references fields.'),
    'error_message' => dt('Reference field could not migrate content successfully.'),
  );
  foreach ($field_infos as $key => $field_info) {
    $batch['operations'][] = array(
      '_drush_entityreference_migration_references_field',
      array(
        $key,
        $field_info,
      ),
    );
  }
  batch_set($batch);
  $batch =& batch_get();
  $batch['progressive'] = FALSE;
  drush_backend_batch_process();
}