cgView->viewPath = APP_DIR . "/modules/module_shop/views/admin_theme/"; $this->moduleShopService = new ModuleShopService(); $this->files = new Files(); } public function actionCreate(): void { $this->cgView->render("form.php"); } /** * @throws \Exception */ #[NoReturn] public function actionAdd(): void { $adminThemeShopForm = new CreateAdminThemeShopForm(); $adminThemeShopForm->load($_REQUEST); if (isset($_FILES['path_to_archive']) && $_FILES['path_to_archive']['error'] === UPLOAD_ERR_OK) { $file = new FileUpload($_FILES['path_to_archive'], ['zip', 'rar', 'igt']); $file->upload(); $adminThemeShopForm->setItem('path_to_archive', $file->getUploadFile()); } $tmpThemeDir = md5(time()); $zip = new ZipArchive; $res = $zip->open(ROOT_DIR . $adminThemeShopForm->getItem('path_to_archive')); if ($res === TRUE) { if (!is_dir(RESOURCES_DIR . '/tmp/ms/')) { $oldMask = umask(0); mkdir(RESOURCES_DIR . '/tmp/ms/', 0775, true); umask($oldMask); } $tmpModuleShopDirFull = RESOURCES_DIR . '/tmp/ms/' . $tmpThemeDir . "/"; $zip->extractTo($tmpModuleShopDirFull); $zip->close(); if (file_exists($tmpModuleShopDirFull . "meta/manifest.json")){ $themeInfo = $this->moduleShopService->getModuleInfo($tmpModuleShopDirFull . "meta"); $adminThemeShopForm->load($themeInfo); } else { throw new \Exception("Manifest.json file not found"); } $this->files->recursiveRemoveDir($tmpModuleShopDirFull); } else { throw new \Exception("zip not found"); } if ($adminThemeShopForm->validate()) { $theme = $this->moduleShopService->create($adminThemeShopForm); if ($theme) { Flash::setMessage("success", "Тема админ-панели добавлена."); $this->redirect("/admin/module_shop/view/" . $theme->id); } } Flash::setMessage("error", "Ошибка добавления темы админ-панели:
" . $adminThemeShopForm->getErrorsStr()); $this->redirect("/admin/module_shop/admin_theme/create"); } }