You are here

function migrate_ui_migrate_dashboard in Migrate 7.2

Form for managing migration groups.

1 string reference to 'migrate_ui_migrate_dashboard'
migrate_ui_menu in migrate_ui/migrate_ui.module
Implementation of hook_menu().

File

migrate_ui/migrate_ui.pages.inc, line 10
Pages for managing migration processes.

Code

function migrate_ui_migrate_dashboard($form, &$form_state) {
  drupal_set_title(t('Migrate dashboard'));
  $build = array();
  $build['overview'] = array(
    '#prefix' => '<div>',
    '#markup' => filter_xss_admin(migrate_overview()),
    '#suffix' => '</div>',
  );
  $header = array(
    'machinename' => array(
      'data' => t('Group'),
    ),
    'status' => array(
      'data' => t('Status'),
    ),
    'source_system' => array(
      'data' => t('Source system'),
    ),
  );
  $result = db_select('migrate_group', 'mg')
    ->fields('mg', array(
    'name',
    'title',
    'arguments',
  ))
    ->execute();
  $rows = array();
  foreach ($result as $group_row) {
    $row = array();
    $migration_result = db_select('migrate_status', 'ms')
      ->fields('ms', array(
      'machine_name',
      'status',
      'arguments',
    ))
      ->condition('group_name', $group_row->name)
      ->execute();
    if (!$migration_result) {
      continue;
    }
    $status = t('Idle');
    $idle = TRUE;
    $machine_names = array();
    foreach ($migration_result as $migration_row) {
      switch ($migration_row->status) {
        case MigrationBase::STATUS_IMPORTING:
          $status = t('Importing');
          $idle = FALSE;
          break;
        case MigrationBase::STATUS_ROLLING_BACK:
          $status = t('Rolling back');
          $idle = FALSE;
          break;
        case MigrationBase::STATUS_STOPPING:
          $status = t('Stopping');
          $idle = FALSE;
          break;
      }
      $machine_names[] = $migration_row->machine_name;
    }

    // If we're not in the middle of an operaton, what's the status of the import?
    if ($idle) {
      $ready = TRUE;
      $complete = TRUE;
      foreach ($machine_names as $machine_name) {
        $migration = Migration::getInstance($machine_name);
        if (!$migration) {
          continue;
        }
        if (method_exists($migration, 'sourceCount') && method_exists($migration, 'processedCount')) {
          $source_count = $migration
            ->sourceCount();
          $processed_count = $migration
            ->processedCount();
          if ($processed_count > 0) {
            $ready = FALSE;
            if (!$complete) {
              break;
            }
          }
          if ($processed_count != $source_count) {
            $complete = FALSE;
            if (!$ready) {
              break;
            }
          }
        }
      }
      if ($ready) {
        $status = t('Ready to import');
      }
      elseif ($complete) {
        $status = t('Import complete');
      }
      else {
        $status = t('Import incomplete, not currently running');
      }
    }
    $row['status'] = $status;
    $row['machinename'] = l($group_row->title, 'admin/content/migrate/groups/' . $group_row->name);
    $arguments = unserialize($group_row->arguments);
    if (!empty($arguments['source_system'])) {
      $row['source_system'] = filter_xss_admin($arguments['source_system']);
    }
    else {
      $row['source_system'] = '';
    }
    $rows[$group_row->name] = $row;
  }
  $build['dashboard']['tasks'] = array(
    '#type' => 'tableselect',
    '#header' => $header,
    '#options' => $rows,
    '#tree' => TRUE,
    '#empty' => t('No migration groups defined.'),
  );
  $build['operations'] = _migrate_ui_migrate_operations();
  return $build;
}