diff --git a/src/Classes/ShopInfo.php b/src/Classes/ShopInfo.php index 5d84b0c0..a8e5b852 100644 --- a/src/Classes/ShopInfo.php +++ b/src/Classes/ShopInfo.php @@ -27,14 +27,31 @@ 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 ''; + return 'unknown'; } $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; } 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