You are here

function schema_requirements in Schema 6

Same name and namespace in other branches
  1. 8 schema.install \schema_requirements()
  2. 5 schema.install \schema_requirements()
  3. 7 schema.install \schema_requirements()

Implementation of hook_requirements(). Checks installation requirements and do status reporting.

Parameters

phase 'install': ignored (no installation requirements): 'runtime': status reporting for database

Return value

A keyed array of requirements

See also

schema_compare_schemas()

File

./schema.install, line 11

Code

function schema_requirements($phase) {
  $reqs = array();
  $t = get_t();
  if ($phase == 'runtime' && variable_get('schema_status_report', TRUE)) {
    $schema = drupal_get_schema(NULL, TRUE);
    $info = schema_compare_schemas($schema);

    // make sure these are defined in increasing-severity order
    $checks = array(
      'same' => array(
        REQUIREMENT_OK,
        'Consistent',
        '@count modules with matching tables',
      ),
      'extra' => array(
        REQUIREMENT_OK,
        'Extra tables',
        '@count extra tables',
      ),
      'warn' => array(
        REQUIREMENT_WARNING,
        'Warning',
        '@count warnings',
      ),
      'missing' => array(
        REQUIREMENT_ERROR,
        'Inconsistent',
        '@count module with missing tables',
      ),
      'different' => array(
        REQUIREMENT_ERROR,
        'Inconsistent',
        '@count module with mis-matching tables',
      ),
    );
    $notes = array();
    $severity = REQUIREMENT_OK;
    foreach ($checks as $key => $data) {
      if (!empty($info[$key])) {
        $severity = $data[0];
        $status = $data[1];
        $notes[] = $t($data[2], array(
          '@count' => count($info[$key]),
        ));
      }
    }
    $desc = '';

    // if there is only one note, it is for 'same'
    if (count($notes) > 1) {
      $desc = $t('The Schema comparison report shows: ') . theme('item_list', $notes);
    }
    if ($severity != REQUIREMENT_OK) {
      $sys_reqs = system_requirements($phase);
      if ($sys_reqs['update']['severity'] != REQUIREMENT_OK) {
        $desc .= $t('You should follow the instructions under <strong>@title</strong> now or run the <a href="@compare">database schema comparison report</a> for more details.', array(
          '@title' => $sys_reqs['update']['title'],
          '@compare' => url('admin/build/schema/compare'),
        ));
      }
      else {
        $desc .= $t('The <a href="@compare">database schema comparison report</a> provides more details.', array(
          '@compare' => url('admin/build/schema/compare'),
        ));
      }
    }
    $reqs['schema'] = array(
      'title' => $t('Database schema'),
      'value' => $status,
      'severity' => $severity,
      'description' => $desc,
    );
  }
  return $reqs;
}