Theme module and them to igfs add

This commit is contained in:
2025-01-19 21:23:53 +03:00
parent dac4db96af
commit 50c6ca98d8
12 changed files with 315 additions and 17 deletions

View File

@ -17,6 +17,7 @@ use kernel\services\AdminThemeService;
use kernel\services\KernelService;
use kernel\services\ModuleService;
use kernel\services\ModuleShopService;
use kernel\services\ThemeService;
use PHPMailer\PHPMailer\Exception;
class ModuleShopClientController extends AdminController
@ -60,6 +61,7 @@ class ModuleShopClientController extends AdminController
'per_page' => $per_page,
'kernelService' => new KernelService(),
'adminThemeService' => new AdminThemeService(),
'themeService' => new ThemeService(),
]);
} else {
$this->cgView->render("module_shop_error_connection.php");
@ -295,4 +297,56 @@ class ModuleShopClientController extends AdminController
$this->redirect('/admin/module_shop_client', 302);
}
#[NoReturn] public function actionThemeInstall(): void
{
$request = new Request();
$id = $request->get("id");
$themeInfo = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/install/' . $id);
$themeInfo = json_decode($themeInfo->getBody()->getContents(), true);
Files::uploadByUrl($_ENV['MODULE_SHOP_URL'] . $themeInfo['path_to_archive'], RESOURCES_DIR . "/tmp/themes");
if ($this->themeService->install('/resources/tmp/themes/' . basename($themeInfo['path_to_archive']))) {
Flash::setMessage("success", "Тема сайта успешно установлена.");
} else {
Session::start();
Session::set("error", implode(";", $this->themeService->getErrors()));
}
$this->redirect('/admin/module_shop_client', 302);
}
#[NoReturn] public function actionThemeUpdate(): void
{
$request = new Request();
$slug = $request->get("slug");
$modules_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug');
$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/themes");
$this->themeService->update('/resources/tmp/themes/' . basename($path));
Flash::setMessage("success", "Тема сайта успешно обновлена.");
} else {
Flash::setMessage("error", "Ошибка обновления темы сайта.");
}
$this->redirect('/admin/module_shop_client', 302);
}
#[NoReturn] public function actionThemeDelete(): void
{
$request = new Request();
$slug = $request->get("slug");
$themeInfo = $this->themeService->getThemeInfoBySlug($slug);
$this->themeService->uninstall($themeInfo['path']);
Flash::setMessage("success", "Тема сайта успешно удалена.");
$this->redirect('/admin/module_shop_client', 302);
}
}