kernel update
This commit is contained in:
84
app/modules/module_shop/controllers/KernelShopController.php
Normal file
84
app/modules/module_shop/controllers/KernelShopController.php
Normal file
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace app\modules\module_shop\controllers;
|
||||
|
||||
use app\modules\module_shop\models\forms\CreateModuleShopForm;
|
||||
use app\modules\module_shop\models\ModuleShop;
|
||||
use app\modules\module_shop\services\ModuleShopService;
|
||||
use JetBrains\PhpStorm\NoReturn;
|
||||
use kernel\AdminController;
|
||||
use kernel\FileUpload;
|
||||
use kernel\Flash;
|
||||
use kernel\helpers\Debug;
|
||||
use kernel\helpers\Files;
|
||||
use kernel\services\ModuleService;
|
||||
use ZipArchive;
|
||||
|
||||
class KernelShopController extends AdminController
|
||||
{
|
||||
protected ModuleShopService $moduleShopService;
|
||||
protected Files $files;
|
||||
|
||||
protected function init(): void
|
||||
{
|
||||
parent::init();
|
||||
$this->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
|
||||
{
|
||||
$moduleShopForm = new CreateModuleShopForm();
|
||||
$moduleShopForm->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();
|
||||
$moduleShopForm->setItem('path_to_archive', $file->getUploadFile());
|
||||
}
|
||||
|
||||
$tmpKernelDir = 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/' . $tmpKernelDir . "/";
|
||||
$zip->extractTo($tmpModuleShopDirFull);
|
||||
$zip->close();
|
||||
|
||||
if (file_exists($tmpModuleShopDirFull . "kernel/manifest.json")){
|
||||
$kernelInfo = $this->moduleShopService->getModuleInfo($tmpModuleShopDirFull . "kernel");
|
||||
$moduleShopForm->load($kernelInfo);
|
||||
}
|
||||
else {
|
||||
throw new \Exception("Manifest.json file not found");
|
||||
}
|
||||
$this->files->recursiveRemoveDir($tmpModuleShopDirFull);
|
||||
|
||||
}
|
||||
else {
|
||||
throw new \Exception("zip not found");
|
||||
}
|
||||
|
||||
if ($moduleShopForm->validate()) {
|
||||
$kernel = $this->moduleShopService->create($moduleShopForm);
|
||||
if ($kernel) {
|
||||
Flash::setMessage("success", "Ядро добавлено.");
|
||||
$this->redirect("/admin/module_shop/view/" . $kernel->id);
|
||||
}
|
||||
}
|
||||
Flash::setMessage("error", "Ошибка добавления ядра: <br>" . $moduleShopForm->getErrorsStr());
|
||||
$this->redirect("/admin/module_shop/kernel/create");
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace app\modules\module_shop\controllers;
|
||||
|
||||
use app\modules\module_shop\models\ModuleShop;
|
||||
use JetBrains\PhpStorm\NoReturn;
|
||||
use kernel\helpers\Debug;
|
||||
use kernel\Request;
|
||||
use kernel\RestController;
|
||||
|
||||
class KernelShopRestController extends RestController
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->model = new ModuleShop();
|
||||
}
|
||||
|
||||
#[NoReturn] public function actionUpdate($id): void
|
||||
{
|
||||
$model = $this->model->where("id", $id)->first();
|
||||
$model->installations++;
|
||||
$model->save();
|
||||
$this->renderApi($model->toArray());
|
||||
}
|
||||
|
||||
}
|
@ -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 . " удален.");
|
||||
|
@ -97,7 +97,7 @@ class ModuleShopRestController extends RestController
|
||||
$this->renderApi($res);
|
||||
}
|
||||
|
||||
public function actionInstall($id): void
|
||||
#[NoReturn] public function actionInstall($id): void
|
||||
{
|
||||
$model = $this->model->where("id", $id)->first();
|
||||
$model->installations++;
|
||||
|
Reference in New Issue
Block a user