You are here

function schema_requirements in Schema 5

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

File

./schema.install, line 3

Code

function schema_requirements($phase) {
  $reqs = array();
  $t = get_t();
  if ($phase == 'runtime') {
    $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;
}