kernel update to v0.1.5

This commit is contained in:
Билай Станислав 2025-01-24 11:33:08 +03:00
parent 4d7a2fbdec
commit 530908568c
5 changed files with 87 additions and 19 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "Kernel", "name": "Kernel",
"version": "0.1.4", "version": "0.1.5",
"author": "ITGuild", "author": "ITGuild",
"slug": "kernel", "slug": "kernel",
"type": "kernel", "type": "kernel",

View File

@ -3,18 +3,31 @@
namespace kernel\modules\themes\controllers; namespace kernel\modules\themes\controllers;
use DirectoryIterator; use DirectoryIterator;
use GuzzleHttp\Exception\GuzzleException;
use JetBrains\PhpStorm\NoReturn; use JetBrains\PhpStorm\NoReturn;
use Josantonius\Session\Exceptions\HeadersSentException;
use Josantonius\Session\Exceptions\SessionNotStartedException;
use Josantonius\Session\Exceptions\SessionStartedException;
use Josantonius\Session\Exceptions\WrongSessionOptionException;
use Josantonius\Session\Facades\Session;
use kernel\AdminController; use kernel\AdminController;
use kernel\helpers\Debug; use kernel\helpers\Debug;
use kernel\models\Option; use kernel\models\Option;
use kernel\Request; use kernel\Request;
use kernel\services\ModuleService;
use kernel\services\ThemeService;
class ThemeController extends AdminController class ThemeController extends AdminController
{ {
public ThemeService $themeService;
public ModuleService $moduleService;
protected function init(): void protected function init(): void
{ {
parent::init(); parent::init();
$this->cgView->viewPath = KERNEL_MODULES_DIR . "/themes/views/"; $this->cgView->viewPath = KERNEL_MODULES_DIR . "/themes/views/";
$this->themeService = new ThemeService();
$this->moduleService = new ModuleService();
} }
public function actionIndex(): void public function actionIndex(): void
@ -62,10 +75,19 @@ class ThemeController extends AdminController
$this->cgView->render("index.php", ['json' => json_encode($infoToTable, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)]); $this->cgView->render("index.php", ['json' => json_encode($infoToTable, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)]);
} }
/**
* @throws HeadersSentException
* @throws WrongSessionOptionException
* @throws SessionStartedException
* @throws GuzzleException
* @throws SessionNotStartedException
*/
#[NoReturn] public function actionActivate(): void #[NoReturn] public function actionActivate(): void
{ {
$request = new Request(); $request = new Request();
$this->themeService->setActiveTheme($request->get("p")); if(!$this->themeService->setActiveTheme($request->get("p"))){
$this->redirect("/admin/settings/themes/", 302);
}
$this->cgView->render("view.php", ['data' => $this->themeService->getThemeInfo($request->get("p"))]); $this->cgView->render("view.php", ['data' => $this->themeService->getThemeInfo($request->get("p"))]);
} }

View File

@ -21,6 +21,7 @@ class ModuleService
protected null|bool $serverAvailable = null; protected null|bool $serverAvailable = null;
public ModuleShopService $moduleShopService; public ModuleShopService $moduleShopService;
public function __construct() public function __construct()
{ {
$this->moduleShopService = new ModuleShopService(); $this->moduleShopService = new ModuleShopService();
@ -601,11 +602,41 @@ class ModuleService
{ {
$data = file_get_contents($templatePath); $data = file_get_contents($templatePath);
foreach ($params as $key => $param){ foreach ($params as $key => $param) {
$data = str_replace("{" . $key . "}", $param, $data); $data = str_replace("{" . $key . "}", $param, $data);
} }
file_put_contents($filePath, $data); file_put_contents($filePath, $data);
} }
/**
* @throws GuzzleException
*/
public function recursiveActivateDependencies(array $dependencies): bool
{
$notActiveDependencies = [];
foreach ($dependencies as $depend) {
if (!$this->isInstall($depend)) {
$this->moduleShopService->installModule($depend);
if (!$this->setActiveModule($depend)) {
$notActiveDependencies[] = $depend;
}
} else {
if (!$this->isActive($depend)) {
if (!$this->setActiveModule($depend)) {
$notActiveDependencies[] = $depend;
}
}
}
}
if ($notActiveDependencies) {
if (!$this->recursiveActivateDependencies($notActiveDependencies)) {
return false;
}
}
return true;
}
} }

View File

@ -88,4 +88,21 @@ class ModuleShopService
return false; return false;
} }
/**
* @param string $slug
* @return bool
* @throws GuzzleException
*/
public function existsInModuleShop(string $slug): bool
{
$modulesInfo = $this->getGroupedBySlugModules();
foreach ($modulesInfo as $module) {
if ($module['slug'] === $slug) {
return true;
}
}
return false;
}
} }

View File

@ -3,6 +3,7 @@
namespace kernel\services; namespace kernel\services;
use DirectoryIterator; use DirectoryIterator;
use Josantonius\Session\Facades\Session;
use kernel\Flash; use kernel\Flash;
use kernel\helpers\Debug; use kernel\helpers\Debug;
use kernel\helpers\Files; use kernel\helpers\Files;
@ -22,6 +23,7 @@ class ThemeService
protected ModuleShopService $moduleShopService; protected ModuleShopService $moduleShopService;
public function __construct() public function __construct()
{ {
$this->option = new Option(); $this->option = new Option();
@ -58,7 +60,6 @@ class ThemeService
return $this->active_theme; return $this->active_theme;
} }
/** /**
* @param string $theme * @param string $theme
* @return bool * @return bool
@ -69,27 +70,24 @@ class ThemeService
$activeTheme = $this->option::where("key", "active_theme")->first(); $activeTheme = $this->option::where("key", "active_theme")->first();
$themeInfo = $this->getThemeInfo(getConst($theme)); $themeInfo = $this->getThemeInfo(getConst($theme));
if (isset($themeInfo['dependence'])) { $dependenceArray = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/get_all_dependencies/' . $themeInfo['slug']);
$dependence_array = explode(',', $themeInfo['dependence']); $dependenceArray = json_decode($dependenceArray->getBody()->getContents(), true);
foreach ($dependence_array as $depend) {
if (!$this->moduleService->isInstall($depend)) { foreach ($dependenceArray as $depend) {
if ($this->moduleService->isShopModule($depend)) { if (!$this->moduleService->isInstall($depend)) {
$this->moduleShopService->installModule($depend); if (!$this->moduleShopService->existsInModuleShop($depend)) {
} else { Flash::setMessage('error', "Модуль $depend не найден в IT Guild Framework Shop.");
Flash::setMessage("error", "Модуль не найден в IT Guild Framework Shop."); return false;
return false;
}
} else {
if (!$this->moduleService->isActive($depend)) {
$this->moduleService->setActiveModule($depend);
}
} }
} }
} }
if (!$this->moduleService->recursiveActivateDependencies($dependenceArray)){
return false;
}
$activeTheme->value = getConst($theme); $activeTheme->value = getConst($theme);
$activeTheme->save(); $activeTheme->save();
return true; return true;
} }