kernel update

This commit is contained in:
2024-11-18 16:04:57 +03:00
parent 10605e17e7
commit 2af9ea876d
27 changed files with 434 additions and 91 deletions

View File

@ -3,9 +3,11 @@
namespace kernel\services;
use DirectoryIterator;
use GuzzleHttp\Client;
use kernel\helpers\Debug;
use kernel\helpers\Files;
use kernel\helpers\Manifest;
use kernel\helpers\RESTClient;
use kernel\models\Option;
use ZipArchive;
@ -281,7 +283,7 @@ class ModuleService
$tmpModuleDir = md5(time());
$res = $zip->open(ROOT_DIR . $path);
if ($res === TRUE) {
$tmpModuleDirFull = RESOURCES_DIR . '/tmp/ad/' . $tmpModuleDir . "/";
$tmpModuleDirFull = RESOURCES_DIR . '/tmp/modules/' . $tmpModuleDir . "/";
$zip->extractTo($tmpModuleDirFull);
$zip->close();
} else {
@ -289,20 +291,20 @@ class ModuleService
return false;
}
if (!file_exists($tmpModuleDirFull . "/app/manifest.json")) {
if (!file_exists($tmpModuleDirFull . "app/manifest.json")) {
$this->addError('manifest.json not found');
return false;
}
$manifestJson = getConst(file_get_contents($tmpModuleDirFull . "/app/manifest.json"));
$manifestJson = getConst(file_get_contents($tmpModuleDirFull . "app/manifest.json"));
$manifest = Manifest::getWithVars($manifestJson);
$fileHelper = new Files();
$fileHelper->copy_folder($tmpModuleDirFull . '/app', $manifest['app_module_path']);
$fileHelper->copy_folder($tmpModuleDirFull . 'app', $manifest['app_module_path']);
if (isset($manifest['kernel_module_path'])) {
$fileHelper->copy_folder($tmpModuleDirFull . '/kernel', $manifest['kernel_module_path']);
$fileHelper->copy_folder($tmpModuleDirFull . 'kernel', $manifest['kernel_module_path']);
} else {
$fileHelper->copy_folder($tmpModuleDirFull . '/kernel', KERNEL_APP_MODULES_DIR . '/' . $manifest['slug']);
$fileHelper->copy_folder($tmpModuleDirFull . 'kernel', KERNEL_APP_MODULES_DIR . '/' . $manifest['slug']);
}
$fileHelper->recursiveRemoveDir($tmpModuleDirFull);
@ -368,7 +370,7 @@ class ModuleService
$tmpModuleDir = md5(time());
$res = $zip->open(ROOT_DIR . $path);
if ($res === TRUE) {
$tmpModuleDirFull = RESOURCES_DIR . '/tmp/ad/' . $tmpModuleDir . "/";
$tmpModuleDirFull = RESOURCES_DIR . '/tmp/modules/' . $tmpModuleDir . "/";
$zip->extractTo($tmpModuleDirFull);
$zip->close();
} else {
@ -376,19 +378,21 @@ class ModuleService
return false;
}
if (!file_exists($tmpModuleDirFull . "/app/manifest.json")) {
if (!file_exists($tmpModuleDirFull . "app/manifest.json")) {
$this->addError('manifest.json not found');
return false;
}
$manifestJson = getConst(file_get_contents($tmpModuleDirFull . "/app/manifest.json"));
$manifestJson = getConst(file_get_contents($tmpModuleDirFull . "app/manifest.json"));
$manifest = Manifest::getWithVars($manifestJson);
$fileHelper = new Files();
$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']);
$fileHelper->copy_folder($tmpModuleDirFull . 'kernel', $manifest['kernel_module_path']);
} else {
$fileHelper->copy_folder($tmpModuleDirFull . '/kernel', KERNEL_APP_MODULES_DIR . '/' . $manifest['slug']);
$fileHelper->copy_folder($tmpModuleDirFull . 'kernel', KERNEL_APP_MODULES_DIR . '/' . $manifest['slug']);
}
$fileHelper->recursiveRemoveDir($tmpModuleDirFull);
@ -411,4 +415,56 @@ class ModuleService
return $dependence_array;
}
public function isInstall(string $slug): bool
{
$module_paths = Option::where("key", "module_paths")->first();
$dirs = [];
if ($module_paths){
$path = json_decode($module_paths->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->getModuleInfo($fileInfo->getPathname())['slug'] === $slug) {
return true;
};
}
}
return false;
}
public function isLastVersion(string $slug): bool
{
$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);
foreach ($modules_info as $mod) {
if ($mod['slug'] === $mod_info['slug'] && $mod['version'] === $mod_info['version']) {
return true;
}
}
return false;
}
public function isKernelModule(string $slug): bool
{
$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);
foreach ($modules_info as $mod) {
if ($mod['slug'] === $mod_info['slug']) {
return false;
}
}
return true;
}
}