Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Classes/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

class Notification
{
public const TYPE_ERROR = 'error';
public const TYPE_WARNING = 'warning';

private const MMLC_SESSION_NAME = 'mmlc';

/**
Expand Down
70 changes: 65 additions & 5 deletions src/Classes/SelfUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -98,13 +100,20 @@ 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) {
$this->backup($mmlcVersionInfo);
$this->install($mmlcVersionInfo);
$this->setupConfig($mmlcVersionInfo);
$this->setupVersion($mmlcVersionInfo);
$this->verifyUpdate($mmlcVersionInfo);
}

$this->remove($mmlcVersionInfo);
$this->removeRestore($mmlcVersionInfo);

opcache_reset();
Expand Down Expand Up @@ -216,7 +225,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);
}

Expand Down Expand Up @@ -285,6 +298,53 @@ private function verifyUpdate(MmlcVersionInfo $mmlcVersionInfo): bool
return true;
}

private function systemCheck(MmlcVersionInfo $mmlcVersionInfo): bool
{
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.<br>\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 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('<?php', '', $fileContent);

eval($fileContent);

$classSystemCheckNew = 'RobinTheHood\ModifiedModuleLoaderClient\SystemCheckNew';
return new $classSystemCheckNew();
} catch (Throwable $t) {
throw new RuntimeException("Can not load file $systemCheckFilePath");
}
}

private function postUpdateSteps(): void
{
// Vor der Version 1.12.0 haben sich die config.php und die version.json
Expand Down
45 changes: 45 additions & 0 deletions src/Classes/SystemCheck.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

/*
* This file is part of MMLC - ModifiedModuleLoaderClient.
*
* (c) Robin Wieschendorf <mail@robinwieschendorf.de>
*
* 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
]
];
}
}
4 changes: 4 additions & 0 deletions src/Templates/SelfUpdate.tmpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
?>

<!DOCTYPE html>
Expand All @@ -15,6 +17,8 @@
<?php include 'Navi.tmpl.php' ?>

<div class="content" style="text-align: center">
<?= $notificationView->renderFlashMessages() ?>

<div class="self-update">
<h2>MMLC - Modified Module Loader Client</h2>
<?= $installedVersionString ?><br><br>
Expand Down