This commit is contained in:
Билай Станислав 2024-11-19 12:27:52 +03:00
parent 202d265cab
commit 772ad48961
7 changed files with 45 additions and 53 deletions

View File

@ -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]);
}
}

View File

@ -347,8 +347,7 @@ class ModuleService
$fileHelper->copy_folder(ROOT_DIR . $path, $tmpModuleDirFull . 'app/');
if (file_exists(KERNEL_APP_MODULES_DIR . '/' . $moduleName)) {
$fileHelper->copy_folder(KERNEL_APP_MODULES_DIR . '/' . $moduleName, $tmpModuleDirFull . 'kernel/');
}
else {
} else {
mkdir($tmpModuleDirFull . 'kernel/');
}
@ -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 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;
}
}

View File

@ -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 = "Удалить";

View File

@ -0,0 +1,9 @@
<?php
/**
* @var string $icon
* @var string $btn
* @var string $url
*/
?>
"<a class='btn btn-$btn' href='$url/deactivate/?slug=$slug' style='margin: 3px; width: 150px;' >$icon</a>";

View File

@ -1,9 +0,0 @@
<?php
/**
* @var string $icon
* @var string $btn
* @var string $url
*/
?>
"<a class='btn btn-$btn_type' href='$url/deactivate/?slug=$slug' style='margin: 3px; width: 150px;' >$label</a>";