Skip to content

Commit

Permalink
Apply migration files that are called install-X.X.X.php
Browse files Browse the repository at this point in the history
  • Loading branch information
Quetzacoalt91 committed Sep 4, 2024
1 parent 25af9df commit 02f23b8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions classes/UpgradeTools/Module/ModuleMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
14 changes: 8 additions & 6 deletions tests/unit/UpgradeTools/Module/ModuleMigrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 02f23b8

Please sign in to comment.