You are here

function migrate_ui_messages in Migrate 7.2

Same name and namespace in other branches
  1. 6.2 migrate_ui/migrate_ui.pages.inc \migrate_ui_messages()

Menu callback for messages page

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

File

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

Code

function migrate_ui_messages($group_name, $migration_name) {
  drupal_set_title(t('Import messages for !migration', array(
    '!migration' => $migration_name,
  )));
  $build = $rows = array();
  $migration = Migration::getInstance($migration_name);
  if (!$migration) {
    return $build;
  }
  $source_key = $migration
    ->getMap()
    ->getSourceKey();
  $source_key_map = $migration
    ->getMap()
    ->getSourceKeyMap();
  $source_key_map_flipped = array_flip($source_key_map);
  $header = array();

  // Add a table header for each source key in the migration's map.
  foreach ($source_key as $key => $map_info) {
    $header[] = array(
      'data' => isset($map_info['description']) ? filter_xss_admin($map_info['description']) : t('Source ID'),
      'field' => $source_key_map[$key],
      'sort' => 'asc',
    );
  }
  $header[] = array(
    'data' => t('Level'),
    'field' => 'level',
  );
  $header[] = array(
    'data' => t('Message'),
    'field' => 'message',
  );

  // TODO: need a general MigrateMap API
  $messages = $migration
    ->getMap()
    ->getConnection()
    ->select($migration
    ->getMap()
    ->getMessageTable(), 'msg')
    ->extend('PagerDefault')
    ->extend('TableSort')
    ->orderByHeader($header)
    ->limit(500)
    ->fields('msg')
    ->execute();
  foreach ($messages as $message) {
    $classes[] = $message->level <= MigrationBase::MESSAGE_WARNING ? 'migrate-error' : '';
    $row = array();

    // Add a table column for each source key.
    foreach ($source_key_map_flipped as $source_key => $source_field) {
      $row[] = array(
        'data' => filter_xss_admin($message->{$source_key}),
        'class' => $classes,
      );
    }
    $row[] = array(
      'data' => filter_xss_admin($migration
        ->getMessageLevelName($message->level)),
      'class' => $classes,
    );
    $row[] = array(
      'data' => filter_xss_admin($message->message),
      'class' => $classes,
    );
    $rows[] = $row;
    unset($classes);
  }
  $build['messages'] = array(
    '#theme' => 'table',
    '#header' => $header,
    '#rows' => $rows,
    '#empty' => t('No messages'),
    '#attached' => array(
      'css' => array(
        drupal_get_path('module', 'migrate_ui') . '/migrate_ui.css',
      ),
    ),
  );
  $build['migrate_ui_pager'] = array(
    '#theme' => 'pager',
  );
  return $build;
}