theme dependence
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
namespace kernel\services;
|
||||
|
||||
use DirectoryIterator;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use kernel\EntityRelation;
|
||||
use kernel\Flash;
|
||||
use kernel\helpers\Debug;
|
||||
@ -19,6 +20,12 @@ class ModuleService
|
||||
|
||||
protected null|bool $serverAvailable = null;
|
||||
|
||||
public ModuleShopService $moduleShopService;
|
||||
public function __construct()
|
||||
{
|
||||
$this->moduleShopService = new ModuleShopService();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $module
|
||||
* @return false|array|string
|
||||
@ -458,12 +465,13 @@ class ModuleService
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function isLastVersion(string $slug): bool
|
||||
{
|
||||
if ($this->isServerAvailable()) {
|
||||
$modules_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug');
|
||||
|
||||
$modules_info = json_decode($modules_info->getBody()->getContents(), true);
|
||||
$modules_info = $this->moduleShopService->getGroupedBySlugModules();
|
||||
|
||||
$mod_info = $this->getModuleInfoBySlug($slug);
|
||||
|
||||
@ -491,16 +499,18 @@ class ModuleService
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function isShopModule(string $slug): bool
|
||||
{
|
||||
if ($this->isServerAvailable()) {
|
||||
$modules_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug');
|
||||
$modules_info = $this->moduleShopService->getGroupedBySlugModules();
|
||||
|
||||
if (!$this->issetModuleShopToken()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$modules_info = json_decode($modules_info->getBody()->getContents(), true);
|
||||
if (isset($modules_info)) {
|
||||
$mod_info = $this->getModuleInfoBySlug($slug);
|
||||
foreach ($modules_info as $mod) {
|
||||
|
@ -3,7 +3,11 @@
|
||||
namespace kernel\services;
|
||||
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use kernel\Flash;
|
||||
use kernel\helpers\Debug;
|
||||
use kernel\helpers\Files;
|
||||
use kernel\helpers\RESTClient;
|
||||
use kernel\Request;
|
||||
|
||||
class ModuleShopService
|
||||
{
|
||||
@ -17,20 +21,71 @@ class ModuleShopService
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $email
|
||||
* @return mixed
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function email_auth(string $email)
|
||||
public function email_auth(string $email): mixed
|
||||
{
|
||||
$request = RESTClient::post($this->url . "/api/secure/email_auth", ['email' => $email], false);
|
||||
|
||||
return json_decode($request->getBody()->getContents(), true);
|
||||
}
|
||||
|
||||
public function code_check(string $code)
|
||||
/**
|
||||
* @param string $code
|
||||
* @return mixed
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function code_check(string $code): mixed
|
||||
{
|
||||
$request = RESTClient::post($this->url . "/api/secure/code_check", ['code' => $code], false);
|
||||
|
||||
return json_decode($request->getBody()->getContents(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function getGroupedBySlugModules(): mixed
|
||||
{
|
||||
$modulesInfo = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug');
|
||||
return json_decode($modulesInfo->getBody()->getContents(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $slug
|
||||
* @return void
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function installModule(string $slug): void
|
||||
{
|
||||
$moduleInfo = $this->getModuleInfoBySlug($slug);
|
||||
|
||||
$moduleInfo = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/install/' . $moduleInfo['id']);
|
||||
$moduleInfo = json_decode($moduleInfo->getBody()->getContents(), true);
|
||||
|
||||
Files::uploadByUrl($_ENV['MODULE_SHOP_URL'] . $moduleInfo['path_to_archive'], RESOURCES_DIR . "/tmp/modules");
|
||||
|
||||
(new ModuleService())->installModule('/resources/tmp/modules/' . basename($moduleInfo['path_to_archive']));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $slug
|
||||
* @return false|mixed
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function getModuleInfoBySlug(string $slug): mixed
|
||||
{
|
||||
$modulesInfo = $this->getGroupedBySlugModules();
|
||||
foreach ($modulesInfo as $module) {
|
||||
if ($module['slug'] === $slug) {
|
||||
return $module;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -3,6 +3,7 @@
|
||||
namespace kernel\services;
|
||||
|
||||
use DirectoryIterator;
|
||||
use kernel\Flash;
|
||||
use kernel\helpers\Debug;
|
||||
use kernel\helpers\Files;
|
||||
use kernel\helpers\Manifest;
|
||||
@ -19,12 +20,15 @@ class ThemeService
|
||||
|
||||
protected ModuleService $moduleService;
|
||||
|
||||
protected ModuleShopService $moduleShopService;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->option = new Option();
|
||||
$this->findActiveTheme();
|
||||
$this->moduleService = new ModuleService();
|
||||
$this->moduleShopService = new ModuleShopService();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -55,7 +59,12 @@ class ThemeService
|
||||
return $this->active_theme;
|
||||
}
|
||||
|
||||
public function setActiveTheme(string $theme): void
|
||||
/**
|
||||
* @param string $theme
|
||||
* @return bool
|
||||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||
*/
|
||||
public function setActiveTheme(string $theme): bool
|
||||
{
|
||||
$activeTheme = $this->option::where("key", "active_theme")->first();
|
||||
|
||||
@ -63,21 +72,25 @@ class ThemeService
|
||||
if (isset($themeInfo['dependence'])) {
|
||||
$dependence_array = explode(',', $themeInfo['dependence']);
|
||||
foreach ($dependence_array as $depend) {
|
||||
$this->moduleService->runInitScript($depend);
|
||||
}
|
||||
}
|
||||
|
||||
$currentThemeInfo = $this->getActiveThemeInfo();
|
||||
|
||||
if (isset($currentThemeInfo['dependence'])) {
|
||||
$dependence_array = explode(',', $currentThemeInfo['dependence']);
|
||||
foreach ($dependence_array as $depend) {
|
||||
$this->moduleService->runDeactivateScript($depend);
|
||||
if (!$this->moduleService->isInstall($depend)) {
|
||||
if ($this->moduleService->isShopModule($depend)) {
|
||||
$this->moduleShopService->installModule($depend);
|
||||
} else {
|
||||
Flash::setMessage("error", "Модуль не найден в IT Guild Framework Shop.");
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!$this->moduleService->isActive($depend)) {
|
||||
$this->moduleService->setActiveModule($depend);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$activeTheme->value = getConst($theme);
|
||||
$activeTheme->save();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getActiveThemeInfo(): false|array|string
|
||||
|
Reference in New Issue
Block a user