You are here

function schema_report in Schema 6

Same name and namespace in other branches
  1. 5 schema.module \schema_report()

"Report" menu callback. This function just massages the data returned by schema_compare_schemas() into HTML.

1 string reference to 'schema_report'
schema_menu in ./schema.module
Implementation of hook_menu(). Define menu items and page callbacks. admin/build/schema calls local task(default): schema_report() admin/build/schema/report calls local task: schema_report() admin/build/schema/describe calls local task:…

File

./schema.module, line 687
The Schema module provides functionality built on the Schema API.

Code

function schema_report() {
  $states = array(
    'same' => t('Match'),
    'different' => t('Mismatch'),
    'missing' => t('Missing'),
    'extra' => t('Extra'),
  );
  $descs = array(
    'same' => 'Tables for which the schema and database agree.',
    'different' => 'Tables for which the schema and database are different.',
    'missing' => 'Tables in the schema that are not present in the database.',
    'extra' => 'Tables in the database that are not present in the schema.  This indicates previously installed modules that are disabled but not un-installed or modules that do not use the Schema API.',
  );
  $schema = drupal_get_schema(NULL, TRUE);
  $info = schema_compare_schemas($schema);
  foreach ($info as $state => $modules) {
    $counts[$state] = 0;
    $data[$state] = $state == 'extra' ? array() : '';
    if ($state == 'extra') {
      $data[$state] = array_merge($data[$state], $modules);
      $counts[$state] += count($modules);
      continue;
    }
    else {
      if ($state == 'warn') {
        foreach ($modules as $msg) {
          drupal_set_message($msg, 'warning');
        }
        continue;
      }
    }
    foreach ($modules as $module => $tables) {
      $counts[$state] += count($tables);
      switch ($state) {
        case 'same':
        case 'missing':
          $data[$state] .= theme('item_list', array_keys($tables), $module);
          break;
        case 'different':
          $items = array();
          foreach ($tables as $name => $stuff) {
            $items[] = "<h4>{$name}</h4>" . theme('item_list', array_merge($tables[$name]['reasons'], $tables[$name]['notes']));
          }
          $form = array();
          $form[$module] = array(
            '#type' => 'fieldset',
            '#title' => t($module),
            '#collapsible' => TRUE,
            '#collapsed' => TRUE,
            '#value' => '',
          );
          $form[$module]['content'] = array(
            '#value' => theme('item_list', $items),
          );
          $data[$state] .= drupal_render($form);
          break;
      }
    }
  }
  if (isset($data['extra'])) {
    $data['extra'] = theme('item_list', $data['extra']);
  }
  $form = array();
  $weight = 0;
  foreach ($states as $state => $content) {
    $content = isset($data[$state]) ? $data[$state] : '';
    $form[$state] = array(
      '#type' => 'fieldset',
      '#title' => t('@state (@count)', array(
        '@state' => $states[$state],
        '@count' => isset($counts[$state]) ? $counts[$state] : 0,
      )),
      '#description' => t($descs[$state]),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#weight' => $weight++,
      '#value' => '',
    );
    $form[$state]['content'] = array(
      '#type' => 'markup',
      '#value' => $content,
    );
  }
  $output = <<<EOT
<p>This page compares the live database as it currently exists against
the combination of all schema information provided by all enabled modules.</p>
EOT;
  $output .= drupal_render($form);
  return $output;
}