cgView->viewPath = APP_DIR . "/modules/module_shop/views/kernel/"; $this->moduleShopService = new ModuleShopService(); $this->files = new Files(); } public function actionCreate(): void { $this->cgView->render("form.php"); } /** * @throws \Exception */ #[NoReturn] public function actionAdd(): void { $kernelShopForm = new CreateKernelShopForm(); $kernelShopForm->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', 'igk']); $file->upload(); $kernelShopForm->setItem('path_to_archive', $file->getUploadFile()); } $tmpKernelDir = md5(time()); $zip = new ZipArchive; $res = $zip->open(ROOT_DIR . $kernelShopForm->getItem('path_to_archive')); if ($res === TRUE) { if (!is_dir(RESOURCES_DIR . '/tmp/ms/')) { mkdir(RESOURCES_DIR . '/tmp/ms/'); } $tmpModuleShopDirFull = RESOURCES_DIR . '/tmp/ms/' . $tmpKernelDir . "/"; $zip->extractTo($tmpModuleShopDirFull); $zip->close(); if (file_exists($tmpModuleShopDirFull . "kernel/manifest.json")){ $kernelInfo = $this->moduleShopService->getModuleInfo($tmpModuleShopDirFull . "kernel"); $kernelShopForm->load($kernelInfo); } else { throw new \Exception("Manifest.json file not found"); } $this->files->recursiveRemoveDir($tmpModuleShopDirFull); } else { throw new \Exception("zip not found"); } if ($kernelShopForm->validate()) { $kernel = $this->moduleShopService->create($kernelShopForm); if ($kernel) { Flash::setMessage("success", "Ядро добавлено."); $this->redirect("/admin/module_shop/view/" . $kernel->id); } } Flash::setMessage("error", "Ошибка добавления ядра:
" . $kernelShopForm->getErrorsStr()); $this->redirect("/admin/module_shop/kernel/create"); } }