kernel update to v0.1.5
This commit is contained in:
parent
4d7a2fbdec
commit
530908568c
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "Kernel",
|
||||
"version": "0.1.4",
|
||||
"version": "0.1.5",
|
||||
"author": "ITGuild",
|
||||
"slug": "kernel",
|
||||
"type": "kernel",
|
||||
|
@ -3,18 +3,31 @@
|
||||
namespace kernel\modules\themes\controllers;
|
||||
|
||||
use DirectoryIterator;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
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\helpers\Debug;
|
||||
use kernel\models\Option;
|
||||
use kernel\Request;
|
||||
use kernel\services\ModuleService;
|
||||
use kernel\services\ThemeService;
|
||||
|
||||
class ThemeController extends AdminController
|
||||
{
|
||||
public ThemeService $themeService;
|
||||
|
||||
public ModuleService $moduleService;
|
||||
protected function init(): void
|
||||
{
|
||||
parent::init();
|
||||
$this->cgView->viewPath = KERNEL_MODULES_DIR . "/themes/views/";
|
||||
$this->themeService = new ThemeService();
|
||||
$this->moduleService = new ModuleService();
|
||||
}
|
||||
|
||||
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)]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws HeadersSentException
|
||||
* @throws WrongSessionOptionException
|
||||
* @throws SessionStartedException
|
||||
* @throws GuzzleException
|
||||
* @throws SessionNotStartedException
|
||||
*/
|
||||
#[NoReturn] public function actionActivate(): void
|
||||
{
|
||||
$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"))]);
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ class ModuleService
|
||||
protected null|bool $serverAvailable = null;
|
||||
|
||||
public ModuleShopService $moduleShopService;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->moduleShopService = new ModuleShopService();
|
||||
@ -608,4 +609,34 @@ class ModuleService
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
@ -88,4 +88,21 @@ class ModuleShopService
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
@ -3,6 +3,7 @@
|
||||
namespace kernel\services;
|
||||
|
||||
use DirectoryIterator;
|
||||
use Josantonius\Session\Facades\Session;
|
||||
use kernel\Flash;
|
||||
use kernel\helpers\Debug;
|
||||
use kernel\helpers\Files;
|
||||
@ -22,6 +23,7 @@ class ThemeService
|
||||
|
||||
protected ModuleShopService $moduleShopService;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->option = new Option();
|
||||
@ -58,7 +60,6 @@ class ThemeService
|
||||
return $this->active_theme;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $theme
|
||||
* @return bool
|
||||
@ -69,27 +70,24 @@ class ThemeService
|
||||
$activeTheme = $this->option::where("key", "active_theme")->first();
|
||||
|
||||
$themeInfo = $this->getThemeInfo(getConst($theme));
|
||||
if (isset($themeInfo['dependence'])) {
|
||||
$dependence_array = explode(',', $themeInfo['dependence']);
|
||||
foreach ($dependence_array as $depend) {
|
||||
$dependenceArray = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/get_all_dependencies/' . $themeInfo['slug']);
|
||||
$dependenceArray = json_decode($dependenceArray->getBody()->getContents(), true);
|
||||
|
||||
foreach ($dependenceArray as $depend) {
|
||||
if (!$this->moduleService->isInstall($depend)) {
|
||||
if ($this->moduleService->isShopModule($depend)) {
|
||||
$this->moduleShopService->installModule($depend);
|
||||
} else {
|
||||
Flash::setMessage("error", "Модуль не найден в IT Guild Framework Shop.");
|
||||
if (!$this->moduleShopService->existsInModuleShop($depend)) {
|
||||
Flash::setMessage('error', "Модуль $depend не найден в IT Guild Framework Shop.");
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!$this->moduleService->isActive($depend)) {
|
||||
$this->moduleService->setActiveModule($depend);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->moduleService->recursiveActivateDependencies($dependenceArray)){
|
||||
return false;
|
||||
}
|
||||
|
||||
$activeTheme->value = getConst($theme);
|
||||
$activeTheme->save();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user