You are here

class TableComparison in Schema 8

Hierarchy

Expanded class hierarchy of TableComparison

3 files declare their use of TableComparison
SchemaComparisonInfoBuilder.php in src/Comparison/SchemaComparisonInfoBuilder.php
Contains Drupal\schema\Comparison\SchemaComparisonInfoBuilder.
SchemaMigrator.php in src/Migration/SchemaMigrator.php
Contains Drupal\schema\Migration\SchemaMigrator.
TableComparisonInfoBuilder.php in src/Comparison/TableComparisonInfoBuilder.php
Contains Drupal\schema\Comparison\TableComparisonInfoBuilder.

File

src/Comparison/Result/TableComparison.php, line 10
Contains Drupal\schema\Comparison\Result\TableComparison.

Namespace

Drupal\schema\Comparison\Result
View source
class TableComparison {
  const STATUS_SAME = 0;
  const STATUS_DIFFERENT = 1;
  protected $name;
  protected $schema;
  protected $table_comment_declared = FALSE;
  protected $table_comment_actual = FALSE;
  protected $fields_diff = array();
  protected $fields_extra = array();
  protected $fields_missing = array();
  protected $index_diff = array();
  protected $index_extra = array();
  protected $index_missing = array();
  protected $status = self::STATUS_SAME;
  public function __construct($name, $schema) {
    $this->name = $name;
    $this->schema = $schema;
  }
  public function getModule() {
    if (isset($this->schema['module'])) {
      return $this->schema['module'];
    }
    return 'unknown';
  }
  public function isTableCommentDifferent() {
    return $this
      ->getActualTableComment() != $this
      ->getDeclaredTableComment();
  }
  public function getActualTableComment() {
    return $this->table_comment_actual;
  }
  public function getDeclaredTableComment() {
    if (!$this->table_comment_declared) {
      $this->table_comment_declared = empty($this->schema['description']) ? FALSE : $this->schema['description'];
    }
    return $this->table_comment_declared;
  }
  public function setActualTableComment($value) {
    if (empty($value)) {
      $value = FALSE;
    }
    $this->table_comment_actual = $value;
  }
  public function setDeclaredTableComment($value) {
    if (empty($value)) {
      $value = FALSE;
    }
    $this->table_comment_declared = $value;
  }
  public function addMissingColumn($field, $definition) {
    $this->status = self::STATUS_DIFFERENT;
    $this->fields_missing[$field] = new MissingColumn($this
      ->getTableName(), $field, $definition);
  }
  public function getTableName() {
    return $this->name;
  }
  public function addExtraColumn($field, $schema) {
    $this->status = self::STATUS_DIFFERENT;
    $this->fields_extra[$field] = new ExtraColumn($this
      ->getTableName(), $field, $schema);
  }
  public function addColumnDifferences($field, $different_keys, $declared_schema, $actual_schema) {
    $this->status = self::STATUS_DIFFERENT;
    $this->fields_diff[$field] = new DifferentColumn($this
      ->getTableName(), $field, $different_keys, $declared_schema, $actual_schema);
  }
  public function addMissingPrimaryKey($definition) {
    $this
      ->addMissingIndex('PRIMARY', 'PRIMARY', $definition);
  }
  public function addMissingIndex($field, $type, $definition) {
    $this->status = self::STATUS_DIFFERENT;
    $this->index_missing[$field] = new MissingIndex($this
      ->getTableName(), $field, $type, $definition);
  }
  public function addExtraPrimaryKey($definition) {
    $this
      ->addExtraIndex('PRIMARY', 'PRIMARY', $definition);
  }
  public function addExtraIndex($field, $type, $schema) {
    $this->status = self::STATUS_DIFFERENT;

    // Other than for the primary key, this is not necessarily an error as the
    // dba might have added the index on purpose for performance reasons.
    $this->index_extra[$field] = new ExtraIndex($this
      ->getTableName(), $field, $type, $schema);
  }
  public function addPrimaryKeyDifference($declared, $actual) {
    $this
      ->addIndexDifferences('PRIMARY', 'PRIMARY', $declared, $actual);
  }
  public function addIndexDifferences($field, $type, $declared_schema, $actual_schema) {
    $this->status = self::STATUS_DIFFERENT;
    $this->index_diff[$field] = new DifferentIndex($this
      ->getTableName(), $field, $type, $declared_schema, $actual_schema);
  }
  public function isStatusSame() {
    return $this
      ->getStatus() == self::STATUS_SAME;
  }
  public function getStatus() {
    return $this->status;
  }
  public function isStatusDifferent() {
    return $this
      ->getStatus() == self::STATUS_DIFFERENT;
  }
  public function getDifferentColumns() {
    return $this->fields_diff;
  }
  public function getExtraColumns() {
    return $this->fields_extra;
  }
  public function getMissingColumns() {
    return $this->fields_missing;
  }
  public function getDeclaredPrimaryKey() {
    return isset($this->schema['primary key']) ? $this->schema['primary key'] : FALSE;
  }

