From 8e062955d5796917001dd018e126a800c53d4ec1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Sun, 9 Oct 2022 23:36:44 +0200 Subject: [PATCH] Address deprecations from DBAL See https://github.com/doctrine/dbal/pull/5731 --- .../ORM/Mapping/Driver/DatabaseDriver.php | 5 +++-- lib/Doctrine/ORM/Tools/SchemaTool.php | 17 ++++++++++------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php b/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php index d61d324c934..952ed821656 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php @@ -304,14 +304,15 @@ private function reverseEngineerMappingFromDatabase(): void $allForeignKeyColumns = array_merge($allForeignKeyColumns, $foreignKey->getLocalColumns()); } - if (! $table->hasPrimaryKey()) { + $primaryKey = $table->getPrimaryKey(); + if ($primaryKey === null) { throw new MappingException( 'Table ' . $tableName . ' has no primary key. Doctrine does not ' . "support reverse engineering from tables that don't have a primary key." ); } - $pkColumns = $table->getPrimaryKey()->getColumns(); + $pkColumns = $primaryKey->getColumns(); sort($pkColumns); sort($allForeignKeyColumns); diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index 81602852e11..d011e8ecc18 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -893,13 +893,16 @@ public function getDropSchemaSQL(array $classes) } foreach ($schema->getTables() as $table) { - if ($table->hasPrimaryKey()) { - $columns = $table->getPrimaryKey()->getColumns(); - if (count($columns) === 1) { - $checkSequence = $table->getName() . '_' . $columns[0] . '_seq'; - if ($deployedSchema->hasSequence($checkSequence) && ! $schema->hasSequence($checkSequence)) { - $schema->createSequence($checkSequence); - } + $primaryKey = $table->getPrimaryKey(); + if ($primaryKey === null) { + continue; + } + + $columns = $primaryKey->getColumns(); + if (count($columns) === 1) { + $checkSequence = $table->getName() . '_' . $columns[0] . '_seq'; + if ($deployedSchema->hasSequence($checkSequence) && ! $schema->hasSequence($checkSequence)) { + $schema->createSequence($checkSequence); } } }