kernel update

This commit is contained in:
2024-12-18 12:46:57 +03:00
parent 653e0bc983
commit 4ff9fa9ad3
56 changed files with 1023 additions and 84 deletions

View File

@@ -11,18 +11,21 @@ use kernel\app_modules\tag\services\TagService;
use kernel\FileUpload;
use kernel\Flash;
use kernel\helpers\Debug;
use kernel\helpers\Files;
use kernel\services\ModuleService;
use ZipArchive;
class ModuleShopController extends AdminController
{
protected ModuleShopService $moduleShopService;
protected Files $files;
protected function init(): void
{
parent::init();
$this->cgView->viewPath = APP_DIR . "/modules/module_shop/views/";
$this->moduleShopService = new ModuleShopService();
$this->files = new Files();
}
public function actionCreate(): void
@@ -44,14 +47,14 @@ class ModuleShopController extends AdminController
$moduleShopForm->setItem('path_to_archive', $file->getUploadFile());
}
$tmpThemeDir = md5(time());
$tmpModuleDir = md5(time());
$zip = new ZipArchive;
$res = $zip->open(ROOT_DIR . $moduleShopForm->getItem('path_to_archive'));
if ($res === TRUE) {
if (!is_dir(RESOURCES_DIR . '/tmp/ms/')) {
mkdir(RESOURCES_DIR . '/tmp/ms/');
}
$tmpModuleShopDirFull = RESOURCES_DIR . '/tmp/ms/' . $tmpThemeDir . "/";
$tmpModuleShopDirFull = RESOURCES_DIR . '/tmp/ms/' . $tmpModuleDir . "/";
$zip->extractTo($tmpModuleShopDirFull);
$zip->close();
@@ -62,6 +65,8 @@ class ModuleShopController extends AdminController
else {
throw new \Exception("Manifest.json file not found");
}
$this->files->recursiveRemoveDir($tmpModuleShopDirFull);
}
else {
throw new \Exception("zip not found");
@@ -71,11 +76,11 @@ class ModuleShopController extends AdminController
$module = $this->moduleShopService->create($moduleShopForm);
if ($module) {
Flash::setMessage("success", "Модуль " . $moduleShopForm->getItem("name") . " добавлен.");
$this->redirect("/admin/module_shop/" . $module->id);
$this->redirect("/admin/module_shop/view/" . $module->id);
}
}
Flash::setMessage("error", "Ошибка добавления модуля: <br>" . $moduleShopForm->getErrorsStr());
$this->redirect("/admin/module_shop/create");
$this->redirect("/admin/module_shop/module/create");
}
public function actionIndex(int $page_number = 1): void
@@ -101,6 +106,9 @@ class ModuleShopController extends AdminController
throw new \Exception("The module not found");
}
$name = $module->name;
$dir = $module->path_to_archive;
$this->files->recursiveRemoveDir(ROOT_DIR . dirname($dir, 2));
$module->delete();
Flash::setMessage("success", "Модуль " . $name . " удален.");