You are here

function schema_inspect in Schema 6

Same name and namespace in other branches
  1. 5 schema.module \schema_inspect()
  2. 7 schema.pages.inc \schema_inspect()

"Inspect" menu callback.

1 string reference to 'schema_inspect'
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 787
The Schema module provides functionality built on the Schema API.

Code

function schema_inspect() {
  $mods = module_list();
  sort($mods);
  $mods = array_flip($mods);
  $schema = drupal_get_schema(NULL, TRUE);
  $inspect = schema_invoke('inspect');
  foreach ($inspect as $name => $table) {
    $module = isset($schema[$name]['module']) ? $schema[$name]['module'] : 'Unknown';
    if (!isset($form[$module])) {
      $form[$module] = array(
        '#type' => 'fieldset',
        '#access' => TRUE,
        '#title' => check_plain($module),
        '#collapsible' => TRUE,
        '#collapsed' => $module != 'Unknown',
        '#weight' => $module == 'Unknown' ? 0 : $mods[$module] + 1,
        '#value' => '',
      );
    }
    if (isset($schema[$name]['module'])) {
      $form[$module][$name] = array(
        '#type' => 'markup',
        '#value' => '<textarea style="width:100%" rows="10">' . check_plain(schema_phpprint_table($name, $schema[$name])) . '</textarea>',
      );
    }
    else {
      $form[$module][$name] = array(
        '#type' => 'markup',
        '#value' => '<textarea style="width:100%" rows="10">' . check_plain(schema_phpprint_table($name, $inspect[$name])) . '</textarea>',
      );
    }
  }
  $output = <<<EOT
<p>This page shows the live database schema as it currently
exists on this system.  Known tables are grouped by the module that
defines them; unknown tables are all grouped together.</p>

<p>To implement hook_schema() for a module that has existing tables, copy
the schema structure for those tables directly into the module's
hook_schema() and return \$schema.</p>
EOT;
  $output .= drupal_render($form);
  return $output;
}