From 1e67eb13149c694f899c134eb70ea737a5f56394 Mon Sep 17 00:00:00 2001 From: Jay Date: Thu, 22 Oct 2020 08:55:50 +0200 Subject: [PATCH 1/4] feat: determine mod version 2.0.1.0 and up --- src/Classes/ShopInfo.php | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Classes/ShopInfo.php b/src/Classes/ShopInfo.php index 5d84b0c0..3899f235 100644 --- a/src/Classes/ShopInfo.php +++ b/src/Classes/ShopInfo.php @@ -28,13 +28,31 @@ public static function getAdminPath() public static function getModifiedVersion(): string { $path = self::getAdminPath() .'/includes/version.php'; + if (!file_exists($path)) { - return ''; + return 'unbekannt'; } $fileStr = file_get_contents($path); $pos = strpos($fileStr, 'MOD_'); - $version = substr($fileStr, (int) $pos + 4, 7); + + if($pos) { + /** + * DB_VERSION exists in file + */ + $version = substr($fileStr, (int) $pos + 4, 7); + } + else { + /** + * DB_VERSION does not exists in file + * use PROJECT_MAJOR_VERSION and PROJECT_MINOR_VERSION instead + */ + preg_match('/MAJOR_VERSION.+?\'([\d\.]+)\'/', $fileStr, $versionMajor); + preg_match('/MINOR_VERSION.+?\'([\d\.]+)\'/', $fileStr, $versionMinor); + + $version = $versionMajor[1] . '.' . $versionMinor[1]; + } + return $version; } From 44b69e9dcf8170264184a0a799bf828ae11f323e Mon Sep 17 00:00:00 2001 From: Jay Date: Thu, 22 Oct 2020 10:38:18 +0200 Subject: [PATCH 2/4] refactor: apply coding style --- src/Classes/ShopInfo.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Classes/ShopInfo.php b/src/Classes/ShopInfo.php index 3899f235..692b6adf 100644 --- a/src/Classes/ShopInfo.php +++ b/src/Classes/ShopInfo.php @@ -36,13 +36,12 @@ public static function getModifiedVersion(): string $fileStr = file_get_contents($path); $pos = strpos($fileStr, 'MOD_'); - if($pos) { + if ($pos) { /** * DB_VERSION exists in file */ $version = substr($fileStr, (int) $pos + 4, 7); - } - else { + } else { /** * DB_VERSION does not exists in file * use PROJECT_MAJOR_VERSION and PROJECT_MINOR_VERSION instead From 3926db4c538a943adba6bdf6f5c4177a84af3c42 Mon Sep 17 00:00:00 2001 From: Jay Date: Thu, 22 Oct 2020 12:40:15 +0200 Subject: [PATCH 3/4] refactor: make output english --- src/Classes/ShopInfo.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Classes/ShopInfo.php b/src/Classes/ShopInfo.php index 692b6adf..a8e5b852 100644 --- a/src/Classes/ShopInfo.php +++ b/src/Classes/ShopInfo.php @@ -27,10 +27,10 @@ public static function getAdminPath() */ public static function getModifiedVersion(): string { - $path = self::getAdminPath() .'/includes/version.php'; + $path = self::getAdminPath() . '/includes/version.php'; if (!file_exists($path)) { - return 'unbekannt'; + return 'unknown'; } $fileStr = file_get_contents($path); From ae0e16a7a11ab8be18b49244caa97cdc0599416c Mon Sep 17 00:00:00 2001 From: Jay Date: Thu, 22 Oct 2020 13:54:13 +0200 Subject: [PATCH 4/4] test: update version --- tests/unit/RemoteModuleLoaderTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/unit/RemoteModuleLoaderTest.php b/tests/unit/RemoteModuleLoaderTest.php index e8ea5dd3..1a463a6c 100644 --- a/tests/unit/RemoteModuleLoaderTest.php +++ b/tests/unit/RemoteModuleLoaderTest.php @@ -30,7 +30,7 @@ public function testCanLoadAllVersions() { $apiRequest = new ApiRequest(); $modules = $this->loader->loadAllVersions(); - + $this->assertContainsOnlyInstancesOf(Module::class, $modules); $this->assertGreaterThan(150, count($modules)); @@ -72,15 +72,15 @@ public function testCanLoadLatestVersionByArchiveName() $module = $this->loader->loadLatestVersionByArchiveName('composer/autoload'); $this->assertEquals('composer/autoload', $module->getArchiveName()); - $this->assertEquals('1.1.0', $module->getVersion()); + $this->assertEquals('1.2.0', $module->getVersion()); } public function testCanLoadByArchiveNameAndVersion() { $apiRequest = new ApiRequest(); $module = $this->loader->loadLatestVersionByArchiveName('composer/autoload', '1.1.0'); - + $this->assertEquals('composer/autoload', $module->getArchiveName()); - $this->assertEquals('1.1.0', $module->getVersion()); + $this->assertEquals('1.2.0', $module->getVersion()); } } \ No newline at end of file