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

Fix: Autoupgrade attempts to update non-installed modules, causing the upgrade process to fail #1036

Closed
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
27 changes: 15 additions & 12 deletions classes/Task/Update/UpdateModules.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,23 @@ public function run(): int
$moduleUnzipper->unzipModule($moduleUnzipperContext);

$dbVersion = (new ModuleVersionAdapter())->get($moduleInfos['name']);
$module = \Module::getInstanceByName($moduleInfos['name']);

if (!($module instanceof \Module)) {
throw (new UpgradeException($this->translator->trans('[WARNING] Error when trying to retrieve module %s instance.', [$moduleInfos['name']])))->setSeverity(UpgradeException::SEVERITY_WARNING);
if ($dbVersion !== '') {
$module = \Module::getInstanceByName($moduleInfos['name']);

if (!($module instanceof \Module)) {
throw (new UpgradeException($this->translator->trans('[WARNING] Error when trying to retrieve module %s instance.', [$moduleInfos['name']])))->setSeverity(UpgradeException::SEVERITY_WARNING);
}

$moduleMigrationContext = new ModuleMigrationContext($module, $dbVersion);

if (!$moduleMigration->needMigration($moduleMigrationContext)) {
$this->logger->info($this->translator->trans('Module %s does not need to be migrated. Module is up to date.', [$moduleInfos['name']]));
} else {
$moduleMigration->runMigration($moduleMigrationContext);
}
$moduleMigration->saveVersionInDb($moduleMigrationContext);
}

$moduleMigrationContext = new ModuleMigrationContext($module, $dbVersion);

if (!$moduleMigration->needMigration($moduleMigrationContext)) {
$this->logger->info($this->translator->trans('Module %s does not need to be migrated. Module is up to date.', [$moduleInfos['name']]));
} else {
$moduleMigration->runMigration($moduleMigrationContext);
}
$moduleMigration->saveVersionInDb($moduleMigrationContext);
}
} catch (UpgradeException $e) {
$this->handleException($e);
Expand Down