You are here

function migrate_ui_messages in Migrate 6.2

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

Menu callback for messages page

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

File

migrate_ui/migrate_ui.pages.inc, line 411

Code

function migrate_ui_messages($migration) {
  drupal_add_css(drupal_get_path('module', 'migrate_ui') . '/migrate_ui.css');
  $build = $rows = array();
  $header = array(
    array(
      'data' => t('Source ID'),
      'field' => 'sourceid1',
      'sort' => 'asc',
    ),
    array(
      'data' => t('Level'),
      'field' => 'level',
    ),
    array(
      'data' => t('Message'),
      'field' => 'message',
    ),
  );
  if (is_string($migration)) {
    $migration = migration_load($migration);
  }

  // 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) {
    $class = $message->level <= MigrationBase::MESSAGE_WARNING ? 'migrate-error' : '';
    $rows[] = array(
      array(
        'data' => $message->sourceid1,
        'class' => $class,
      ),
      // TODO: deal with compound keys
      array(
        'data' => $migration
          ->getMessageLevelName($message->level),
        'class' => $class,
      ),
      array(
        'data' => $message->message,
        'class' => $class,
      ),
    );
    unset($classes);
  }
  $build['messages'] = array(
    '#prefix' => '<div>',
    '#value' => theme_table($header, $rows),
    '#suffix' => '</div>',
  );
  $build['migrate_ui_pager'] = array(
    '#theme' => 'pager',
  );
  return drupal_render($build);
}