Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent exception due to missing database columns in update wizard #29

Merged
merged 1 commit into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 39 additions & 12 deletions Classes/Updates/MigrateOldLocations.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ public function getDescription(): string

public function updateNecessary(): bool
{
return $this->getQueryBuilder()
return $this->hasOldColumns()
&& $this->getQueryBuilder()
->count('*')
->execute()
->fetchOne() > 0
Expand Down Expand Up @@ -219,17 +220,8 @@ private function updateEvent(array $event): void

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);
Expand Down Expand Up @@ -257,6 +249,41 @@ public function getPrerequisites(): array
];
}

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;
Expand Down
5 changes: 5 additions & 0 deletions Documentation/Changelog/3.4.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----

Expand Down