From 2bbf9216c29f57dafd370fb775d698c8617cb13d Mon Sep 17 00:00:00 2001 From: Adrien Dupuis <61695653+adriendupuis@users.noreply.github.com> Date: Thu, 20 Feb 2025 16:37:24 +0100 Subject: [PATCH 1/6] InstallPlatformCommand.php: "Continue?" default to "no" --- .../RepositoryInstaller/Command/InstallPlatformCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bundle/RepositoryInstaller/Command/InstallPlatformCommand.php b/src/bundle/RepositoryInstaller/Command/InstallPlatformCommand.php index 0011d9d37c..8cdb8239b3 100644 --- a/src/bundle/RepositoryInstaller/Command/InstallPlatformCommand.php +++ b/src/bundle/RepositoryInstaller/Command/InstallPlatformCommand.php @@ -88,7 +88,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $schemaManager = $this->connection->getSchemaManager(); if (!empty($schemaManager->listTables())) { $io = new SymfonyStyle($input, $output); - if (!$io->confirm('Running this command will delete data in all Ibexa generated tables. Continue?', )) { + if (!$io->confirm('Running this command will delete data in all Ibexa generated tables. Continue?', false)) { return 0; } } From 9e7de5a271e1d8cf65edc9800a4ce727732040dd Mon Sep 17 00:00:00 2001 From: Adrien Dupuis <61695653+adriendupuis@users.noreply.github.com> Date: Thu, 20 Feb 2025 16:38:50 +0100 Subject: [PATCH 2/6] CoreInstaller.php: FOREIGN_KEY_CHECKS=0 to drop all tables Answering "yes" to "Continue?" just throw errors and fail. SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails --- src/bundle/RepositoryInstaller/Installer/CoreInstaller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bundle/RepositoryInstaller/Installer/CoreInstaller.php b/src/bundle/RepositoryInstaller/Installer/CoreInstaller.php index 6b05899ffe..6041119f70 100644 --- a/src/bundle/RepositoryInstaller/Installer/CoreInstaller.php +++ b/src/bundle/RepositoryInstaller/Installer/CoreInstaller.php @@ -98,7 +98,7 @@ protected function getDropSqlStatementsForExistingSchema( AbstractPlatform $databasePlatform ): array { $existingSchema = $this->db->getSchemaManager()->createSchema(); - $statements = []; + $statements = ['SET FOREIGN_KEY_CHECKS=0']; // reverse table order for clean-up (due to FKs) $tables = array_reverse($newSchema->getTables()); // cleanup pre-existing database From 6730d90dba4c3b6e7a8933510a6f763a1aa32c7c Mon Sep 17 00:00:00 2001 From: Adrien Dupuis <61695653+adriendupuis@users.noreply.github.com> Date: Thu, 20 Feb 2025 18:18:16 +0100 Subject: [PATCH 3/6] CoreInstaller.php: drop foreign keys instead of ignoring them More cross-platform solution. --- .../Installer/CoreInstaller.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/bundle/RepositoryInstaller/Installer/CoreInstaller.php b/src/bundle/RepositoryInstaller/Installer/CoreInstaller.php index 6041119f70..d21a9f4519 100644 --- a/src/bundle/RepositoryInstaller/Installer/CoreInstaller.php +++ b/src/bundle/RepositoryInstaller/Installer/CoreInstaller.php @@ -98,10 +98,20 @@ protected function getDropSqlStatementsForExistingSchema( AbstractPlatform $databasePlatform ): array { $existingSchema = $this->db->getSchemaManager()->createSchema(); - $statements = ['SET FOREIGN_KEY_CHECKS=0']; + $statements = []; // reverse table order for clean-up (due to FKs) $tables = array_reverse($newSchema->getTables()); - // cleanup pre-existing database + if ($databasePlatform->supportsForeignKeyConstraints()) { + // cleanup pre-existing database: drop foreign keys + foreach ($tables as $table) { + if ($existingSchema->hasTable($table->getName())) { + foreach($this->db->getSchemaManager()->listTableForeignKeys($table->getName()) as $foreignKeyConstraint) { + $statements[] = $databasePlatform->getDropForeignKeySQL($foreignKeyConstraint->getName(), $table->getName()); + } + } + } + } + // cleanup pre-existing database: drop tables foreach ($tables as $table) { if ($existingSchema->hasTable($table->getName())) { $statements[] = $databasePlatform->getDropTableSQL($table); From 29a684f8038cde1b9feb685178a0f2f1fa25c452 Mon Sep 17 00:00:00 2001 From: Adrien Dupuis <61695653+adriendupuis@users.noreply.github.com> Date: Thu, 20 Feb 2025 18:24:39 +0100 Subject: [PATCH 4/6] InstallPlatformCommand.php: Fix CS --- .../RepositoryInstaller/Command/InstallPlatformCommand.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bundle/RepositoryInstaller/Command/InstallPlatformCommand.php b/src/bundle/RepositoryInstaller/Command/InstallPlatformCommand.php index 8cdb8239b3..851cf972dc 100644 --- a/src/bundle/RepositoryInstaller/Command/InstallPlatformCommand.php +++ b/src/bundle/RepositoryInstaller/Command/InstallPlatformCommand.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ + namespace Ibexa\Bundle\RepositoryInstaller\Command; use Doctrine\DBAL\Connection; From dabd45cb191cc91cf283d10c7e8755690f8efa50 Mon Sep 17 00:00:00 2001 From: Adrien Dupuis <61695653+adriendupuis@users.noreply.github.com> Date: Thu, 20 Feb 2025 19:07:34 +0100 Subject: [PATCH 5/6] Fix CS --- .../RepositoryInstaller/Command/InstallPlatformCommand.php | 1 - src/bundle/RepositoryInstaller/Installer/CoreInstaller.php | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/bundle/RepositoryInstaller/Command/InstallPlatformCommand.php b/src/bundle/RepositoryInstaller/Command/InstallPlatformCommand.php index 851cf972dc..8cdb8239b3 100644 --- a/src/bundle/RepositoryInstaller/Command/InstallPlatformCommand.php +++ b/src/bundle/RepositoryInstaller/Command/InstallPlatformCommand.php @@ -4,7 +4,6 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ - namespace Ibexa\Bundle\RepositoryInstaller\Command; use Doctrine\DBAL\Connection; diff --git a/src/bundle/RepositoryInstaller/Installer/CoreInstaller.php b/src/bundle/RepositoryInstaller/Installer/CoreInstaller.php index d21a9f4519..f7da4fc459 100644 --- a/src/bundle/RepositoryInstaller/Installer/CoreInstaller.php +++ b/src/bundle/RepositoryInstaller/Installer/CoreInstaller.php @@ -105,7 +105,7 @@ protected function getDropSqlStatementsForExistingSchema( // cleanup pre-existing database: drop foreign keys foreach ($tables as $table) { if ($existingSchema->hasTable($table->getName())) { - foreach($this->db->getSchemaManager()->listTableForeignKeys($table->getName()) as $foreignKeyConstraint) { + foreach ($this->db->getSchemaManager()->listTableForeignKeys($table->getName()) as $foreignKeyConstraint) { $statements[] = $databasePlatform->getDropForeignKeySQL($foreignKeyConstraint->getName(), $table->getName()); } } From da2fe071c9cff875f2d12e2a012bd22a60ca73db Mon Sep 17 00:00:00 2001 From: Adrien Dupuis <61695653+adriendupuis@users.noreply.github.com> Date: Thu, 20 Feb 2025 19:15:58 +0100 Subject: [PATCH 6/6] CoreInstaller.php: No need to rv table order If written only for FKs, it didn't work. --- src/bundle/RepositoryInstaller/Installer/CoreInstaller.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/bundle/RepositoryInstaller/Installer/CoreInstaller.php b/src/bundle/RepositoryInstaller/Installer/CoreInstaller.php index f7da4fc459..fbfe5c31a0 100644 --- a/src/bundle/RepositoryInstaller/Installer/CoreInstaller.php +++ b/src/bundle/RepositoryInstaller/Installer/CoreInstaller.php @@ -99,8 +99,7 @@ protected function getDropSqlStatementsForExistingSchema( ): array { $existingSchema = $this->db->getSchemaManager()->createSchema(); $statements = []; - // reverse table order for clean-up (due to FKs) - $tables = array_reverse($newSchema->getTables()); + $tables = $newSchema->getTables(); if ($databasePlatform->supportsForeignKeyConstraints()) { // cleanup pre-existing database: drop foreign keys foreach ($tables as $table) {