2024-10-08 12:16:41 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace kernel\console\controllers;
|
|
|
|
|
|
|
|
use kernel\console\ConsoleController;
|
2024-10-08 17:06:14 +03:00
|
|
|
use kernel\helpers\Debug;
|
2024-10-08 12:16:41 +03:00
|
|
|
use kernel\helpers\Files;
|
|
|
|
use kernel\helpers\Manifest;
|
|
|
|
use kernel\models\Option;
|
|
|
|
use ZipArchive;
|
|
|
|
use kernel\services\ModuleService;
|
|
|
|
|
|
|
|
class ModuleController extends ConsoleController
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws \Exception
|
|
|
|
*/
|
|
|
|
public function actionInstallModule(): void
|
|
|
|
{
|
|
|
|
if (!isset($this->argv['path'])) {
|
|
|
|
throw new \Exception('Missing module path "--path" specified');
|
|
|
|
}
|
|
|
|
|
2024-10-09 16:42:20 +03:00
|
|
|
if (file_exists(ROOT_DIR . $this->argv['path'])) {
|
|
|
|
$moduleService = new ModuleService();
|
2024-10-24 11:44:16 +03:00
|
|
|
if ($moduleService->installModule($this->argv['path'])) {
|
|
|
|
$this->out->r("Модуль установлен", 'green');
|
|
|
|
} else {
|
|
|
|
$this->out->r("Ошибка установки модуля", 'red');
|
|
|
|
}
|
2024-10-08 12:16:41 +03:00
|
|
|
} else {
|
2024-10-09 16:42:20 +03:00
|
|
|
$this->out->r("Модуль не найден", 'red');
|
2024-10-08 12:16:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws \Exception
|
|
|
|
*/
|
|
|
|
public function actionUninstallModule(): void
|
|
|
|
{
|
|
|
|
if (!isset($this->argv['path'])) {
|
|
|
|
throw new \Exception('Missing module path "--path" specified');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (file_exists(ROOT_DIR . $this->argv['path'])) {
|
|
|
|
$moduleService = new ModuleService();
|
2024-10-09 16:42:20 +03:00
|
|
|
$moduleService->uninstallModule($this->argv['path']);
|
2024-10-24 11:44:16 +03:00
|
|
|
$this->out->r("Модуль удален", 'green');
|
2024-10-08 12:16:41 +03:00
|
|
|
} else {
|
|
|
|
$this->out->r("Модуль не найден", 'red');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-09 16:42:20 +03:00
|
|
|
/**
|
|
|
|
* @throws \Exception
|
|
|
|
*/
|
2024-10-08 17:06:14 +03:00
|
|
|
public function actionPackModule(): void
|
|
|
|
{
|
|
|
|
if (!isset($this->argv['path'])) {
|
|
|
|
throw new \Exception('Missing module path "--path" specified');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (file_exists(ROOT_DIR . $this->argv['path'])) {
|
2024-10-09 16:42:20 +03:00
|
|
|
$moduleService = new ModuleService();
|
|
|
|
$moduleService->packModule($this->argv['path']);
|
2024-10-24 11:44:16 +03:00
|
|
|
$this->out->r("Модуль заархивирован", 'green');
|
2024-10-09 16:42:20 +03:00
|
|
|
} else {
|
|
|
|
$this->out->r("Модуль не найден", 'red');
|
2024-10-08 17:06:14 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-10 11:19:51 +03:00
|
|
|
/**
|
|
|
|
* @throws \Exception
|
|
|
|
*/
|
|
|
|
public function actionUpdateModule(): void
|
|
|
|
{
|
|
|
|
if (!isset($this->argv['path'])) {
|
|
|
|
throw new \Exception('Missing module path "--path" specified');
|
|
|
|
}
|
|
|
|
if (file_exists(ROOT_DIR . $this->argv['path'])) {
|
|
|
|
$moduleService = new ModuleService();
|
2024-10-24 11:44:16 +03:00
|
|
|
if ($moduleService->updateModule($this->argv['path'])) {
|
|
|
|
$this->out->r("Модуль обновлен", 'green');
|
|
|
|
} else {
|
|
|
|
$this->out->r("Ошибка обновления модуля", 'red');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$this->out->r("Модуль не найден", 'red');
|
2024-10-10 11:19:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-10 15:28:34 +03:00
|
|
|
public function actionConstructModule(): void
|
|
|
|
{
|
2024-12-10 17:01:25 +03:00
|
|
|
$this->out->r("Введите slug модуля:", 'yellow');
|
|
|
|
$slug = substr(fgets(STDIN), 0, -1);
|
|
|
|
$slug = strtolower($slug);
|
|
|
|
|
2024-12-10 15:28:34 +03:00
|
|
|
$this->out->r("Введите название модуля:", 'yellow');
|
|
|
|
$name = substr(fgets(STDIN), 0, -1);
|
|
|
|
|
|
|
|
$this->out->r("Введите автора модуля:", 'yellow');
|
|
|
|
$author = substr(fgets(STDIN), 0, -1);
|
|
|
|
|
2024-12-10 17:01:25 +03:00
|
|
|
$this->out->r("Введите название пунтка меню для модуля:", 'yellow');
|
|
|
|
$label = substr(fgets(STDIN), 0, -1);
|
2024-12-10 15:28:34 +03:00
|
|
|
|
|
|
|
$moduleService = new ModuleService();
|
|
|
|
$moduleService->createDirs($slug);
|
|
|
|
|
2024-12-12 14:06:25 +03:00
|
|
|
$moduleService->createModuleByParams([
|
|
|
|
'slug' => $slug,
|
|
|
|
'model' => ucfirst($slug),
|
2024-12-10 15:28:34 +03:00
|
|
|
'author' => $author,
|
2024-12-12 14:06:25 +03:00
|
|
|
'name' => $name,
|
2024-12-12 15:04:45 +03:00
|
|
|
'label' => $label,
|
2024-12-10 15:28:34 +03:00
|
|
|
]);
|
2024-12-12 11:58:55 +03:00
|
|
|
|
2024-12-12 14:06:25 +03:00
|
|
|
$this->out->r("Модуль $slug создан", 'green');
|
2024-12-10 15:28:34 +03:00
|
|
|
}
|
|
|
|
|
2024-10-08 12:16:41 +03:00
|
|
|
}
|