  /**
   * Get all declared indexes for this table.
   *
   * @param bool $include_extra
   *   Also include extra indexes, i.e. indexes which are present in the
   *   database but missing from the declared schema.
   * @return array
   */
  public function getDeclaredIndexes($include_extra = FALSE) {
    $indexes = array(
      'indexes' => isset($this->schema['indexes']) ? $this->schema['indexes'] : array(),
      'unique keys' => isset($this->schema['unique keys']) ? $this->schema['unique keys'] : array(),
    );
    if ($include_extra) {

      /** @var ExtraIndex $index */
      foreach ($this
        ->getExtraIndexes() as $index) {
        $type = $index
          ->getType() == 'UNIQUE' ? 'unique keys' : 'indexes';
        $indexes[$type][$index
          ->getIndexName()] = $index
          ->getSchema();
      }
    }
    return $indexes;
  }
  public function getExtraIndexes() {
    return $this->index_extra;
  }
  public function getMissingIndexes() {
    return $this->index_missing;
  }
  public function getDifferentIndexes() {
    return $this->index_diff;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
TableComparison::$fields_diff protected property
TableComparison::$fields_extra protected property
TableComparison::$fields_missing protected property
TableComparison::$index_diff protected property
TableComparison::$index_extra protected property
TableComparison::$index_missing protected property
TableComparison::$name protected property
TableComparison::$schema protected property
TableComparison::$status protected property
TableComparison::$table_comment_actual protected property
TableComparison::$table_comment_declared protected property
TableComparison::addColumnDifferences public function
TableComparison::addExtraColumn public function
TableComparison::addExtraIndex public function
TableComparison::addExtraPrimaryKey public function
TableComparison::addIndexDifferences public function
TableComparison::addMissingColumn public function
TableComparison::addMissingIndex public function
TableComparison::addMissingPrimaryKey public function
TableComparison::addPrimaryKeyDifference public function
TableComparison::getActualTableComment public function
TableComparison::getDeclaredIndexes public function Get all declared indexes for this table.
TableComparison::getDeclaredPrimaryKey public function
TableComparison::getDeclaredTableComment public function
TableComparison::getDifferentColumns public function
TableComparison::getDifferentIndexes public function
TableComparison::getExtraColumns public function
TableComparison::getExtraIndexes public function
TableComparison::getMissingColumns public function
TableComparison::getMissingIndexes public function
TableComparison::getModule public function
TableComparison::getStatus public function
TableComparison::getTableName public function
TableComparison::isStatusDifferent public function
TableComparison::isStatusSame public function
TableComparison::isTableCommentDifferent public function
TableComparison::setActualTableComment public function
TableComparison::setDeclaredTableComment public function
TableComparison::STATUS_DIFFERENT constant
TableComparison::STATUS_SAME constant
TableComparison::__construct public function