From 6348b1079d2804b956e398ea26e8d85576cfd5b7 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 4 Jul 2023 10:31:01 +0200 Subject: [PATCH] Prevent exception due to missing database columns in update wizard (#29) --- Classes/Updates/MigrateOldLocations.php | 51 +++++++++++++++++++------ Documentation/Changelog/3.4.0.rst | 5 +++ 2 files changed, 44 insertions(+), 12 deletions(-) diff --git a/Classes/Updates/MigrateOldLocations.php b/Classes/Updates/MigrateOldLocations.php index abbe0b9..bcd4cde 100644 --- a/Classes/Updates/MigrateOldLocations.php +++ b/Classes/Updates/MigrateOldLocations.php @@ -75,7 +75,8 @@ class MigrateOldLocations implements UpgradeWizardInterface public function updateNecessary(): bool { - return $this->getQueryBuilder() + return $this->hasOldColumns() + && $this->getQueryBuilder() ->count('*') ->execute() ->fetchOne() > 0 @@ -219,17 +220,8 @@ class MigrateOldLocations implements UpgradeWizardInterface private function getQueryBuilder(): QueryBuilder { - $columns = [ - 'name', - 'street', - 'district', - 'city', - 'zip', - 'country', - 'phone', - 'latitude', - 'longitude', - ]; + $columns = $this->columnsToFetch(); + $qb = $this->connectionPool->getQueryBuilderForTable('tx_events_domain_model_event'); $qb->getRestrictions()->removeAll(); $qb->select(...$columns); @@ -257,6 +249,41 @@ class MigrateOldLocations implements UpgradeWizardInterface ]; } + private function hasOldColumns(): bool + { + $schema = $this->connectionPool + ->getConnectionForTable('tx_events_domain_model_event') + ->getSchemaManager() + ->createSchema() + ->getTable('tx_events_domain_model_event'); + + foreach ($this->columnsToFetch() as $column) { + if ($schema->hasColumn($column) === false) { + return false; + } + } + + return true; + } + + /** + * @return string[] + */ + private function columnsToFetch(): array + { + return [ + 'name', + 'street', + 'district', + 'city', + 'zip', + 'country', + 'phone', + 'latitude', + 'longitude', + ]; + } + public static function register(): void { $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update'][self::class] = self::class; diff --git a/Documentation/Changelog/3.4.0.rst b/Documentation/Changelog/3.4.0.rst index b417110..468656b 100644 --- a/Documentation/Changelog/3.4.0.rst +++ b/Documentation/Changelog/3.4.0.rst @@ -69,6 +69,11 @@ Fixes There are now two database queries and the logic is moved to PHP. Furthermore, the test cases were extended with another situation. +* Do not break update wizard due to missing columns. + The existing update wizard expects old columns to exist in order to migrate data. + Those might not exist in newer systems where migration is not necessary. + The wizard now properly checks for existence before querying the data. + Tasks -----