AbstractVisitor.php
2 years ago
CreateSchemaSqlCollector.php
2 years ago
DropSchemaSqlCollector.php
9 months ago
Graphviz.php
2 years ago
NamespaceVisitor.php
2 years ago
RemoveNamespacedAssets.php
2 years ago
Visitor.php
2 years ago
index.php
2 years ago
RemoveNamespacedAssets.php
59 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Doctrine\DBAL\Schema\Visitor; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | use MailPoetVendor\Doctrine\DBAL\Schema\ForeignKeyConstraint; |
| 5 | use MailPoetVendor\Doctrine\DBAL\Schema\Schema; |
| 6 | use MailPoetVendor\Doctrine\DBAL\Schema\Sequence; |
| 7 | use MailPoetVendor\Doctrine\DBAL\Schema\Table; |
| 8 | use MailPoetVendor\Doctrine\Deprecations\Deprecation; |
| 9 | class RemoveNamespacedAssets extends AbstractVisitor |
| 10 | { |
| 11 | private ?Schema $schema = null; |
| 12 | public function __construct() |
| 13 | { |
| 14 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5432', 'RemoveNamespacedAssets is deprecated. Do not use namespaces' . " if the target database platform doesn't support them."); |
| 15 | } |
| 16 | public function acceptSchema(Schema $schema) |
| 17 | { |
| 18 | $this->schema = $schema; |
| 19 | } |
| 20 | public function acceptTable(Table $table) |
| 21 | { |
| 22 | if ($this->schema === null) { |
| 23 | return; |
| 24 | } |
| 25 | if ($table->isInDefaultNamespace($this->schema->getName())) { |
| 26 | return; |
| 27 | } |
| 28 | $this->schema->dropTable($table->getName()); |
| 29 | } |
| 30 | public function acceptSequence(Sequence $sequence) |
| 31 | { |
| 32 | if ($this->schema === null) { |
| 33 | return; |
| 34 | } |
| 35 | if ($sequence->isInDefaultNamespace($this->schema->getName())) { |
| 36 | return; |
| 37 | } |
| 38 | $this->schema->dropSequence($sequence->getName()); |
| 39 | } |
| 40 | public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint) |
| 41 | { |
| 42 | if ($this->schema === null) { |
| 43 | return; |
| 44 | } |
| 45 | // The table may already be deleted in a previous |
| 46 | // RemoveNamespacedAssets#acceptTable call. Removing Foreign keys that |
| 47 | // point to nowhere. |
| 48 | if (!$this->schema->hasTable($fkConstraint->getForeignTableName())) { |
| 49 | $localTable->removeForeignKey($fkConstraint->getName()); |
| 50 | return; |
| 51 | } |
| 52 | $foreignTable = $this->schema->getTable($fkConstraint->getForeignTableName()); |
| 53 | if ($foreignTable->isInDefaultNamespace($this->schema->getName())) { |
| 54 | return; |
| 55 | } |
| 56 | $localTable->removeForeignKey($fkConstraint->getName()); |
| 57 | } |
| 58 | } |
| 59 |