backend/kernel/console/controllers/AdminThemeController.php

74 lines
2.8 KiB
PHP
Raw Normal View History

2024-09-11 17:38:46 +03:00
<?php
namespace kernel\console\controllers;
use kernel\console\ConsoleController;
use kernel\helpers\Files;
use kernel\helpers\Manifest;
2024-09-12 12:56:10 +03:00
use kernel\models\Option;
use kernel\services\AdminThemeService;
2024-09-11 17:38:46 +03:00
use ZipArchive;
class AdminThemeController extends ConsoleController
{
public function actionInstallTheme(): void
{
if (!isset($this->argv['path'])) {
throw new \Exception('Missing admin theme path "--path" specified');
}
$zip = new ZipArchive;
$tmpThemeDir = md5(time());
$res = $zip->open(ROOT_DIR . $this->argv['path']);
if ($res === TRUE) {
$tmpThemeDirFull = RESOURCES_DIR . '/tmp/ad/' . $tmpThemeDir . "/";
$zip->extractTo($tmpThemeDirFull);
$zip->close();
$this->out->r('Архив распакован', 'green');
} else {
$this->out->r('Message: Ошибка чтения архива', 'red');
}
if (file_exists($tmpThemeDirFull . "meta/manifest.json")){
$manifestJson = getConst(file_get_contents($tmpThemeDirFull . "meta/manifest.json"));
$manifest = Manifest::getWithVars($manifestJson);
$this->out->r('manifest.json инициализирован', 'green');
$fileHelper = new Files();
$fileHelper->copy_folder($tmpThemeDirFull . "meta", $manifest['theme_path']);
$fileHelper->copy_folder($tmpThemeDirFull . "resources", $manifest['resource_path']);
$this->out->r("Удаляем временные файлы", 'green');
$fileHelper->recursiveRemoveDir($tmpThemeDirFull);
$this->out->r("Тема " . $manifest['name'] . " установлена", 'green');
}
2024-09-12 12:06:44 +03:00
}
2024-09-11 17:38:46 +03:00
2024-09-12 12:06:44 +03:00
public function actionUninstallTheme(): void
{
if (!isset($this->argv['path'])) {
throw new \Exception('Missing admin theme path "--path" specified');
}
2024-09-11 17:38:46 +03:00
2024-09-12 12:06:44 +03:00
if (file_exists(ROOT_DIR . $this->argv['path'])) {
$themeName = basename($this->argv['path']);
2024-09-12 12:56:10 +03:00
$active_admin_theme = Option::where("key", "active_admin_theme")->first();
if ($active_admin_theme->value === ROOT_DIR . $this->argv['path']) {
$this->out->r("Меняем тему на базовую", 'green');
$adminThemeService = new AdminThemeService();
$adminThemeService->setActiveAdminTheme(KERNEL_ADMIN_THEMES_DIR . '/default');
$this->out->r("Тема изменена", 'green');
}
2024-09-12 12:06:44 +03:00
$fileHelper = new Files();
$fileHelper->recursiveRemoveDir(ROOT_DIR . $this->argv['path']);
$fileHelper->recursiveRemoveDir(RESOURCES_DIR . '/' . $themeName);
$this->out->r("Тема удалена", 'green');
} else {
$this->out->r("Тема не найдена", 'red');
}
2024-09-11 17:38:46 +03:00
}
}