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
DropSchemaSqlCollector.php
69 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Doctrine\DBAL\Schema\Visitor; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | use MailPoetVendor\Doctrine\DBAL\Platforms\AbstractPlatform; |
| 5 | use MailPoetVendor\Doctrine\DBAL\Schema\ForeignKeyConstraint; |
| 6 | use MailPoetVendor\Doctrine\DBAL\Schema\SchemaException; |
| 7 | use MailPoetVendor\Doctrine\DBAL\Schema\Sequence; |
| 8 | use MailPoetVendor\Doctrine\DBAL\Schema\Table; |
| 9 | use MailPoetVendor\Doctrine\Deprecations\Deprecation; |
| 10 | use SplObjectStorage; |
| 11 | use function assert; |
| 12 | use function strlen; |
| 13 | class DropSchemaSqlCollector extends AbstractVisitor |
| 14 | { |
| 15 | private SplObjectStorage $constraints; |
| 16 | private SplObjectStorage $sequences; |
| 17 | private SplObjectStorage $tables; |
| 18 | private AbstractPlatform $platform; |
| 19 | public function __construct(AbstractPlatform $platform) |
| 20 | { |
| 21 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5416', 'DropSchemaSqlCollector is deprecated. Use DropSchemaObjectsSQLBuilder instead.'); |
| 22 | $this->platform = $platform; |
| 23 | $this->initializeQueries(); |
| 24 | } |
| 25 | public function acceptTable(Table $table) |
| 26 | { |
| 27 | $this->tables->offsetSet($table); |
| 28 | } |
| 29 | public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint) |
| 30 | { |
| 31 | if (strlen($fkConstraint->getName()) === 0) { |
| 32 | throw SchemaException::namedForeignKeyRequired($localTable, $fkConstraint); |
| 33 | } |
| 34 | $this->constraints->offsetSet($fkConstraint, $localTable); |
| 35 | } |
| 36 | public function acceptSequence(Sequence $sequence) |
| 37 | { |
| 38 | $this->sequences->offsetSet($sequence); |
| 39 | } |
| 40 | public function clearQueries() |
| 41 | { |
| 42 | $this->initializeQueries(); |
| 43 | } |
| 44 | public function getQueries() |
| 45 | { |
| 46 | $sql = []; |
| 47 | foreach ($this->constraints as $fkConstraint) { |
| 48 | assert($fkConstraint instanceof ForeignKeyConstraint); |
| 49 | $localTable = $this->constraints[$fkConstraint]; |
| 50 | $sql[] = $this->platform->getDropForeignKeySQL($fkConstraint->getQuotedName($this->platform), $localTable->getQuotedName($this->platform)); |
| 51 | } |
| 52 | foreach ($this->sequences as $sequence) { |
| 53 | assert($sequence instanceof Sequence); |
| 54 | $sql[] = $this->platform->getDropSequenceSQL($sequence->getQuotedName($this->platform)); |
| 55 | } |
| 56 | foreach ($this->tables as $table) { |
| 57 | assert($table instanceof Table); |
| 58 | $sql[] = $this->platform->getDropTableSQL($table->getQuotedName($this->platform)); |
| 59 | } |
| 60 | return $sql; |
| 61 | } |
| 62 | private function initializeQueries() : void |
| 63 | { |
| 64 | $this->constraints = new SplObjectStorage(); |
| 65 | $this->sequences = new SplObjectStorage(); |
| 66 | $this->tables = new SplObjectStorage(); |
| 67 | } |
| 68 | } |
| 69 |