admin theme manager
This commit is contained in:
@ -4,7 +4,6 @@
|
||||
namespace kernel\console;
|
||||
|
||||
|
||||
use app\helpers\Debug;
|
||||
use kernel\App;
|
||||
use Phroute\Phroute\Dispatcher;
|
||||
|
||||
|
@ -1,29 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\console\controllers;
|
||||
|
||||
use app\helpers\Debug;
|
||||
use kernel\console\ConsoleController;
|
||||
use ZipArchive;
|
||||
|
||||
class AdminTheme extends ConsoleController
|
||||
{
|
||||
|
||||
public function actionInstallTheme()
|
||||
{
|
||||
if (!isset($this->argv['path'])) {
|
||||
throw new \Exception('Missing admin theme path "--path" specified');
|
||||
}
|
||||
|
||||
$zip = new ZipArchive;
|
||||
$res = $zip->open(ROOT_DIR . $this->argv['path']);
|
||||
if ($res === TRUE) {
|
||||
$zip->extractTo(RESOURCES_DIR . '/tmp/ad/');
|
||||
$zip->close();
|
||||
echo 'woot!';
|
||||
} else {
|
||||
echo 'doh!';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
49
kernel/console/controllers/AdminThemeController.php
Normal file
49
kernel/console/controllers/AdminThemeController.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\console\controllers;
|
||||
|
||||
use kernel\console\ConsoleController;
|
||||
use kernel\helpers\Files;
|
||||
use kernel\helpers\Manifest;
|
||||
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');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -13,6 +13,6 @@ App::$collector->group(["prefix" => "migration"], callback: function (RouteColle
|
||||
});
|
||||
|
||||
App::$collector->group(["prefix" => "admin-theme"], callback: function (RouteCollector $router){
|
||||
App::$collector->console('install', [\kernel\console\controllers\AdminTheme::class, 'actionInstallTheme']);
|
||||
App::$collector->console('install', [\kernel\console\controllers\AdminThemeController::class, 'actionInstallTheme']);
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user