From 17ec5b95fc54a7f17fb64f3a9288524afbe0acf9 Mon Sep 17 00:00:00 2001 From: Robin Wieschendorf Date: Wed, 29 Mar 2023 08:16:51 +0200 Subject: [PATCH 1/5] feat: add new TYPE consts to class Notification --- src/Classes/Notification.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Classes/Notification.php b/src/Classes/Notification.php index 46776c38..e787c919 100644 --- a/src/Classes/Notification.php +++ b/src/Classes/Notification.php @@ -15,6 +15,9 @@ class Notification { + public const TYPE_ERROR = 'error'; + public const TYPE_WARNING = 'warning'; + private const MMLC_SESSION_NAME = 'mmlc'; /** From 5fa7ea76704ba8d282cc7f791188e3d87cae39dc Mon Sep 17 00:00:00 2001 From: Robin Wieschendorf Date: Wed, 29 Mar 2023 08:17:37 +0200 Subject: [PATCH 2/5] feat: show notification on SelfUpdate template --- src/Templates/SelfUpdate.tmpl.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Templates/SelfUpdate.tmpl.php b/src/Templates/SelfUpdate.tmpl.php index 206d3eb4..d5094d1f 100644 --- a/src/Templates/SelfUpdate.tmpl.php +++ b/src/Templates/SelfUpdate.tmpl.php @@ -2,7 +2,9 @@ defined('LOADED_FROM_INDEX') && LOADED_FROM_INDEX ?? die('Access denied.'); use RobinTheHood\ModifiedModuleLoaderClient\Config; +use RobinTheHood\ModifiedModuleLoaderClient\ViewModels\NotificationViewModel; +$notificationView = new NotificationViewModel(); ?> @@ -15,6 +17,8 @@
+ renderFlashMessages() ?> +

MMLC - Modified Module Loader Client



From 668c1f14083a93fa777feaa65ae61a41ff29ac52 Mon Sep 17 00:00:00 2001 From: Robin Wieschendorf Date: Wed, 29 Mar 2023 08:20:10 +0200 Subject: [PATCH 3/5] feat: add and use method systemCheck() in class SelfUpdater --- src/Classes/SelfUpdater.php | 44 ++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/src/Classes/SelfUpdater.php b/src/Classes/SelfUpdater.php index bfe15cbe..43b174cf 100644 --- a/src/Classes/SelfUpdater.php +++ b/src/Classes/SelfUpdater.php @@ -98,13 +98,25 @@ public function update(MmlcVersionInfo $mmlcVersionInfo): void $this->createRestore($mmlcVersionInfo); $this->download($mmlcVersionInfo); - $this->backup($mmlcVersionInfo); $this->untar($mmlcVersionInfo); $this->verifyUntar($mmlcVersionInfo); - $this->install($mmlcVersionInfo); - $this->setupConfig($mmlcVersionInfo); - $this->setupVersion($mmlcVersionInfo); - $this->verifyUpdate($mmlcVersionInfo); + + $check = $this->systemCheck($mmlcVersionInfo); + + if ($check['result'] === 'passed') { + $this->backup($mmlcVersionInfo); + $this->install($mmlcVersionInfo); + $this->setupConfig($mmlcVersionInfo); + $this->setupVersion($mmlcVersionInfo); + $this->verifyUpdate($mmlcVersionInfo); + } else { + Notification::pushFlashMessage([ + 'text' => "Can not update MMLC. Not all system requirements are met.", + 'type' => Notification::TYPE_ERROR + ]); + } + + $this->remove($mmlcVersionInfo); $this->removeRestore($mmlcVersionInfo); opcache_reset(); @@ -216,7 +228,11 @@ private function install(MmlcVersionInfo $mmlcVersionInfo): void $files = FileHelper::scanDir($srcPath, FileHelper::FILES_AND_DIRS, true); FileHelper::moveFilesTo($files, $srcPath, $destPath); + } + private function remove(MmlcVersionInfo $mmlcVersionInfo): void + { + $srcPath = $this->appRoot . '/ModifiedModuleLoaderClient'; system('rm -rf ' . $srcPath); } @@ -285,6 +301,24 @@ private function verifyUpdate(MmlcVersionInfo $mmlcVersionInfo): bool return true; } + private function systemCheck(MmlcVersionInfo $mmlcVersionInfo): array + { + return [ + 'result' => 'passed' + ]; + + return [ + 'result' => 'failed', + 'checks' => [ + 'php' => [ + 'is' => '7.0.4', + 'require' => '^8.0', + 'result' => 'failed' + ] + ] + ]; + } + private function postUpdateSteps(): void { // Vor der Version 1.12.0 haben sich die config.php und die version.json From ce7cc43153aecd82d32b0e776aeaf28924a62c07 Mon Sep 17 00:00:00 2001 From: Robin Wieschendorf Date: Wed, 29 Mar 2023 18:41:55 +0200 Subject: [PATCH 4/5] feat: add class SystemCheck --- src/Classes/SystemCheck.php | 45 +++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/Classes/SystemCheck.php diff --git a/src/Classes/SystemCheck.php b/src/Classes/SystemCheck.php new file mode 100644 index 00000000..707c28f0 --- /dev/null +++ b/src/Classes/SystemCheck.php @@ -0,0 +1,45 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace RobinTheHood\ModifiedModuleLoaderClient; + +class SystemCheck +{ + public const RESULT_PASSED = 'passed'; + public const RESULT_FAILED = 'failed'; + + public const REQUIRED_PHP_VERSION = '7.4.0'; + + public function check(array $options = []): array + { + $php = [ + 'is' => PHP_VERSION, + 'require' => '>=' . self::REQUIRED_PHP_VERSION, + ]; + + if (version_compare(PHP_VERSION, self::REQUIRED_PHP_VERSION, '<')) { + $php['result'] = self::RESULT_FAILED; + $result = self::RESULT_FAILED; + } else { + $php['result'] = self::RESULT_PASSED; + $result = self::RESULT_PASSED; + } + + return [ + 'result' => $result, + 'checks' => [ + 'php' => $php + ] + ]; + } +} From 62b3230e5b5962047e95c494fed51578da41ea53 Mon Sep 17 00:00:00 2001 From: Robin Wieschendorf Date: Wed, 29 Mar 2023 18:42:38 +0200 Subject: [PATCH 5/5] feat: use new class SystemCheck in SelfUpdater --- src/Classes/SelfUpdater.php | 66 ++++++++++++++++++++++++++----------- 1 file changed, 46 insertions(+), 20 deletions(-) diff --git a/src/Classes/SelfUpdater.php b/src/Classes/SelfUpdater.php index 43b174cf..9115e9be 100644 --- a/src/Classes/SelfUpdater.php +++ b/src/Classes/SelfUpdater.php @@ -21,6 +21,8 @@ use RobinTheHood\ModifiedModuleLoaderClient\Api\V1\HttpRequest; use RobinTheHood\ModifiedModuleLoaderClient\Semver\Filter; use RobinTheHood\ModifiedModuleLoaderClient\Semver\Sorter; +use RuntimeException; +use Throwable; class SelfUpdater { @@ -103,17 +105,12 @@ public function update(MmlcVersionInfo $mmlcVersionInfo): void $check = $this->systemCheck($mmlcVersionInfo); - if ($check['result'] === 'passed') { + if ($check) { $this->backup($mmlcVersionInfo); $this->install($mmlcVersionInfo); $this->setupConfig($mmlcVersionInfo); $this->setupVersion($mmlcVersionInfo); $this->verifyUpdate($mmlcVersionInfo); - } else { - Notification::pushFlashMessage([ - 'text' => "Can not update MMLC. Not all system requirements are met.", - 'type' => Notification::TYPE_ERROR - ]); } $this->remove($mmlcVersionInfo); @@ -301,22 +298,51 @@ private function verifyUpdate(MmlcVersionInfo $mmlcVersionInfo): bool return true; } - private function systemCheck(MmlcVersionInfo $mmlcVersionInfo): array + private function systemCheck(MmlcVersionInfo $mmlcVersionInfo): bool { - return [ - 'result' => 'passed' - ]; + try { + $systemCheck = $this->getSystemCheckObj(); + $check = $systemCheck->check(); + if ($check['result'] === 'passed') { + return true; + } else { + Notification::pushFlashMessage([ + 'text' => "Update canceled - Can not update MMLC. Not all system requirements are met.
\n" + . json_encode($check['checks'], JSON_PRETTY_PRINT), + 'type' => Notification::TYPE_ERROR + ]); + } + } catch (RuntimeException $e) { + Notification::pushFlashMessage([ + 'text' => "Update canceled - " . $e->getMessage(), + 'type' => Notification::TYPE_ERROR + ]); + } - return [ - 'result' => 'failed', - 'checks' => [ - 'php' => [ - 'is' => '7.0.4', - 'require' => '^8.0', - 'result' => 'failed' - ] - ] - ]; + return false; + } + + private function getSystemCheckObj() + { + $systemCheckFilePath = $this->appRoot . '/ModifiedModuleLoaderClient/src/Classes/SystemCheck.php'; + // $systemCheckFilePath = $this->appRoot . '/src/Classes/SystemCheck.php'; // Für Testzwecke + + if (!file_exists($systemCheckFilePath)) { + throw new RuntimeException("Can not find file $systemCheckFilePath in downloaded .tar file"); + } + + try { + $fileContent = file_get_contents($systemCheckFilePath); + $fileContent = str_replace('class SystemCheck', 'class SystemCheckNew', $fileContent); + $fileContent = str_replace('