You are here

schema.install in Schema 8

Same filename and directory in other branches
  1. 5 schema.install
  2. 6 schema.install
  3. 7 schema.install

Install, update and uninstall functions for the schema module.

File

schema.install
View source
<?php

/**
 * @file
 * Install, update and uninstall functions for the schema module.
 */
use Drupal\Core\Url;

/**
 * Implementation of hook_requirements().
 */
function schema_requirements($phase) {
  $reqs = array();
  $t = 't';
  $schema_status_report = \Drupal::config('schema.settings')
    ->get('schema_status_report');
  if ($phase == 'runtime' && $schema_status_report) {

    // 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 modules with missing tables',
      ),
      'different' => array(
        REQUIREMENT_ERROR,
        'Inconsistent',
        '@count modules with mis-matching tables',
      ),
    );

    // Use first entry as default value.
    list($severity, $status, ) = extract(reset($checks));

    // Load and compare schema, then set requirement according to the results.
    $schema = schema_get_schema(TRUE);
    $info = schema_compare_schemas($schema);
    $notes = array();
    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 = array();

    // If there is only one note, it is for 'same'.
    if (count($notes) > 1) {
      $desc['notes_title'] = array(
        '#markup' => $t('The Schema comparison report shows: '),
      );
      $desc['notes'] = array(
        '#theme' => 'item_list',
        '#items' => $notes,
      );
    }
    if ($severity != REQUIREMENT_OK) {
      $sys_reqs = system_requirements($phase);
      if (isset($sys_reqs['update']['severity']) && $sys_reqs['update']['severity'] != REQUIREMENT_OK) {
        $help_text = $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::fromRoute('schema.compare')
            ->toString(),
        ));
      }
      else {
        $help_text = $t('The <a href="@compare">database schema comparison report</a> provides more details.', array(
          '@compare' => Url::fromRoute('schema.compare')
            ->toString(),
        ));
      }
      $desc['notes_help'] = array(
        '#markup' => $help_text,
      );
    }
    $reqs['schema'] = array(
      'title' => $t('Database schema'),
      'value' => $status,
      'severity' => $severity,
      'description' => $desc,
    );
  }
  return $reqs;
}

Functions

Namesort descending Description
schema_requirements Implementation of hook_requirements().