button fix, kernel update
This commit is contained in:
@ -2,20 +2,24 @@
|
||||
|
||||
namespace kernel\services;
|
||||
|
||||
use DirectoryIterator;
|
||||
use kernel\helpers\Debug;
|
||||
use kernel\helpers\Manifest;
|
||||
use kernel\helpers\RESTClient;
|
||||
use kernel\models\Option;
|
||||
|
||||
class AdminThemeService
|
||||
{
|
||||
protected Option $option;
|
||||
protected string $active_theme;
|
||||
protected ModuleService $moduleService;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->option = new Option();
|
||||
$this->findActiveAdminTheme();
|
||||
$this->moduleService = new ModuleService();
|
||||
}
|
||||
|
||||
public function findActiveAdminTheme(): void
|
||||
@ -56,4 +60,43 @@ class AdminThemeService
|
||||
return $info;
|
||||
}
|
||||
|
||||
public function isInstall(string $slug): bool
|
||||
{
|
||||
$adminThemePaths = Option::where("key", "admin_theme_paths")->first();
|
||||
$dirs = [];
|
||||
if ($adminThemePaths) {
|
||||
$path = json_decode($adminThemePaths->value);
|
||||
foreach ($path->paths as $p) {
|
||||
$dirs[] = getConst($p);
|
||||
}
|
||||
}
|
||||
foreach ($dirs as $dir) {
|
||||
foreach (new DirectoryIterator($dir) as $fileInfo) {
|
||||
if ($fileInfo->isDot()) continue;
|
||||
if ($this->getAdminThemeInfo($fileInfo->getPathname())['slug'] === $slug) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function isLastVersion(string $slug): bool
|
||||
{
|
||||
if ($this->moduleService->isServerAvailable()) {
|
||||
$modules_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug');
|
||||
|
||||
$modules_info = json_decode($modules_info->getBody()->getContents(), true);
|
||||
|
||||
$themeInfo = $this->getAdminThemeInfo($slug);
|
||||
foreach ($modules_info as $mod) {
|
||||
if ($mod['slug'] === $themeInfo['slug'] && $mod['version'] === $themeInfo['version']) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
99
kernel/services/KernelService.php
Normal file
99
kernel/services/KernelService.php
Normal file
@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\services;
|
||||
|
||||
use kernel\helpers\Debug;
|
||||
use kernel\helpers\Files;
|
||||
use kernel\helpers\Manifest;
|
||||
use kernel\helpers\RESTClient;
|
||||
use kernel\helpers\Version;
|
||||
use kernel\Request;
|
||||
use ZipArchive;
|
||||
|
||||
class KernelService
|
||||
{
|
||||
protected null|bool $serverAvailable = null;
|
||||
protected ModuleService $moduleService;
|
||||
protected Files $files;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->moduleService = new ModuleService();
|
||||
$this->files = new Files();
|
||||
}
|
||||
|
||||
public function getKernelInfo(): false|array|string
|
||||
{
|
||||
$info = [];
|
||||
$info['path'] = KERNEL_DIR;
|
||||
if (file_exists(KERNEL_DIR . "/manifest.json")) {
|
||||
$manifest = json_decode(file_get_contents(KERNEL_DIR . "/manifest.json"), true);
|
||||
$manifest = getConst($manifest);
|
||||
$info = array_merge($info, $manifest);
|
||||
}
|
||||
|
||||
return $info;
|
||||
}
|
||||
|
||||
public function isLastVersion(): bool
|
||||
{
|
||||
if ($this->moduleService->isServerAvailable()) {
|
||||
$modules_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug');
|
||||
|
||||
$modules_info = json_decode($modules_info->getBody()->getContents(), true);
|
||||
|
||||
$kernel_info = $this->getKernelInfo();
|
||||
|
||||
$kernelVersion = Version::getIntVersionByString($kernel_info['version']);
|
||||
|
||||
foreach ($modules_info as $mod) {
|
||||
$modVersion = Version::getIntVersionByString($mod['version']);
|
||||
if ($mod['slug'] === $kernel_info['slug'] && $modVersion <= $kernelVersion) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function updateKernel(string $path): bool
|
||||
{
|
||||
$request = new Request();
|
||||
$files = $request->post('files');
|
||||
|
||||
$zip = new ZipArchive;
|
||||
if (file_exists(ROOT_DIR . $path)) {
|
||||
$tmpKernelDir = md5(time());
|
||||
$res = $zip->open(ROOT_DIR . $path);
|
||||
if ($res === TRUE) {
|
||||
$tmpKernelDirFull = RESOURCES_DIR . '/tmp/kernel/' . $tmpKernelDir . "/";
|
||||
$zip->extractTo($tmpKernelDirFull);
|
||||
$zip->close();
|
||||
$this->files->recursiveRemoveKernelDir();
|
||||
$this->files->copyKernelFolder($tmpKernelDirFull . 'kernel' , ROOT_DIR . "/kernel");
|
||||
|
||||
foreach ($files as $file) {
|
||||
if ($file === 'bootstrap.php') {
|
||||
$this->files->recursiveRemoveDir(ROOT_DIR . '/bootstrap');
|
||||
$this->files->copyKernelFolder($tmpKernelDirFull . 'bootstrap' , ROOT_DIR . '/bootstrap');
|
||||
}
|
||||
if ($file === 'env.example') {
|
||||
copy($tmpKernelDirFull . $file , ROOT_DIR . '/.' . $file);
|
||||
chmod(ROOT_DIR . '/.' . $file, 0775);
|
||||
continue;
|
||||
}
|
||||
copy($tmpKernelDirFull . $file , ROOT_DIR . '/' . $file);
|
||||
chmod(ROOT_DIR . '/' . $file, 0775);
|
||||
}
|
||||
|
||||
$this->files->recursiveRemoveDir($tmpKernelDirFull);
|
||||
unlink(ROOT_DIR . $path);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -9,8 +9,8 @@ use kernel\helpers\Debug;
|
||||
use kernel\helpers\Files;
|
||||
use kernel\helpers\Manifest;
|
||||
use kernel\helpers\RESTClient;
|
||||
use kernel\helpers\Version;
|
||||
use kernel\models\Option;
|
||||
use MongoDB\Driver\Session;
|
||||
use ZipArchive;
|
||||
|
||||
class ModuleService
|
||||
@ -308,7 +308,12 @@ class ModuleService
|
||||
$manifest = Manifest::getWithVars($manifestJson);
|
||||
|
||||
$fileHelper = new Files();
|
||||
$fileHelper->copy_folder($tmpModuleDirFull . 'app', $manifest['app_module_path']);
|
||||
if (isset($manifest['app_module_path'])) {
|
||||
$fileHelper->copy_folder($tmpModuleDirFull . 'app', $manifest['app_module_path']);
|
||||
} else {
|
||||
$fileHelper->copy_folder($tmpModuleDirFull . 'app', APP_DIR . '/modules/' . $manifest['slug']);
|
||||
}
|
||||
|
||||
if (isset($manifest['kernel_module_path'])) {
|
||||
$fileHelper->copy_folder($tmpModuleDirFull . 'kernel', $manifest['kernel_module_path']);
|
||||
} else {
|
||||
@ -316,6 +321,7 @@ class ModuleService
|
||||
}
|
||||
|
||||
$fileHelper->recursiveRemoveDir($tmpModuleDirFull);
|
||||
unlink(ROOT_DIR . $path);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -392,8 +398,12 @@ class ModuleService
|
||||
$manifest = Manifest::getWithVars($manifestJson);
|
||||
|
||||
$fileHelper = new Files();
|
||||
if (isset($manifest['app_module_path'])) {
|
||||
$fileHelper->copy_folder($tmpModuleDirFull . 'app/manifest.json', $manifest['app_module_path'] . '/manifest.json');
|
||||
} else {
|
||||
$fileHelper->copy_folder($tmpModuleDirFull . 'app/manifest.json', APP_DIR . '/modules/' . $manifest['slug'] . '/manifest.json');
|
||||
}
|
||||
|
||||
$fileHelper->copy_folder($tmpModuleDirFull . 'app/manifest.json', $manifest['app_module_path'] . '/manifest.json');
|
||||
if (isset($manifest['kernel_module_path'])) {
|
||||
$fileHelper->copy_folder($tmpModuleDirFull . 'kernel', $manifest['kernel_module_path']);
|
||||
} else {
|
||||
@ -401,6 +411,8 @@ class ModuleService
|
||||
}
|
||||
$fileHelper->recursiveRemoveDir($tmpModuleDirFull);
|
||||
|
||||
unlink(ROOT_DIR . $path);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -448,9 +460,13 @@ class ModuleService
|
||||
$modules_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug');
|
||||
|
||||
$modules_info = json_decode($modules_info->getBody()->getContents(), true);
|
||||
|
||||
$mod_info = $this->getModuleInfoBySlug($slug);
|
||||
|
||||
$currentVersion = Version::getIntVersionByString($mod_info['version']);
|
||||
foreach ($modules_info as $mod) {
|
||||
if ($mod['slug'] === $mod_info['slug'] && $mod['version'] === $mod_info['version']) {
|
||||
$modVersion = Version::getIntVersionByString($mod['version']);
|
||||
if ($mod['slug'] === $mod_info['slug'] && $modVersion <= $currentVersion) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user