diff --git a/kernel/controllers/ModuleController.php b/kernel/controllers/ModuleController.php
index 18262cb..3e2bb18 100644
--- a/kernel/controllers/ModuleController.php
+++ b/kernel/controllers/ModuleController.php
@@ -3,6 +3,7 @@
namespace kernel\controllers;
use DirectoryIterator;
+use JetBrains\PhpStorm\NoReturn;
use Josantonius\Session\Facades\Session;
use kernel\AdminController;
use kernel\helpers\Debug;
@@ -53,10 +54,6 @@ class ModuleController extends AdminController
$i++;
}
}
-// foreach (ModuleShopClientService::getModuleShopClientInfo() as $module) {
-// $module->id = $i++;
-// $modules_info[] = $module;
-// }
$module_count = count($modules_info);
$modules_info = array_slice($modules_info, $per_page*($page_number-1), $per_page);
@@ -106,23 +103,11 @@ class ModuleController extends AdminController
$this->cgView->render("view.php", ['data' => $mod_info]);
}
- public function actionUpdate(): void
+ #[NoReturn] public function actionUpdate(): void
{
$request = new Request();
$slug = $request->get('slug');
- if ($this->moduleService->isKernelModule($slug)) {
- $active_res = $this->moduleService->updateModule($request->get("slug"));
- if (!$active_res){
- Session::start();
- Session::set("error", implode(";", $this->moduleService->getErrors()));
- $this->redirect("/admin", 302);
- }
- $mod_info = $this->moduleService->getModuleInfoBySlug($request->get('slug'));
- } else {
- $this->redirect("/admin/module_shop_client/update/?slug=" . $slug, 302);
- }
-
- $this->cgView->render("view.php", ['data' => $mod_info]);
+ $this->redirect("/admin/module_shop_client/update/?slug=" . $slug, 302);
}
}
\ No newline at end of file
diff --git a/kernel/services/ModuleService.php b/kernel/services/ModuleService.php
index cc45d1a..3840192 100644
--- a/kernel/services/ModuleService.php
+++ b/kernel/services/ModuleService.php
@@ -189,8 +189,8 @@ class ModuleService
*/
public function runInitScript($mod_info): void
{
- if (isset($mod_info['module_class'])){
- if (isset($mod_info['module_class_file'])){
+ if (isset($mod_info['module_class'])) {
+ if (isset($mod_info['module_class_file'])) {
require_once $mod_info['module_class_file'];
}
$moduleClass = new $mod_info['module_class']();
@@ -204,8 +204,8 @@ class ModuleService
*/
public function runDeactivateScript($mod_info): void
{
- if (isset($mod_info['module_class'])){
- if (isset($mod_info['module_class_file'])){
+ if (isset($mod_info['module_class'])) {
+ if (isset($mod_info['module_class_file'])) {
require_once $mod_info['module_class_file'];
}
$moduleClass = new $mod_info['module_class']();
@@ -233,11 +233,11 @@ class ModuleService
foreach ($dirs as $dir) {
foreach (new DirectoryIterator($dir) as $fileInfo) {
- if($fileInfo->isDot() or !in_array($fileInfo->getFilename(), $active_modules['modules'])) continue;
+ if ($fileInfo->isDot() or !in_array($fileInfo->getFilename(), $active_modules['modules'])) continue;
$modules[] = $this->getModuleInfo($fileInfo->getPathname());
}
}
-
+
return $modules;
}
@@ -248,8 +248,8 @@ class ModuleService
{
$routs = [];
$modules = $this->getActiveModules();
- foreach ($modules as $module){
- if (isset($module['routs'])){
+ foreach ($modules as $module) {
+ if (isset($module['routs'])) {
$routs[] = $module['path'] . "/" . $module['routs'];
}
}
@@ -264,8 +264,8 @@ class ModuleService
{
$migrationsPaths = [];
$modules = $this->getActiveModules();
- foreach ($modules as $module){
- if (isset($module['migration_path'])){
+ foreach ($modules as $module) {
+ if (isset($module['migration_path'])) {
$migrationsPaths[] = $module['path'] . "/" . $module['migration_path'];
}
}
@@ -326,7 +326,7 @@ class ModuleService
$fileHelper = new Files();
if (file_exists(APP_DIR . '/modules/' . $moduleInfo['slug'])) {
- $fileHelper->recursiveRemoveDir(APP_DIR . '/modules/'. $moduleInfo['slug']);
+ $fileHelper->recursiveRemoveDir(APP_DIR . '/modules/' . $moduleInfo['slug']);
}
if (file_exists(KERNEL_APP_MODULES_DIR . '/' . $moduleInfo['slug'])) {
$fileHelper->recursiveRemoveDir(KERNEL_APP_MODULES_DIR . '/' . $moduleInfo['slug']);
@@ -345,10 +345,9 @@ class ModuleService
$fileHelper = new Files();
$fileHelper->copy_folder(ROOT_DIR . $path, $tmpModuleDirFull . 'app/');
- if (file_exists(KERNEL_APP_MODULES_DIR . '/' . $moduleName)){
+ if (file_exists(KERNEL_APP_MODULES_DIR . '/' . $moduleName)) {
$fileHelper->copy_folder(KERNEL_APP_MODULES_DIR . '/' . $moduleName, $tmpModuleDirFull . 'kernel/');
- }
- else {
+ } else {
mkdir($tmpModuleDirFull . 'kernel/');
}
@@ -419,15 +418,15 @@ class ModuleService
{
$module_paths = Option::where("key", "module_paths")->first();
$dirs = [];
- if ($module_paths){
+ if ($module_paths) {
$path = json_decode($module_paths->value);
- foreach ($path->paths as $p){
+ foreach ($path->paths as $p) {
$dirs[] = getConst($p);
}
}
- foreach ($dirs as $dir){
+ foreach ($dirs as $dir) {
foreach (new DirectoryIterator($dir) as $fileInfo) {
- if($fileInfo->isDot()) continue;
+ if ($fileInfo->isDot()) continue;
if ($this->getModuleInfo($fileInfo->getPathname())['slug'] === $slug) {
return true;
};
@@ -454,17 +453,25 @@ class ModuleService
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);
+ $modules_info = $this->getKernelModules();
foreach ($modules_info as $mod) {
- if ($mod['slug'] === $mod_info['slug']) {
- return false;
+ if ($mod['slug'] === $slug) {
+ return true;
}
}
- return true;
+ return false;
+ }
+
+ public function getKernelModules(): array
+ {
+ $modules_info = [];
+ foreach (new DirectoryIterator(KERNEL_MODULES_DIR) as $fileInfo) {
+ if ($fileInfo->isDot()) continue;
+ $modules_info[] = $this->getModuleInfo($fileInfo->getPathname());
+ }
+
+ return $modules_info;
}
}
\ No newline at end of file
diff --git a/kernel/views/module/index.php b/kernel/views/module/index.php
index f615734..5caf429 100644
--- a/kernel/views/module/index.php
+++ b/kernel/views/module/index.php
@@ -60,7 +60,7 @@ $table->addAction(function ($row, $url) use ($moduleService){
return false;
});
-$table->addAction(function ($row, $url) use ($moduleService){
+$table->addAction(function ($row) use ($moduleService){
$slug = $row['slug'];
if (!$moduleService->isKernelModule($slug)){
$label = "Удалить";
diff --git a/kernel/views/widgets/admin/action_button.php b/kernel/views/widgets/admin/action_button.php
new file mode 100644
index 0000000..32dee23
--- /dev/null
+++ b/kernel/views/widgets/admin/action_button.php
@@ -0,0 +1,9 @@
+
+
+"$icon";
\ No newline at end of file
diff --git a/views/widgets/admin/menu.php b/kernel/views/widgets/admin/menu.php
similarity index 100%
rename from views/widgets/admin/menu.php
rename to kernel/views/widgets/admin/menu.php
diff --git a/views/widgets/admin/module_tabs.php b/kernel/views/widgets/admin/module_tabs.php
similarity index 100%
rename from views/widgets/admin/module_tabs.php
rename to kernel/views/widgets/admin/module_tabs.php
diff --git a/views/widgets/admin/action_button.php b/views/widgets/admin/action_button.php
deleted file mode 100644
index f04355c..0000000
--- a/views/widgets/admin/action_button.php
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
-"$label";
\ No newline at end of file