kernel update
This commit is contained in:
@ -23,6 +23,7 @@ class MigrationService
|
||||
public function runAtPath(string $path = ROOT_DIR . '/migrations'): array
|
||||
{
|
||||
$path = getConst($path);
|
||||
// Debug::dd($path);
|
||||
|
||||
try {
|
||||
$dmr = new DatabaseMigrationRepository(App::$db->capsule->getDatabaseManager(), 'migration');
|
||||
@ -31,7 +32,7 @@ class MigrationService
|
||||
|
||||
return $m->run($path);
|
||||
} catch (\Exception $e) {
|
||||
throw new \Exception('Не удалось поднять играции');
|
||||
throw new \Exception('Не удалось поднять миграции');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,18 +3,22 @@
|
||||
namespace kernel\services;
|
||||
|
||||
use DirectoryIterator;
|
||||
use GuzzleHttp\Client;
|
||||
use kernel\EntityRelation;
|
||||
use kernel\Flash;
|
||||
use kernel\helpers\Debug;
|
||||
use kernel\helpers\Files;
|
||||
use kernel\helpers\Manifest;
|
||||
use kernel\helpers\RESTClient;
|
||||
use kernel\models\Option;
|
||||
use MongoDB\Driver\Session;
|
||||
use ZipArchive;
|
||||
|
||||
class ModuleService
|
||||
{
|
||||
protected array $errors = [];
|
||||
|
||||
protected null|bool $serverAvailable = null;
|
||||
|
||||
/**
|
||||
* @param string $module
|
||||
* @return false|array|string
|
||||
@ -67,9 +71,9 @@ class ModuleService
|
||||
{
|
||||
$active_modules = Option::where("key", "active_modules")->first();
|
||||
if ($active_modules) {
|
||||
$path = json_decode($active_modules->value);
|
||||
foreach ($path->modules as $p) {
|
||||
if ($p === $slug) {
|
||||
$modules = json_decode($active_modules->value);
|
||||
foreach ($modules->modules as $mod) {
|
||||
if ($mod === $slug) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -109,7 +113,7 @@ class ModuleService
|
||||
if (isset($module_info['dependence'])) {
|
||||
$dependence_array = explode(',', $module_info['dependence']);
|
||||
foreach ($dependence_array as $depend) {
|
||||
if (!in_array($depend, $active_modules->modules)) {
|
||||
if (!in_array(trim($depend), $active_modules->modules)) {
|
||||
$this->addError("first activate the $depend module");
|
||||
return false;
|
||||
}
|
||||
@ -131,6 +135,10 @@ class ModuleService
|
||||
public function deactivateModule(string $module): bool
|
||||
{
|
||||
$active_modules_info = Option::where("key", "active_modules")->first();
|
||||
|
||||
EntityRelation::removeEntityRelation($module);
|
||||
EntityRelation::removePropertyRelation($module);
|
||||
|
||||
$active_modules = json_decode($active_modules_info->value);
|
||||
if (!in_array($module, $active_modules->modules)) {
|
||||
return true;
|
||||
@ -355,8 +363,6 @@ class ModuleService
|
||||
mkdir(RESOURCES_DIR . '/tmp/modules', 0777, true);
|
||||
}
|
||||
$fileHelper->pack($tmpModuleDirFull, RESOURCES_DIR . '/tmp/modules/' . $moduleName . '.igm');
|
||||
|
||||
//$fileHelper->recursiveRemoveDir($tmpModuleDirFull);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -438,17 +444,19 @@ class ModuleService
|
||||
|
||||
public function isLastVersion(string $slug): bool
|
||||
{
|
||||
$modules_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug');
|
||||
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);
|
||||
$mod_info = $this->getModuleInfoBySlug($slug);
|
||||
foreach ($modules_info as $mod) {
|
||||
if ($mod['slug'] === $mod_info['slug'] && $mod['version'] === $mod_info['version']) {
|
||||
return true;
|
||||
$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;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function isKernelModule(string $slug): bool
|
||||
@ -463,6 +471,27 @@ class ModuleService
|
||||
return false;
|
||||
}
|
||||
|
||||
public function isShopModule(string $slug): bool
|
||||
{
|
||||
if ($this->isServerAvailable()){
|
||||
$modules_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug');
|
||||
|
||||
if (!$this->issetModuleShopToken()){
|
||||
return false;
|
||||
}
|
||||
|
||||
$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 true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getKernelModules(): array
|
||||
{
|
||||
$modules_info = [];
|
||||
@ -474,4 +503,30 @@ class ModuleService
|
||||
return $modules_info;
|
||||
}
|
||||
|
||||
public function isServerAvailable(): bool
|
||||
{
|
||||
if (null !== $this->serverAvailable){
|
||||
return $this->serverAvailable;
|
||||
}
|
||||
|
||||
try {
|
||||
RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug');
|
||||
$this->serverAvailable = true;
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
$this->serverAvailable = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function issetModuleShopToken(): bool
|
||||
{
|
||||
if (!empty($_ENV['MODULE_SHOP_TOKEN'])){
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
36
kernel/services/ModuleShopService.php
Normal file
36
kernel/services/ModuleShopService.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\services;
|
||||
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use kernel\helpers\RESTClient;
|
||||
|
||||
class ModuleShopService
|
||||
{
|
||||
protected string $url;
|
||||
protected string $token;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->url = $_ENV['MODULE_SHOP_URL'];
|
||||
$this->token = $_ENV['MODULE_SHOP_TOKEN'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function email_auth(string $email)
|
||||
{
|
||||
$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)
|
||||
{
|
||||
$request = RESTClient::post($this->url . "/api/secure/code_check", ['code' => $code], false);
|
||||
|
||||
return json_decode($request->getBody()->getContents(), true);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user