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
AbstractSchemaManager.php
663 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Doctrine\DBAL\Schema; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | use MailPoetVendor\Doctrine\DBAL\Connection; |
| 5 | use MailPoetVendor\Doctrine\DBAL\Event\SchemaColumnDefinitionEventArgs; |
| 6 | use MailPoetVendor\Doctrine\DBAL\Event\SchemaIndexDefinitionEventArgs; |
| 7 | use MailPoetVendor\Doctrine\DBAL\Events; |
| 8 | use MailPoetVendor\Doctrine\DBAL\Exception; |
| 9 | use MailPoetVendor\Doctrine\DBAL\Exception\DatabaseRequired; |
| 10 | use MailPoetVendor\Doctrine\DBAL\Platforms\AbstractPlatform; |
| 11 | use MailPoetVendor\Doctrine\DBAL\Result; |
| 12 | use MailPoetVendor\Doctrine\Deprecations\Deprecation; |
| 13 | use Throwable; |
| 14 | use function array_filter; |
| 15 | use function array_intersect; |
| 16 | use function array_map; |
| 17 | use function array_values; |
| 18 | use function assert; |
| 19 | use function call_user_func_array; |
| 20 | use function count; |
| 21 | use function func_get_args; |
| 22 | use function is_callable; |
| 23 | use function is_string; |
| 24 | use function preg_match; |
| 25 | use function str_replace; |
| 26 | use function strtolower; |
| 27 | abstract class AbstractSchemaManager |
| 28 | { |
| 29 | protected $_conn; |
| 30 | protected $_platform; |
| 31 | public function __construct(Connection $connection, AbstractPlatform $platform) |
| 32 | { |
| 33 | $this->_conn = $connection; |
| 34 | $this->_platform = $platform; |
| 35 | } |
| 36 | public function getDatabasePlatform() |
| 37 | { |
| 38 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5387', 'AbstractSchemaManager::getDatabasePlatform() is deprecated.' . ' Use Connection::getDatabasePlatform() instead.'); |
| 39 | return $this->_platform; |
| 40 | } |
| 41 | public function tryMethod() |
| 42 | { |
| 43 | Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4897', 'AbstractSchemaManager::tryMethod() is deprecated.'); |
| 44 | $args = func_get_args(); |
| 45 | $method = $args[0]; |
| 46 | unset($args[0]); |
| 47 | $args = array_values($args); |
| 48 | $callback = [$this, $method]; |
| 49 | assert(is_callable($callback)); |
| 50 | try { |
| 51 | return call_user_func_array($callback, $args); |
| 52 | } catch (Throwable $e) { |
| 53 | return \false; |
| 54 | } |
| 55 | } |
| 56 | public function listDatabases() |
| 57 | { |
| 58 | $sql = $this->_platform->getListDatabasesSQL(); |
| 59 | $databases = $this->_conn->fetchAllAssociative($sql); |
| 60 | return $this->_getPortableDatabasesList($databases); |
| 61 | } |
| 62 | public function listNamespaceNames() |
| 63 | { |
| 64 | Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/4503', 'AbstractSchemaManager::listNamespaceNames() is deprecated,' . ' use AbstractSchemaManager::listSchemaNames() instead.'); |
| 65 | $sql = $this->_platform->getListNamespacesSQL(); |
| 66 | $namespaces = $this->_conn->fetchAllAssociative($sql); |
| 67 | return $this->getPortableNamespacesList($namespaces); |
| 68 | } |
| 69 | public function listSchemaNames() : array |
| 70 | { |
| 71 | throw Exception::notSupported(__METHOD__); |
| 72 | } |
| 73 | public function listSequences($database = null) |
| 74 | { |
| 75 | if ($database === null) { |
| 76 | $database = $this->getDatabase(__METHOD__); |
| 77 | } else { |
| 78 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/5284', 'Passing $database to AbstractSchemaManager::listSequences() is deprecated.'); |
| 79 | } |
| 80 | $sql = $this->_platform->getListSequencesSQL($database); |
| 81 | $sequences = $this->_conn->fetchAllAssociative($sql); |
| 82 | return $this->filterAssetNames($this->_getPortableSequencesList($sequences)); |
| 83 | } |
| 84 | public function listTableColumns($table, $database = null) |
| 85 | { |
| 86 | if ($database === null) { |
| 87 | $database = $this->getDatabase(__METHOD__); |
| 88 | } else { |
| 89 | Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/5284', 'Passing $database to AbstractSchemaManager::listTableColumns() is deprecated.'); |
| 90 | } |
| 91 | $sql = $this->_platform->getListTableColumnsSQL($table, $database); |
| 92 | $tableColumns = $this->_conn->fetchAllAssociative($sql); |
| 93 | return $this->_getPortableTableColumnList($table, $database, $tableColumns); |
| 94 | } |
| 95 | protected function doListTableColumns($table, $database = null) : array |
| 96 | { |
| 97 | if ($database === null) { |
| 98 | $database = $this->getDatabase(__METHOD__); |
| 99 | } else { |
| 100 | Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/5284', 'Passing $database to AbstractSchemaManager::doListTableColumns() is deprecated.'); |
| 101 | } |
| 102 | return $this->_getPortableTableColumnList($table, $database, $this->selectTableColumns($database, $this->normalizeName($table))->fetchAllAssociative()); |
| 103 | } |
| 104 | public function listTableIndexes($table) |
| 105 | { |
| 106 | $sql = $this->_platform->getListTableIndexesSQL($table, $this->_conn->getDatabase()); |
| 107 | $tableIndexes = $this->_conn->fetchAllAssociative($sql); |
| 108 | return $this->_getPortableTableIndexesList($tableIndexes, $table); |
| 109 | } |
| 110 | protected function doListTableIndexes($table) : array |
| 111 | { |
| 112 | $database = $this->getDatabase(__METHOD__); |
| 113 | $table = $this->normalizeName($table); |
| 114 | return $this->_getPortableTableIndexesList($this->selectIndexColumns($database, $table)->fetchAllAssociative(), $table); |
| 115 | } |
| 116 | public function tablesExist($names) |
| 117 | { |
| 118 | if (is_string($names)) { |
| 119 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/3580', 'The usage of a string $tableNames in AbstractSchemaManager::tablesExist() is deprecated. ' . 'Pass a one-element array instead.'); |
| 120 | } |
| 121 | $names = array_map('strtolower', (array) $names); |
| 122 | return count($names) === count(array_intersect($names, array_map('strtolower', $this->listTableNames()))); |
| 123 | } |
| 124 | public function listTableNames() |
| 125 | { |
| 126 | $sql = $this->_platform->getListTablesSQL(); |
| 127 | $tables = $this->_conn->fetchAllAssociative($sql); |
| 128 | $tableNames = $this->_getPortableTablesList($tables); |
| 129 | return $this->filterAssetNames($tableNames); |
| 130 | } |
| 131 | protected function doListTableNames() : array |
| 132 | { |
| 133 | $database = $this->getDatabase(__METHOD__); |
| 134 | return $this->filterAssetNames($this->_getPortableTablesList($this->selectTableNames($database)->fetchAllAssociative())); |
| 135 | } |
| 136 | protected function filterAssetNames($assetNames) |
| 137 | { |
| 138 | $filter = $this->_conn->getConfiguration()->getSchemaAssetsFilter(); |
| 139 | if ($filter === null) { |
| 140 | return $assetNames; |
| 141 | } |
| 142 | return array_values(array_filter($assetNames, $filter)); |
| 143 | } |
| 144 | public function listTables() |
| 145 | { |
| 146 | $tableNames = $this->listTableNames(); |
| 147 | $tables = []; |
| 148 | foreach ($tableNames as $tableName) { |
| 149 | $tables[] = $this->introspectTable($tableName); |
| 150 | } |
| 151 | return $tables; |
| 152 | } |
| 153 | protected function doListTables() : array |
| 154 | { |
| 155 | $database = $this->getDatabase(__METHOD__); |
| 156 | $tableColumnsByTable = $this->fetchTableColumnsByTable($database); |
| 157 | $indexColumnsByTable = $this->fetchIndexColumnsByTable($database); |
| 158 | $foreignKeyColumnsByTable = $this->fetchForeignKeyColumnsByTable($database); |
| 159 | $tableOptionsByTable = $this->fetchTableOptionsByTable($database); |
| 160 | $filter = $this->_conn->getConfiguration()->getSchemaAssetsFilter(); |
| 161 | $tables = []; |
| 162 | foreach ($tableColumnsByTable as $tableName => $tableColumns) { |
| 163 | if ($filter !== null && !$filter($tableName)) { |
| 164 | continue; |
| 165 | } |
| 166 | $tables[] = new Table($tableName, $this->_getPortableTableColumnList($tableName, $database, $tableColumns), $this->_getPortableTableIndexesList($indexColumnsByTable[$tableName] ?? [], $tableName), [], $this->_getPortableTableForeignKeysList($foreignKeyColumnsByTable[$tableName] ?? []), $tableOptionsByTable[$tableName] ?? []); |
| 167 | } |
| 168 | return $tables; |
| 169 | } |
| 170 | public function listTableDetails($name) |
| 171 | { |
| 172 | Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5595', '%s is deprecated. Use introspectTable() instead.', __METHOD__); |
| 173 | $columns = $this->listTableColumns($name); |
| 174 | $foreignKeys = []; |
| 175 | if ($this->_platform->supportsForeignKeyConstraints()) { |
| 176 | $foreignKeys = $this->listTableForeignKeys($name); |
| 177 | } |
| 178 | $indexes = $this->listTableIndexes($name); |
| 179 | return new Table($name, $columns, $indexes, [], $foreignKeys); |
| 180 | } |
| 181 | protected function doListTableDetails($name) : Table |
| 182 | { |
| 183 | $database = $this->getDatabase(__METHOD__); |
| 184 | $normalizedName = $this->normalizeName($name); |
| 185 | $tableOptionsByTable = $this->fetchTableOptionsByTable($database, $normalizedName); |
| 186 | if ($this->_platform->supportsForeignKeyConstraints()) { |
| 187 | $foreignKeys = $this->listTableForeignKeys($name); |
| 188 | } else { |
| 189 | $foreignKeys = []; |
| 190 | } |
| 191 | return new Table($name, $this->listTableColumns($name, $database), $this->listTableIndexes($name), [], $foreignKeys, $tableOptionsByTable[$normalizedName] ?? []); |
| 192 | } |
| 193 | protected function normalizeName(string $name) : string |
| 194 | { |
| 195 | $identifier = new Identifier($name); |
| 196 | return $identifier->getName(); |
| 197 | } |
| 198 | protected function selectTableNames(string $databaseName) : Result |
| 199 | { |
| 200 | throw Exception::notSupported(__METHOD__); |
| 201 | } |
| 202 | protected function selectTableColumns(string $databaseName, ?string $tableName = null) : Result |
| 203 | { |
| 204 | throw Exception::notSupported(__METHOD__); |
| 205 | } |
| 206 | protected function selectIndexColumns(string $databaseName, ?string $tableName = null) : Result |
| 207 | { |
| 208 | throw Exception::notSupported(__METHOD__); |
| 209 | } |
| 210 | protected function selectForeignKeyColumns(string $databaseName, ?string $tableName = null) : Result |
| 211 | { |
| 212 | throw Exception::notSupported(__METHOD__); |
| 213 | } |
| 214 | protected function fetchTableColumnsByTable(string $databaseName) : array |
| 215 | { |
| 216 | return $this->fetchAllAssociativeGrouped($this->selectTableColumns($databaseName)); |
| 217 | } |
| 218 | protected function fetchIndexColumnsByTable(string $databaseName) : array |
| 219 | { |
| 220 | return $this->fetchAllAssociativeGrouped($this->selectIndexColumns($databaseName)); |
| 221 | } |
| 222 | protected function fetchForeignKeyColumnsByTable(string $databaseName) : array |
| 223 | { |
| 224 | if (!$this->_platform->supportsForeignKeyConstraints()) { |
| 225 | return []; |
| 226 | } |
| 227 | return $this->fetchAllAssociativeGrouped($this->selectForeignKeyColumns($databaseName)); |
| 228 | } |
| 229 | protected function fetchTableOptionsByTable(string $databaseName, ?string $tableName = null) : array |
| 230 | { |
| 231 | throw Exception::notSupported(__METHOD__); |
| 232 | } |
| 233 | public function introspectTable(string $name) : Table |
| 234 | { |
| 235 | $table = $this->listTableDetails($name); |
| 236 | if ($table->getColumns() === []) { |
| 237 | throw SchemaException::tableDoesNotExist($name); |
| 238 | } |
| 239 | return $table; |
| 240 | } |
| 241 | public function listViews() |
| 242 | { |
| 243 | $database = $this->_conn->getDatabase(); |
| 244 | $sql = $this->_platform->getListViewsSQL($database); |
| 245 | $views = $this->_conn->fetchAllAssociative($sql); |
| 246 | return $this->_getPortableViewsList($views); |
| 247 | } |
| 248 | public function listTableForeignKeys($table, $database = null) |
| 249 | { |
| 250 | if ($database === null) { |
| 251 | $database = $this->getDatabase(__METHOD__); |
| 252 | } else { |
| 253 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/5284', 'Passing $database to AbstractSchemaManager::listTableForeignKeys() is deprecated.'); |
| 254 | } |
| 255 | $sql = $this->_platform->getListTableForeignKeysSQL($table, $database); |
| 256 | $tableForeignKeys = $this->_conn->fetchAllAssociative($sql); |
| 257 | return $this->_getPortableTableForeignKeysList($tableForeignKeys); |
| 258 | } |
| 259 | protected function doListTableForeignKeys($table, $database = null) : array |
| 260 | { |
| 261 | if ($database === null) { |
| 262 | $database = $this->getDatabase(__METHOD__); |
| 263 | } else { |
| 264 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/5284', 'Passing $database to AbstractSchemaManager::listTableForeignKeys() is deprecated.'); |
| 265 | } |
| 266 | return $this->_getPortableTableForeignKeysList($this->selectForeignKeyColumns($database, $this->normalizeName($table))->fetchAllAssociative()); |
| 267 | } |
| 268 | public function dropDatabase($database) |
| 269 | { |
| 270 | $this->_conn->executeStatement($this->_platform->getDropDatabaseSQL($database)); |
| 271 | } |
| 272 | public function dropSchema(string $schemaName) : void |
| 273 | { |
| 274 | $this->_conn->executeStatement($this->_platform->getDropSchemaSQL($schemaName)); |
| 275 | } |
| 276 | public function dropTable($name) |
| 277 | { |
| 278 | $this->_conn->executeStatement($this->_platform->getDropTableSQL($name)); |
| 279 | } |
| 280 | public function dropIndex($index, $table) |
| 281 | { |
| 282 | if ($index instanceof Index) { |
| 283 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/4798', 'Passing $index as an Index object to %s is deprecated. Pass it as a quoted name instead.', __METHOD__); |
| 284 | $index = $index->getQuotedName($this->_platform); |
| 285 | } |
| 286 | if ($table instanceof Table) { |
| 287 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/4798', 'Passing $table as an Table object to %s is deprecated. Pass it as a quoted name instead.', __METHOD__); |
| 288 | $table = $table->getQuotedName($this->_platform); |
| 289 | } |
| 290 | $this->_conn->executeStatement($this->_platform->getDropIndexSQL($index, $table)); |
| 291 | } |
| 292 | public function dropConstraint(Constraint $constraint, $table) |
| 293 | { |
| 294 | if ($table instanceof Table) { |
| 295 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/4798', 'Passing $table as a Table object to %s is deprecated. Pass it as a quoted name instead.', __METHOD__); |
| 296 | $table = $table->getQuotedName($this->_platform); |
| 297 | } |
| 298 | $this->_conn->executeStatement($this->_platform->getDropConstraintSQL($constraint->getQuotedName($this->_platform), $table)); |
| 299 | } |
| 300 | public function dropForeignKey($foreignKey, $table) |
| 301 | { |
| 302 | if ($foreignKey instanceof ForeignKeyConstraint) { |
| 303 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/4798', 'Passing $foreignKey as a ForeignKeyConstraint object to %s is deprecated.' . ' Pass it as a quoted name instead.', __METHOD__); |
| 304 | $foreignKey = $foreignKey->getQuotedName($this->_platform); |
| 305 | } |
| 306 | if ($table instanceof Table) { |
| 307 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/4798', 'Passing $table as a Table object to %s is deprecated. Pass it as a quoted name instead.', __METHOD__); |
| 308 | $table = $table->getQuotedName($this->_platform); |
| 309 | } |
| 310 | $this->_conn->executeStatement($this->_platform->getDropForeignKeySQL($foreignKey, $table)); |
| 311 | } |
| 312 | public function dropSequence($name) |
| 313 | { |
| 314 | $this->_conn->executeStatement($this->_platform->getDropSequenceSQL($name)); |
| 315 | } |
| 316 | public function dropUniqueConstraint(string $name, string $tableName) : void |
| 317 | { |
| 318 | $this->_conn->executeStatement($this->_platform->getDropUniqueConstraintSQL($name, $tableName)); |
| 319 | } |
| 320 | public function dropView($name) |
| 321 | { |
| 322 | $this->_conn->executeStatement($this->_platform->getDropViewSQL($name)); |
| 323 | } |
| 324 | public function createSchemaObjects(Schema $schema) : void |
| 325 | { |
| 326 | $this->_execSql($schema->toSql($this->_platform)); |
| 327 | } |
| 328 | public function createDatabase($database) |
| 329 | { |
| 330 | $this->_conn->executeStatement($this->_platform->getCreateDatabaseSQL($database)); |
| 331 | } |
| 332 | public function createTable(Table $table) |
| 333 | { |
| 334 | $createFlags = AbstractPlatform::CREATE_INDEXES | AbstractPlatform::CREATE_FOREIGNKEYS; |
| 335 | $this->_execSql($this->_platform->getCreateTableSQL($table, $createFlags)); |
| 336 | } |
| 337 | public function createSequence($sequence) |
| 338 | { |
| 339 | $this->_conn->executeStatement($this->_platform->getCreateSequenceSQL($sequence)); |
| 340 | } |
| 341 | public function createConstraint(Constraint $constraint, $table) |
| 342 | { |
| 343 | $this->_conn->executeStatement($this->_platform->getCreateConstraintSQL($constraint, $table)); |
| 344 | } |
| 345 | public function createIndex(Index $index, $table) |
| 346 | { |
| 347 | $this->_conn->executeStatement($this->_platform->getCreateIndexSQL($index, $table)); |
| 348 | } |
| 349 | public function createForeignKey(ForeignKeyConstraint $foreignKey, $table) |
| 350 | { |
| 351 | $this->_conn->executeStatement($this->_platform->getCreateForeignKeySQL($foreignKey, $table)); |
| 352 | } |
| 353 | public function createUniqueConstraint(UniqueConstraint $uniqueConstraint, string $tableName) : void |
| 354 | { |
| 355 | $this->_conn->executeStatement($this->_platform->getCreateUniqueConstraintSQL($uniqueConstraint, $tableName)); |
| 356 | } |
| 357 | public function createView(View $view) |
| 358 | { |
| 359 | $this->_conn->executeStatement($this->_platform->getCreateViewSQL($view->getQuotedName($this->_platform), $view->getSql())); |
| 360 | } |
| 361 | public function dropSchemaObjects(Schema $schema) : void |
| 362 | { |
| 363 | $this->_execSql($schema->toDropSql($this->_platform)); |
| 364 | } |
| 365 | public function dropAndCreateConstraint(Constraint $constraint, $table) |
| 366 | { |
| 367 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4897', 'AbstractSchemaManager::dropAndCreateConstraint() is deprecated.' . ' Use AbstractSchemaManager::dropIndex() and AbstractSchemaManager::createIndex(),' . ' AbstractSchemaManager::dropForeignKey() and AbstractSchemaManager::createForeignKey()' . ' or AbstractSchemaManager::dropUniqueConstraint()' . ' and AbstractSchemaManager::createUniqueConstraint() instead.'); |
| 368 | $this->tryMethod('dropConstraint', $constraint, $table); |
| 369 | $this->createConstraint($constraint, $table); |
| 370 | } |
| 371 | public function dropAndCreateIndex(Index $index, $table) |
| 372 | { |
| 373 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4897', 'AbstractSchemaManager::dropAndCreateIndex() is deprecated.' . ' Use AbstractSchemaManager::dropIndex() and AbstractSchemaManager::createIndex() instead.'); |
| 374 | $this->tryMethod('dropIndex', $index->getQuotedName($this->_platform), $table); |
| 375 | $this->createIndex($index, $table); |
| 376 | } |
| 377 | public function dropAndCreateForeignKey(ForeignKeyConstraint $foreignKey, $table) |
| 378 | { |
| 379 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4897', 'AbstractSchemaManager::dropAndCreateForeignKey() is deprecated.' . ' Use AbstractSchemaManager::dropForeignKey() and AbstractSchemaManager::createForeignKey() instead.'); |
| 380 | $this->tryMethod('dropForeignKey', $foreignKey, $table); |
| 381 | $this->createForeignKey($foreignKey, $table); |
| 382 | } |
| 383 | public function dropAndCreateSequence(Sequence $sequence) |
| 384 | { |
| 385 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4897', 'AbstractSchemaManager::dropAndCreateSequence() is deprecated.' . ' Use AbstractSchemaManager::dropSequence() and AbstractSchemaManager::createSequence() instead.'); |
| 386 | $this->tryMethod('dropSequence', $sequence->getQuotedName($this->_platform)); |
| 387 | $this->createSequence($sequence); |
| 388 | } |
| 389 | public function dropAndCreateTable(Table $table) |
| 390 | { |
| 391 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4897', 'AbstractSchemaManager::dropAndCreateTable() is deprecated.' . ' Use AbstractSchemaManager::dropTable() and AbstractSchemaManager::createTable() instead.'); |
| 392 | $this->tryMethod('dropTable', $table->getQuotedName($this->_platform)); |
| 393 | $this->createTable($table); |
| 394 | } |
| 395 | public function dropAndCreateDatabase($database) |
| 396 | { |
| 397 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4897', 'AbstractSchemaManager::dropAndCreateDatabase() is deprecated.' . ' Use AbstractSchemaManager::dropDatabase() and AbstractSchemaManager::createDatabase() instead.'); |
| 398 | $this->tryMethod('dropDatabase', $database); |
| 399 | $this->createDatabase($database); |
| 400 | } |
| 401 | public function dropAndCreateView(View $view) |
| 402 | { |
| 403 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4897', 'AbstractSchemaManager::dropAndCreateView() is deprecated.' . ' Use AbstractSchemaManager::dropView() and AbstractSchemaManager::createView() instead.'); |
| 404 | $this->tryMethod('dropView', $view->getQuotedName($this->_platform)); |
| 405 | $this->createView($view); |
| 406 | } |
| 407 | public function alterSchema(SchemaDiff $schemaDiff) : void |
| 408 | { |
| 409 | $this->_execSql($this->_platform->getAlterSchemaSQL($schemaDiff)); |
| 410 | } |
| 411 | public function migrateSchema(Schema $toSchema) : void |
| 412 | { |
| 413 | $schemaDiff = $this->createComparator()->compareSchemas($this->introspectSchema(), $toSchema); |
| 414 | $this->alterSchema($schemaDiff); |
| 415 | } |
| 416 | public function alterTable(TableDiff $tableDiff) |
| 417 | { |
| 418 | $this->_execSql($this->_platform->getAlterTableSQL($tableDiff)); |
| 419 | } |
| 420 | public function renameTable($name, $newName) |
| 421 | { |
| 422 | $this->_execSql($this->_platform->getRenameTableSQL($name, $newName)); |
| 423 | } |
| 424 | protected function _getPortableDatabasesList($databases) |
| 425 | { |
| 426 | $list = []; |
| 427 | foreach ($databases as $value) { |
| 428 | $list[] = $this->_getPortableDatabaseDefinition($value); |
| 429 | } |
| 430 | return $list; |
| 431 | } |
| 432 | protected function getPortableNamespacesList(array $namespaces) |
| 433 | { |
| 434 | Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/4503', 'AbstractSchemaManager::getPortableNamespacesList() is deprecated,' . ' use AbstractSchemaManager::listSchemaNames() instead.'); |
| 435 | $namespacesList = []; |
| 436 | foreach ($namespaces as $namespace) { |
| 437 | $namespacesList[] = $this->getPortableNamespaceDefinition($namespace); |
| 438 | } |
| 439 | return $namespacesList; |
| 440 | } |
| 441 | protected function _getPortableDatabaseDefinition($database) |
| 442 | { |
| 443 | return $database; |
| 444 | } |
| 445 | protected function getPortableNamespaceDefinition(array $namespace) |
| 446 | { |
| 447 | Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/4503', 'AbstractSchemaManager::getPortableNamespaceDefinition() is deprecated,' . ' use AbstractSchemaManager::listSchemaNames() instead.'); |
| 448 | return $namespace; |
| 449 | } |
| 450 | protected function _getPortableSequencesList($sequences) |
| 451 | { |
| 452 | $list = []; |
| 453 | foreach ($sequences as $value) { |
| 454 | $list[] = $this->_getPortableSequenceDefinition($value); |
| 455 | } |
| 456 | return $list; |
| 457 | } |
| 458 | protected function _getPortableSequenceDefinition($sequence) |
| 459 | { |
| 460 | throw Exception::notSupported('Sequences'); |
| 461 | } |
| 462 | protected function _getPortableTableColumnList($table, $database, $tableColumns) |
| 463 | { |
| 464 | $eventManager = $this->_platform->getEventManager(); |
| 465 | $list = []; |
| 466 | foreach ($tableColumns as $tableColumn) { |
| 467 | $column = null; |
| 468 | $defaultPrevented = \false; |
| 469 | if ($eventManager !== null && $eventManager->hasListeners(Events::onSchemaColumnDefinition)) { |
| 470 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/5784', 'Subscribing to %s events is deprecated. Use a custom schema manager instead.', Events::onSchemaColumnDefinition); |
| 471 | $eventArgs = new SchemaColumnDefinitionEventArgs($tableColumn, $table, $database, $this->_conn); |
| 472 | $eventManager->dispatchEvent(Events::onSchemaColumnDefinition, $eventArgs); |
| 473 | $defaultPrevented = $eventArgs->isDefaultPrevented(); |
| 474 | $column = $eventArgs->getColumn(); |
| 475 | } |
| 476 | if (!$defaultPrevented) { |
| 477 | $column = $this->_getPortableTableColumnDefinition($tableColumn); |
| 478 | } |
| 479 | if ($column === null) { |
| 480 | continue; |
| 481 | } |
| 482 | $name = strtolower($column->getQuotedName($this->_platform)); |
| 483 | $list[$name] = $column; |
| 484 | } |
| 485 | return $list; |
| 486 | } |
| 487 | protected abstract function _getPortableTableColumnDefinition($tableColumn); |
| 488 | protected function _getPortableTableIndexesList($tableIndexes, $tableName = null) |
| 489 | { |
| 490 | $result = []; |
| 491 | foreach ($tableIndexes as $tableIndex) { |
| 492 | $indexName = $keyName = $tableIndex['key_name']; |
| 493 | if ($tableIndex['primary']) { |
| 494 | $keyName = 'primary'; |
| 495 | } |
| 496 | $keyName = strtolower($keyName); |
| 497 | if (!isset($result[$keyName])) { |
| 498 | $options = ['lengths' => []]; |
| 499 | if (isset($tableIndex['where'])) { |
| 500 | $options['where'] = $tableIndex['where']; |
| 501 | } |
| 502 | $result[$keyName] = ['name' => $indexName, 'columns' => [], 'unique' => !$tableIndex['non_unique'], 'primary' => $tableIndex['primary'], 'flags' => $tableIndex['flags'] ?? [], 'options' => $options]; |
| 503 | } |
| 504 | $result[$keyName]['columns'][] = $tableIndex['column_name']; |
| 505 | $result[$keyName]['options']['lengths'][] = $tableIndex['length'] ?? null; |
| 506 | } |
| 507 | $eventManager = $this->_platform->getEventManager(); |
| 508 | $indexes = []; |
| 509 | foreach ($result as $indexKey => $data) { |
| 510 | $index = null; |
| 511 | $defaultPrevented = \false; |
| 512 | if ($eventManager !== null && $eventManager->hasListeners(Events::onSchemaIndexDefinition)) { |
| 513 | Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/issues/5784', 'Subscribing to %s events is deprecated. Use a custom schema manager instead.', Events::onSchemaColumnDefinition); |
| 514 | $eventArgs = new SchemaIndexDefinitionEventArgs($data, $tableName, $this->_conn); |
| 515 | $eventManager->dispatchEvent(Events::onSchemaIndexDefinition, $eventArgs); |
| 516 | $defaultPrevented = $eventArgs->isDefaultPrevented(); |
| 517 | $index = $eventArgs->getIndex(); |
| 518 | } |
| 519 | if (!$defaultPrevented) { |
| 520 | $index = new Index($data['name'], $data['columns'], $data['unique'], $data['primary'], $data['flags'], $data['options']); |
| 521 | } |
| 522 | if ($index === null) { |
| 523 | continue; |
| 524 | } |
| 525 | $indexes[$indexKey] = $index; |
| 526 | } |
| 527 | return $indexes; |
| 528 | } |
| 529 | protected function _getPortableTablesList($tables) |
| 530 | { |
| 531 | $list = []; |
| 532 | foreach ($tables as $value) { |
| 533 | $list[] = $this->_getPortableTableDefinition($value); |
| 534 | } |
| 535 | return $list; |
| 536 | } |
| 537 | protected function _getPortableTableDefinition($table) |
| 538 | { |
| 539 | return $table; |
| 540 | } |
| 541 | protected function _getPortableViewsList($views) |
| 542 | { |
| 543 | $list = []; |
| 544 | foreach ($views as $value) { |
| 545 | $view = $this->_getPortableViewDefinition($value); |
| 546 | if ($view === \false) { |
| 547 | continue; |
| 548 | } |
| 549 | $viewName = strtolower($view->getQuotedName($this->_platform)); |
| 550 | $list[$viewName] = $view; |
| 551 | } |
| 552 | return $list; |
| 553 | } |
| 554 | protected function _getPortableViewDefinition($view) |
| 555 | { |
| 556 | return \false; |
| 557 | } |
| 558 | protected function _getPortableTableForeignKeysList($tableForeignKeys) |
| 559 | { |
| 560 | $list = []; |
| 561 | foreach ($tableForeignKeys as $value) { |
| 562 | $list[] = $this->_getPortableTableForeignKeyDefinition($value); |
| 563 | } |
| 564 | return $list; |
| 565 | } |
| 566 | protected function _getPortableTableForeignKeyDefinition($tableForeignKey) |
| 567 | { |
| 568 | return $tableForeignKey; |
| 569 | } |
| 570 | protected function _execSql($sql) |
| 571 | { |
| 572 | foreach ((array) $sql as $query) { |
| 573 | $this->_conn->executeStatement($query); |
| 574 | } |
| 575 | } |
| 576 | public function createSchema() |
| 577 | { |
| 578 | Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5613', '%s is deprecated. Use introspectSchema() instead.', __METHOD__); |
| 579 | $schemaNames = []; |
| 580 | if ($this->_platform->supportsSchemas()) { |
| 581 | $schemaNames = $this->listNamespaceNames(); |
| 582 | } |
| 583 | $sequences = []; |
| 584 | if ($this->_platform->supportsSequences()) { |
| 585 | $sequences = $this->listSequences(); |
| 586 | } |
| 587 | $tables = $this->listTables(); |
| 588 | return new Schema($tables, $sequences, $this->createSchemaConfig(), $schemaNames); |
| 589 | } |
| 590 | public function introspectSchema() : Schema |
| 591 | { |
| 592 | return $this->createSchema(); |
| 593 | } |
| 594 | public function createSchemaConfig() |
| 595 | { |
| 596 | $schemaConfig = new SchemaConfig(); |
| 597 | $schemaConfig->setMaxIdentifierLength($this->_platform->getMaxIdentifierLength()); |
| 598 | $searchPaths = $this->getSchemaSearchPaths(); |
| 599 | if (isset($searchPaths[0])) { |
| 600 | $schemaConfig->setName($searchPaths[0]); |
| 601 | } |
| 602 | $params = $this->_conn->getParams(); |
| 603 | if (!isset($params['defaultTableOptions'])) { |
| 604 | $params['defaultTableOptions'] = []; |
| 605 | } |
| 606 | if (!isset($params['defaultTableOptions']['charset']) && isset($params['charset'])) { |
| 607 | $params['defaultTableOptions']['charset'] = $params['charset']; |
| 608 | } |
| 609 | $schemaConfig->setDefaultTableOptions($params['defaultTableOptions']); |
| 610 | return $schemaConfig; |
| 611 | } |
| 612 | public function getSchemaSearchPaths() |
| 613 | { |
| 614 | Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/4821', 'AbstractSchemaManager::getSchemaSearchPaths() is deprecated.'); |
| 615 | $database = $this->_conn->getDatabase(); |
| 616 | if ($database !== null) { |
| 617 | return [$database]; |
| 618 | } |
| 619 | return []; |
| 620 | } |
| 621 | public function extractDoctrineTypeFromComment($comment, $currentType) |
| 622 | { |
| 623 | if ($this->_conn->getConfiguration()->getDisableTypeComments()) { |
| 624 | return $currentType; |
| 625 | } |
| 626 | if ($comment !== null && preg_match('(\\(DC2Type:(((?!\\)).)+)\\))', $comment, $match) === 1) { |
| 627 | return $match[1]; |
| 628 | } |
| 629 | return $currentType; |
| 630 | } |
| 631 | public function removeDoctrineTypeFromComment($comment, $type) |
| 632 | { |
| 633 | if ($this->_conn->getConfiguration()->getDisableTypeComments()) { |
| 634 | return $comment; |
| 635 | } |
| 636 | if ($comment === null) { |
| 637 | return null; |
| 638 | } |
| 639 | return str_replace('(DC2Type:' . $type . ')', '', $comment); |
| 640 | } |
| 641 | private function getDatabase(string $methodName) : string |
| 642 | { |
| 643 | $database = $this->_conn->getDatabase(); |
| 644 | if ($database === null) { |
| 645 | throw DatabaseRequired::new($methodName); |
| 646 | } |
| 647 | return $database; |
| 648 | } |
| 649 | public function createComparator() : Comparator |
| 650 | { |
| 651 | return new Comparator($this->_platform); |
| 652 | } |
| 653 | private function fetchAllAssociativeGrouped(Result $result) : array |
| 654 | { |
| 655 | $data = []; |
| 656 | foreach ($result->fetchAllAssociative() as $row) { |
| 657 | $tableName = $this->_getPortableTableDefinition($row); |
| 658 | $data[$tableName][] = $row; |
| 659 | } |
| 660 | return $data; |
| 661 | } |
| 662 | } |
| 663 |