update, delete module from shop on local page
This commit is contained in:
parent
faf0217b52
commit
f4b0f006aa
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "Tags",
|
||||
"version": "0.1",
|
||||
"version": "0.12",
|
||||
"author": "ITGuild",
|
||||
"slug": "tag",
|
||||
"description": "Tags module",
|
||||
|
@ -109,13 +109,20 @@ class ModuleController extends AdminController
|
||||
public function actionUpdate(): void
|
||||
{
|
||||
$request = new Request();
|
||||
$active_res = $this->moduleService->updateModule($request->get("slug"));
|
||||
if (!$active_res){
|
||||
Session::start();
|
||||
Session::set("error", implode(";", $this->moduleService->getErrors()));
|
||||
$this->redirect("/admin", 302);
|
||||
$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);
|
||||
}
|
||||
$mod_info = $this->moduleService->getModuleInfoBySlug($request->get('slug'));
|
||||
|
||||
|
||||
|
||||
$this->cgView->render("view.php", ['data' => $mod_info]);
|
||||
}
|
||||
|
@ -75,17 +75,24 @@ class ModuleShopClientController extends AdminController
|
||||
#[NoReturn] public function actionUpdate(): void
|
||||
{
|
||||
$request = new Request();
|
||||
$id = $request->get("id");
|
||||
$module_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/' . $id);
|
||||
$slug = $request->get("slug");
|
||||
$modules_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug');
|
||||
|
||||
$module_info = json_decode($module_info->getBody()->getContents(), true);
|
||||
Files::uploadByUrl($_ENV['MODULE_SHOP_URL'] . $module_info['path_to_archive'], RESOURCES_DIR . "/tmp/modules");
|
||||
$this->moduleService->updateModule('/resources/tmp/modules/' . basename($module_info['path_to_archive']));
|
||||
$modules_info = json_decode($modules_info->getBody()->getContents(), true);
|
||||
foreach ($modules_info as $module) {
|
||||
if ($module['slug'] === $slug) {
|
||||
$path = $module['path_to_archive'];
|
||||
}
|
||||
}
|
||||
if (isset($path)) {
|
||||
Files::uploadByUrl($_ENV['MODULE_SHOP_URL'] . $path, RESOURCES_DIR . "/tmp/modules");
|
||||
$this->moduleService->updateModule('/resources/tmp/modules/' . basename($path));
|
||||
Flash::setMessage("success", "Модуль успешно обновлен.");
|
||||
} else {
|
||||
Flash::setMessage("error", "Ошибка обновления модуля.");
|
||||
}
|
||||
|
||||
Flash::setMessage("success", "Модуль успешно обновлен.");
|
||||
$this->redirect('/admin/module_shop_client', 302);
|
||||
|
||||
|
||||
}
|
||||
|
||||
#[NoReturn] public function actionDelete(): void
|
||||
|
@ -41,7 +41,7 @@ $table->addAction(function ($row, $url) use ($moduleService){
|
||||
}
|
||||
else {
|
||||
$label = "Установить";
|
||||
$btn_type = "warning";
|
||||
$btn_type = "success";
|
||||
$btn = "<a class='btn btn-$btn_type' href='$url/install/?id=$id' style='margin: 3px; width: 150px;' >$label</a>";
|
||||
}
|
||||
|
||||
@ -50,16 +50,15 @@ $table->addAction(function ($row, $url) use ($moduleService){
|
||||
|
||||
$table->addAction(function ($row, $url) use ($moduleService){
|
||||
$slug = $row['slug'];
|
||||
$id = $row['id'];
|
||||
if ($moduleService->isInstall($slug)){
|
||||
if (!$moduleService->isLastVersion($slug)) {
|
||||
$label = "Обновить";
|
||||
$btn_type = "danger";
|
||||
return "<a class='btn btn-$btn_type' href='$url/update/?id=$id' style='margin: 3px; width: 150px;' >$label</a>";
|
||||
$btn_type = "info";
|
||||
return "<a class='btn btn-$btn_type' href='$url/update/?slug=$slug' style='margin: 3px; width: 150px;' >$label</a>";
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
|
||||
|
@ -7,6 +7,7 @@ use GuzzleHttp\Client;
|
||||
use kernel\helpers\Debug;
|
||||
use kernel\helpers\Files;
|
||||
use kernel\helpers\Manifest;
|
||||
use kernel\helpers\RESTClient;
|
||||
use kernel\models\Option;
|
||||
use ZipArchive;
|
||||
|
||||
@ -438,13 +439,8 @@ class ModuleService
|
||||
|
||||
public function isLastVersion(string $slug): bool
|
||||
{
|
||||
$client = new Client();
|
||||
$token = $_ENV['MODULE_SHOP_TOKEN'];
|
||||
$modules_info = $client->request('GET', $_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug', [
|
||||
'headers' => [
|
||||
'Authorization' => 'Bearer ' . $token,
|
||||
]
|
||||
]);
|
||||
$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) {
|
||||
@ -456,4 +452,19 @@ 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);
|
||||
foreach ($modules_info as $mod) {
|
||||
if ($mod['slug'] === $mod_info['slug']) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -35,7 +35,7 @@ $table->addAction(function ($row, $url) use ($moduleService) {
|
||||
|
||||
} else {
|
||||
$label = "Активировать";
|
||||
$btn_type = "primary";
|
||||
$btn_type = "success";
|
||||
$btn = "<a class='btn btn-$btn_type' href='$url/activate/?slug=$slug' style='margin: 3px; width: 150px;' >$label</a>";
|
||||
}
|
||||
|
||||
@ -47,10 +47,28 @@ $table->addAction(function ($row, $url) use ($moduleService) {
|
||||
return "<a class='btn btn-primary' href='$url/view/?slug=$slug' style='margin: 3px; width: 150px;' >Просмотр</a>";
|
||||
});
|
||||
|
||||
//$table->addAction(function ($row, $url) use ($moduleService) {
|
||||
// $slug = $row['slug'];
|
||||
// return "<a class='btn btn-primary' href='$url/update/?slug=$slug' style='margin: 3px; width: 150px;' >Обновить</a>";
|
||||
//});
|
||||
$table->addAction(function ($row, $url) use ($moduleService){
|
||||
$slug = $row['slug'];
|
||||
if (!$moduleService->isKernelModule($slug)){
|
||||
if (!$moduleService->isLastVersion($slug)) {
|
||||
$label = "Обновить";
|
||||
$btn_type = "info";
|
||||
return "<a class='btn btn-$btn_type' href='$url/update/?slug=$slug' style='margin: 3px; width: 150px;' >$label</a>";
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
$table->addAction(function ($row, $url) use ($moduleService){
|
||||
$slug = $row['slug'];
|
||||
if (!$moduleService->isKernelModule($slug)){
|
||||
$label = "Удалить";
|
||||
$btn_type = "danger";
|
||||
return "<a class='btn btn-$btn_type' href='admin/module_shop_client/delete/?slug=$slug' style='margin: 3px; width: 150px;' >$label</a>";
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
$table->create();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user