Exception
2 years ago
Visitor
9 months ago
AbstractAsset.php
2 years ago
AbstractSchemaManager.php
9 months ago
Column.php
2 years ago
ColumnDiff.php
2 years ago
Comparator.php
2 years ago
Constraint.php
2 years ago
DB2SchemaManager.php
2 years ago
DefaultSchemaManagerFactory.php
2 years ago
ForeignKeyConstraint.php
9 months ago
Identifier.php
2 years ago
Index.php
2 years ago
LegacySchemaManagerFactory.php
2 years ago
MySQLSchemaManager.php
9 months ago
OracleSchemaManager.php
2 years ago
PostgreSQLSchemaManager.php
9 months ago
SQLServerSchemaManager.php
9 months ago
Schema.php
2 years ago
SchemaConfig.php
2 years ago
SchemaDiff.php
2 years ago
SchemaException.php
2 years ago
SchemaManagerFactory.php
2 years ago
Sequence.php
2 years ago
SqliteSchemaManager.php
8 months ago
Table.php
2 years ago
TableDiff.php
2 years ago
UniqueConstraint.php
2 years ago
View.php
2 years ago
SchemaDiff.php
117 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Doctrine\DBAL\Schema; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | use MailPoetVendor\Doctrine\DBAL\Platforms\AbstractPlatform; |
| 5 | use MailPoetVendor\Doctrine\Deprecations\Deprecation; |
| 6 | use function array_filter; |
| 7 | use function array_merge; |
| 8 | use function count; |
| 9 | class SchemaDiff |
| 10 | { |
| 11 | public $fromSchema; |
| 12 | public $newNamespaces = []; |
| 13 | public $removedNamespaces = []; |
| 14 | public $newTables = []; |
| 15 | public $changedTables = []; |
| 16 | public $removedTables = []; |
| 17 | public $newSequences = []; |
| 18 | public $changedSequences = []; |
| 19 | public $removedSequences = []; |
| 20 | public $orphanedForeignKeys = []; |
| 21 | public function __construct($newTables = [], $changedTables = [], $removedTables = [], ?Schema $fromSchema = null, $createdSchemas = [], $droppedSchemas = [], $createdSequences = [], $alteredSequences = [], $droppedSequences = []) |
| 22 | { |
| 23 | $this->newTables = $newTables; |
| 24 | $this->changedTables = array_filter($changedTables, static function (TableDiff $diff) : bool { |
| 25 | return !$diff->isEmpty(); |
| 26 | }); |
| 27 | $this->removedTables = $removedTables; |
| 28 | $this->fromSchema = $fromSchema; |
| 29 | $this->newNamespaces = $createdSchemas; |
| 30 | $this->removedNamespaces = $droppedSchemas; |
| 31 | $this->newSequences = $createdSequences; |
| 32 | $this->changedSequences = $alteredSequences; |
| 33 | $this->removedSequences = $droppedSequences; |
| 34 | } |
| 35 | public function getCreatedSchemas() : array |
| 36 | { |
| 37 | return $this->newNamespaces; |
| 38 | } |
| 39 | public function getDroppedSchemas() : array |
| 40 | { |
| 41 | return $this->removedNamespaces; |
| 42 | } |
| 43 | public function getCreatedTables() : array |
| 44 | { |
| 45 | return $this->newTables; |
| 46 | } |
| 47 | public function getAlteredTables() : array |
| 48 | { |
| 49 | return $this->changedTables; |
| 50 | } |
| 51 | public function getDroppedTables() : array |
| 52 | { |
| 53 | return $this->removedTables; |
| 54 | } |
| 55 | public function getCreatedSequences() : array |
| 56 | { |
| 57 | return $this->newSequences; |
| 58 | } |
| 59 | public function getAlteredSequences() : array |
| 60 | { |
| 61 | return $this->changedSequences; |
| 62 | } |
| 63 | public function getDroppedSequences() : array |
| 64 | { |
| 65 | return $this->removedSequences; |
| 66 | } |
| 67 | public function isEmpty() : bool |
| 68 | { |
| 69 | return count($this->newNamespaces) === 0 && count($this->removedNamespaces) === 0 && count($this->newTables) === 0 && count($this->changedTables) === 0 && count($this->removedTables) === 0 && count($this->newSequences) === 0 && count($this->changedSequences) === 0 && count($this->removedSequences) === 0; |
| 70 | } |
| 71 | public function toSaveSql(AbstractPlatform $platform) |
| 72 | { |
| 73 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5766', '%s is deprecated.', __METHOD__); |
| 74 | return $this->_toSql($platform, \true); |
| 75 | } |
| 76 | public function toSql(AbstractPlatform $platform) |
| 77 | { |
| 78 | Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5766', '%s is deprecated. Use AbstractPlatform::getAlterSchemaSQL() instead.', __METHOD__); |
| 79 | return $this->_toSql($platform, \false); |
| 80 | } |
| 81 | protected function _toSql(AbstractPlatform $platform, $saveMode = \false) |
| 82 | { |
| 83 | $sql = []; |
| 84 | if ($platform->supportsSchemas()) { |
| 85 | foreach ($this->getCreatedSchemas() as $schema) { |
| 86 | $sql[] = $platform->getCreateSchemaSQL($schema); |
| 87 | } |
| 88 | } |
| 89 | if ($platform->supportsForeignKeyConstraints() && $saveMode === \false) { |
| 90 | foreach ($this->orphanedForeignKeys as $orphanedForeignKey) { |
| 91 | $sql[] = $platform->getDropForeignKeySQL($orphanedForeignKey, $orphanedForeignKey->getLocalTable()); |
| 92 | } |
| 93 | } |
| 94 | if ($platform->supportsSequences() === \true) { |
| 95 | foreach ($this->getAlteredSequences() as $sequence) { |
| 96 | $sql[] = $platform->getAlterSequenceSQL($sequence); |
| 97 | } |
| 98 | if ($saveMode === \false) { |
| 99 | foreach ($this->getDroppedSequences() as $sequence) { |
| 100 | $sql[] = $platform->getDropSequenceSQL($sequence); |
| 101 | } |
| 102 | } |
| 103 | foreach ($this->getCreatedSequences() as $sequence) { |
| 104 | $sql[] = $platform->getCreateSequenceSQL($sequence); |
| 105 | } |
| 106 | } |
| 107 | $sql = array_merge($sql, $platform->getCreateTablesSQL($this->getCreatedTables())); |
| 108 | if ($saveMode === \false) { |
| 109 | $sql = array_merge($sql, $platform->getDropTablesSQL($this->getDroppedTables())); |
| 110 | } |
| 111 | foreach ($this->getAlteredTables() as $tableDiff) { |
| 112 | $sql = array_merge($sql, $platform->getAlterTableSQL($tableDiff)); |
| 113 | } |
| 114 | return $sql; |
| 115 | } |
| 116 | } |
| 117 |