diff --git a/classes/UpgradeTools/Module/ModuleMigration.php b/classes/UpgradeTools/Module/ModuleMigration.php index ecf252f0d0..a69293329e 100644 --- a/classes/UpgradeTools/Module/ModuleMigration.php +++ b/classes/UpgradeTools/Module/ModuleMigration.php @@ -75,7 +75,7 @@ public function listUpgradeFiles(ModuleMigrationContext $moduleMigrationContext) $upgradeFiles = []; foreach ($files as $file) { - if (preg_match('/upgrade-(\d+(?:\.\d+){0,2}).php$/', basename($file), $matches)) { + if (preg_match('/(?:install|upgrade)-(\d+(?:\.\d+){0,2}).php$/', basename($file), $matches)) { $fileVersion = $matches[1]; if (version_compare($fileVersion, $moduleMigrationContext->getDbVersion(), '>') && version_compare($fileVersion, $moduleMigrationContext->getLocalVersion(), '<=')) { $upgradeFiles[] = ['file' => $file, 'version' => $fileVersion]; @@ -148,7 +148,7 @@ private function getUpgradeMethodName(string $filePath): string { $fileName = basename($filePath); - preg_match('/upgrade-([\d.]+)\.php$/', $fileName, $matches); + preg_match('/(?:install|upgrade)-([\d.]+)\.php$/', $fileName, $matches); $version = str_replace('.', '_', $matches[1]); diff --git a/tests/fixtures/mymodule/upgrade/upgrade-1.0.1.php b/tests/fixtures/mymodule/upgrade/upgrade-1.0.2.php similarity index 95% rename from tests/fixtures/mymodule/upgrade/upgrade-1.0.1.php rename to tests/fixtures/mymodule/upgrade/upgrade-1.0.2.php index 6797acedcd..c09468ddaa 100644 --- a/tests/fixtures/mymodule/upgrade/upgrade-1.0.1.php +++ b/tests/fixtures/mymodule/upgrade/upgrade-1.0.2.php @@ -23,7 +23,7 @@ * @copyright Since 2007 PrestaShop SA and Contributors * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) */ -function upgrade_module_1_0_1(Module $module): bool +function upgrade_module_1_0_2(Module $module): bool { return true; } diff --git a/tests/unit/UpgradeTools/Module/ModuleMigrationTest.php b/tests/unit/UpgradeTools/Module/ModuleMigrationTest.php index b1f758a411..5cae1c6187 100644 --- a/tests/unit/UpgradeTools/Module/ModuleMigrationTest.php +++ b/tests/unit/UpgradeTools/Module/ModuleMigrationTest.php @@ -137,7 +137,8 @@ public function testListUpgradeFilesWithDifferentVersionAndUpgradeFiles() $moduleMigrationContext = new ModuleMigrationContext($mymodule, $dbVersion); $this->assertEquals([ - __DIR__ . '/../../../fixtures/mymodule/upgrade/upgrade-1.0.1.php', + __DIR__ . '/../../../fixtures/mymodule/upgrade/install-1.0.1.php', + __DIR__ . '/../../../fixtures/mymodule/upgrade/upgrade-1.0.2.php', __DIR__ . '/../../../fixtures/mymodule/upgrade/upgrade-1.1.php', ], $this->moduleMigration->listUpgradeFiles($moduleMigrationContext)); } @@ -165,13 +166,14 @@ public function testRunMigrationWithXYZDifferentFiles() $this->moduleMigration->needMigration($moduleMigrationContext); - $this->logger->expects($this->exactly(4)) + $this->logger->expects($this->exactly(5)) ->method('notice') ->withConsecutive( - ['(1/4) Applying migration file upgrade-1.php.'], - ['(2/4) Applying migration file upgrade-1.0.1.php.'], - ['(3/4) Applying migration file upgrade-1.1.php.'], - ['(4/4) Applying migration file upgrade-1.1.1.php.'] + ['(1/5) Applying migration file upgrade-1.php.'], + ['(2/5) Applying migration file install-1.0.1.php.'], + ['(3/5) Applying migration file upgrade-1.0.2.php.'], + ['(4/5) Applying migration file upgrade-1.1.php.'], + ['(5/5) Applying migration file upgrade-1.1.1.php.'] ); $this->moduleMigration->runMigration($moduleMigrationContext);