From ef2b124fa19cb52726089518682a24be63d379b7 Mon Sep 17 00:00:00 2001 From: Robin Wieschendorf Date: Mon, 19 Jun 2023 16:05:55 +0200 Subject: [PATCH 1/2] feat: detect when MMLC is installed via git and show a note --- src/Classes/IndexController.php | 43 +++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/Classes/IndexController.php b/src/Classes/IndexController.php index f78622e0..2dd9e7a0 100644 --- a/src/Classes/IndexController.php +++ b/src/Classes/IndexController.php @@ -137,6 +137,19 @@ public function invokeSelfUpdate() return $accessRedirect; } + $gitBranch = $this->getCurrentGitBranch(App::getRoot() . '/.git'); + + if ($gitBranch) { + Notification::pushFlashMessage([ + 'text' => + 'Der MMLC wurde über Git installiert.
+ 🔀 Branch: ' . $gitBranch . '
+ Bitte führe die Aktualisierung des MMLC über Git durch. Beachte, dass ein Update über den MMLC + möglicherweise zu Fehlern führen kann.', + 'type' => 'warning' + ]); + } + // Nächste mögliche MMLC Version ermittlen $latest = Config::getSelfUpdate() == 'latest'; $installedMmlcVersionString = App::getMmlcVersion(); @@ -737,4 +750,34 @@ private function addModuleNotFoundNotification($archiveName, $version = '') 'type' => 'error' ]); } + + private function getCurrentGitBranch(string $gitPath): ?string + { + if (!is_dir($gitPath)) { + return null; + } + + $os = strtoupper(substr(PHP_OS, 0, 3)); + $command = ''; + + switch ($os) { + case 'WIN': + $command = 'cd /d "' . $gitPath . '" & git symbolic-ref --short HEAD 2>NUL'; + break; + case 'LIN': + case 'DAR': + $command = 'cd "' . $gitPath . '" && git symbolic-ref --short HEAD 2>/dev/null'; + break; + default: + return 'unkown branch'; + } + + $output = trim(shell_exec($command)); + + if (empty($output)) { + return null; + } + + return $output; + } } From 004635c98fcb6a17c78cb570d81cf6f87ea41137 Mon Sep 17 00:00:00 2001 From: Robin Wieschendorf Date: Mon, 19 Jun 2023 20:13:08 +0200 Subject: [PATCH 2/2] fix: psalm errors --- psalm-baseline.xml | 13 ++++--------- src/Classes/IndexController.php | 2 +- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index bdace0a4..4cbddfa9 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,19 +1,14 @@ - + $configuration - - - false - - - $module - - + + shell_exec($command) + getChangeLogMd getInstallationMd diff --git a/src/Classes/IndexController.php b/src/Classes/IndexController.php index 2dd9e7a0..a6bec6b8 100644 --- a/src/Classes/IndexController.php +++ b/src/Classes/IndexController.php @@ -772,7 +772,7 @@ private function getCurrentGitBranch(string $gitPath): ?string return 'unkown branch'; } - $output = trim(shell_exec($command)); + $output = trim('' . shell_exec($command)); if (empty($output)) { return null;