public function testGetDropTableSqlDispatchEvent() { $listenerMock = $this->getMock('GetDropTableSqlDispatchEventListener', array('onSchemaDropTable')); $listenerMock->expects($this->once())->method('onSchemaDropTable'); $eventManager = new EventManager(); $eventManager->addEventListener(array(Events::onSchemaDropTable), $listenerMock); $this->_platform->setEventManager($eventManager); $this->_platform->getDropTableSQL('TABLE'); }
/** * @param $applicableSequences * @param $tables * * @throws \Doctrine\DBAL\DBALException */ protected function dropExistingSchema($tables, $mauticTables) { $sql = []; //drop tables foreach ($tables as $t) { if (isset($mauticTables[$t])) { $sql[] = $this->platform->getDropTableSQL($t); } } return $sql; }
/** * * @param array $classes * @return array */ public function getDropSchemaSQL(array $classes) { $sm = $this->_em->getConnection()->getSchemaManager(); $sql = array(); $orderedTables = array(); foreach ($classes AS $class) { if ($class->isIdGeneratorSequence() && $class->name == $class->rootEntityName && $this->_platform->supportsSequences()) { $sql[] = $this->_platform->getDropSequenceSQL($class->sequenceGeneratorDefinition['sequenceName']); } } $commitOrder = $this->_getCommitOrder($classes); $associationTables = $this->_getAssociationTables($commitOrder); // Drop association tables first foreach ($associationTables as $associationTable) { if (!in_array($associationTable, $orderedTables)) { $orderedTables[] = $associationTable; } } // Drop tables in reverse commit order for ($i = count($commitOrder) - 1; $i >= 0; --$i) { $class = $commitOrder[$i]; if (($class->isInheritanceTypeSingleTable() && $class->name != $class->rootEntityName) || $class->isMappedSuperclass) { continue; } if (!in_array($class->getTableName(), $orderedTables)) { $orderedTables[] = $class->getTableName(); } } $dropTablesSql = array(); foreach ($orderedTables AS $tableName) { /* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */ $foreignKeys = $sm->listTableForeignKeys($tableName); foreach ($foreignKeys AS $foreignKey) { $sql[] = $this->_platform->getDropForeignKeySQL($foreignKey, $tableName); } $dropTablesSql[] = $this->_platform->getDropTableSQL($tableName); } return array_merge($sql, $dropTablesSql); }
/** * @return array */ public function getQueries() { $sql = array(); foreach ($this->constraints as $fkConstraint) { $localTable = $this->constraints[$fkConstraint]; $sql[] = $this->platform->getDropForeignKeySQL($fkConstraint, $localTable); } foreach ($this->sequences as $sequence) { $sql[] = $this->platform->getDropSequenceSQL($sequence); } foreach ($this->tables as $table) { $sql[] = $this->platform->getDropTableSQL($table); } return $sql; }
/** * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform * @param boolean $saveMode * * @return array */ protected function _toSql(AbstractPlatform $platform, $saveMode = false) { $sql = array(); if ($platform->supportsSchemas()) { foreach ($this->newNamespaces as $newNamespace) { $sql[] = $platform->getCreateSchemaSQL($newNamespace); } } if ($platform->supportsForeignKeyConstraints() && $saveMode == false) { foreach ($this->orphanedForeignKeys as $orphanedForeignKey) { $sql[] = $platform->getDropForeignKeySQL($orphanedForeignKey, $orphanedForeignKey->getLocalTableName()); } } if ($platform->supportsSequences() == true) { foreach ($this->changedSequences as $sequence) { $sql[] = $platform->getAlterSequenceSQL($sequence); } if ($saveMode === false) { foreach ($this->removedSequences as $sequence) { $sql[] = $platform->getDropSequenceSQL($sequence); } } foreach ($this->newSequences as $sequence) { $sql[] = $platform->getCreateSequenceSQL($sequence); } } $foreignKeySql = array(); foreach ($this->newTables as $table) { $sql = array_merge($sql, $platform->getCreateTableSQL($table, AbstractPlatform::CREATE_INDEXES)); if ($platform->supportsForeignKeyConstraints()) { foreach ($table->getForeignKeys() as $foreignKey) { $foreignKeySql[] = $platform->getCreateForeignKeySQL($foreignKey, $table); } } } $sql = array_merge($sql, $foreignKeySql); if ($saveMode === false) { foreach ($this->removedTables as $table) { $sql[] = $platform->getDropTableSQL($table); } } foreach ($this->changedTables as $tableDiff) { $sql = array_merge($sql, $platform->getAlterTableSQL($tableDiff)); } return $sql; }
/** * Drop the given table * * @param string $table The name of the table to drop */ public function dropTable($table) { $this->_execSql($this->_platform->getDropTableSQL($table)); }
/** * @param Table $table */ public function acceptTable(Table $table) { $this->_tables[] = $this->_platform->getDropTableSQL($table->getQuotedName($this->_platform)); }