From 89d178d7468d360123bf7b6c4b7aad8704c86722 Mon Sep 17 00:00:00 2001 From: Jay Date: Thu, 5 Nov 2020 12:50:44 +0100 Subject: [PATCH 1/4] feat: inform user about invalid parent directory --- mmlc_installer.php | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/mmlc_installer.php b/mmlc_installer.php index 34cb1c44..3bb0af81 100644 --- a/mmlc_installer.php +++ b/mmlc_installer.php @@ -37,6 +37,10 @@ public function invokeIndex() if ($errors) { echo Template::showSystemCheck($errors); } else if (!$this->isInstalled()) { + if (!$this->isInShopRoot()) { + echo Template::showInvalidRoot(); + } + echo Template::showInstall(); } else { echo Template::showInstalled(); @@ -93,6 +97,33 @@ public function isInstalled() return false; } + public function isInShopRoot() + { + /** + * Check whether the installer is in the root directory + */ + $shopRoot = [ + 'api', + 'callback', + 'images', + 'inc', + 'includes', + 'lang', + 'templates', + 'templates_c', + ]; + $installerIsInShopRoot = true; + + foreach ($shopRoot as $shopDirectory) { + if (!is_dir($shopDirectory)) { + $installerIsInShopRoot = false; + break; + } + } + + return $installerIsInShopRoot; + } + public function download() { $remoteAddress = self::REMOTE_ADDRESS . self::INSTALL_FILE; @@ -301,6 +332,16 @@ public static function showInstallDone() '; } + public static function showInvalidRoot() + { + return + self::style() . ' +
+

Warning: Invalid Install-Directory!

+
+ '; + } + public static function style() { return ' From e828276cfb6074b8247cb867a1d4d4951c0e8aca Mon Sep 17 00:00:00 2001 From: Jay Date: Thu, 5 Nov 2020 13:29:33 +0100 Subject: [PATCH 2/4] refactor: directory is checked in doSystemCheck() --- mmlc_installer.php | 46 +++++----------------------------------------- 1 file changed, 5 insertions(+), 41 deletions(-) diff --git a/mmlc_installer.php b/mmlc_installer.php index 3bb0af81..15c7c4ed 100644 --- a/mmlc_installer.php +++ b/mmlc_installer.php @@ -37,10 +37,6 @@ public function invokeIndex() if ($errors) { echo Template::showSystemCheck($errors); } else if (!$this->isInstalled()) { - if (!$this->isInShopRoot()) { - echo Template::showInvalidRoot(); - } - echo Template::showInstall(); } else { echo Template::showInstalled(); @@ -50,6 +46,7 @@ public function invokeIndex() public function doSystemCheck() { $errors = []; + if (!ini_get('allow_url_fopen')) { $errors[] = 'No connection to server. allow_url_fopen has to be activated in php.ini.'; } @@ -58,6 +55,10 @@ public function doSystemCheck() $errors[] = 'Current PHP version is ' . PHP_VERSION . '. The MMLC needs version ' . self::REQUIRED_PHP_VERSION . ' or higher.'; } + if (!file_exists('/includes/classes/modified_api.php')) { + $errors[] = __DIR__ . 'is the wrong installation directory. Please use the shop root.'; + } + return $errors; } @@ -97,33 +98,6 @@ public function isInstalled() return false; } - public function isInShopRoot() - { - /** - * Check whether the installer is in the root directory - */ - $shopRoot = [ - 'api', - 'callback', - 'images', - 'inc', - 'includes', - 'lang', - 'templates', - 'templates_c', - ]; - $installerIsInShopRoot = true; - - foreach ($shopRoot as $shopDirectory) { - if (!is_dir($shopDirectory)) { - $installerIsInShopRoot = false; - break; - } - } - - return $installerIsInShopRoot; - } - public function download() { $remoteAddress = self::REMOTE_ADDRESS . self::INSTALL_FILE; @@ -332,16 +306,6 @@ public static function showInstallDone() '; } - public static function showInvalidRoot() - { - return - self::style() . ' -
-

Warning: Invalid Install-Directory!

-
- '; - } - public static function style() { return ' From 20c6c9bc3dbd6b5d37841c827348525e53b03f17 Mon Sep 17 00:00:00 2001 From: Jay Date: Thu, 5 Nov 2020 13:45:55 +0100 Subject: [PATCH 3/4] style: show directory in code block --- mmlc_installer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mmlc_installer.php b/mmlc_installer.php index 15c7c4ed..7d8380c2 100644 --- a/mmlc_installer.php +++ b/mmlc_installer.php @@ -56,7 +56,7 @@ public function doSystemCheck() } if (!file_exists('/includes/classes/modified_api.php')) { - $errors[] = __DIR__ . 'is the wrong installation directory. Please use the shop root.'; + $errors[] = '' . __DIR__ . ' is the wrong installation directory. Please use the shop root.'; } return $errors; From 0f4d2589e442f0561fe90812f8f59c0da6b8889b Mon Sep 17 00:00:00 2001 From: Jay Date: Thu, 5 Nov 2020 13:47:05 +0100 Subject: [PATCH 4/4] refactor: directory check with absolute path --- mmlc_installer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mmlc_installer.php b/mmlc_installer.php index 7d8380c2..ee8cad68 100644 --- a/mmlc_installer.php +++ b/mmlc_installer.php @@ -55,7 +55,7 @@ public function doSystemCheck() $errors[] = 'Current PHP version is ' . PHP_VERSION . '. The MMLC needs version ' . self::REQUIRED_PHP_VERSION . ' or higher.'; } - if (!file_exists('/includes/classes/modified_api.php')) { + if (!file_exists(__DIR__ . '/includes/classes/modified_api.php')) { $errors[] = '' . __DIR__ . ' is the wrong installation directory. Please use the shop root.'; }