You are here

public function TableComparisonInfoBuilder::getInfoArray in Schema 8

File

src/Comparison/TableComparisonInfoBuilder.php, line 25
Contains Drupal\schema\Comparison\TableComparisonInfoBuilder.

Class

TableComparisonInfoBuilder

Namespace

Drupal\schema\Comparison

Code

public function getInfoArray() {
  $reasons = array();
  $notes = array();
  if ($this->o
    ->isTableCommentDifferent()) {
    $reasons[] = array(
      '#markup' => 'Table comment is different.' . '<br/>declared: ' . $this->o
        ->getDeclaredTableComment() . '<br/>actual: ' . $this->o
        ->getActualTableComment(),
    );
  }

  /** @var MissingColumn $column */
  foreach ($this->o
    ->getMissingColumns() as $column) {
    $reasons[] = sprintf("%s: not in database", $column
      ->getColumnName());
  }

  /** @var DifferentColumn $column */
  foreach ($this->o
    ->getDifferentColumns() as $column) {
    $colname = $column
      ->getColumnName();
    $kdiffs = $column
      ->getDifferentKeys();
    $reasons[] = array(
      '#markup' => "column {$colname} - difference" . (count($kdiffs) > 1 ? 's' : '') . " on: " . implode(', ', $kdiffs) . "<br/>declared: " . schema_phpprint_column($column
        ->getDeclaredSchema()) . '<br/>actual: ' . schema_phpprint_column($column
        ->getActualSchema()),
    );
  }

  /** @var ExtraColumn $column */
  foreach ($this->o
    ->getExtraColumns() as $column) {
    $reasons[] = sprintf("%s: unexpected column in database", $column
      ->getColumnName());
  }

  /** @var MissingIndex $index */
  foreach ($this->o
    ->getMissingIndexes() as $index) {
    $keyname = $index
      ->getIndexName();
    $type = $index
      ->getType();
    if ($index
      ->isPrimary()) {
      $reasons[] = "primary key: missing in database";
    }
    else {
      $reasons[] = "{$type} {$keyname}: missing in database";
    }
  }

  /** @var DifferentIndex $index */
  foreach ($this->o
    ->getDifferentIndexes() as $index) {
    $type = $index
      ->getType();
    $keyname = $index
      ->getIndexName();
    if ($index
      ->isPrimary()) {
      $reasons[] = array(
        '#markup' => "{$type} {$keyname}:<br />declared: " . schema_phpprint_key($index
          ->getDeclaredSchema()) . '<br />actual: ' . schema_phpprint_key($index
          ->getActualSchema()),
      );
    }
    else {
      $reasons[] = array(
        '#markup' => "primary key:<br />declared: " . schema_phpprint_key($index
          ->getDeclaredSchema()) . '<br />actual: ' . schema_phpprint_key($index
          ->getActualSchema()),
      );
    }
  }

  /** @var ExtraIndex $index */
  foreach ($this->o
    ->getExtraIndexes() as $index) {
    $keyname = $index
      ->getIndexName();
    $type = $index
      ->getType();
    if ($index
      ->isPrimary()) {
      $reasons[] = "primary key: missing in schema";
    }
    else {
      $notes[] = "{$type} {$keyname}: unexpected (not an error)";
    }
  }
  return array(
    'status' => $this->o
      ->isStatusDifferent() ? "different" : "same",
    'reasons' => $reasons,
    'notes' => $notes,
  );
}