2024-10-14 15:52:52 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace kernel\console\controllers;
|
|
|
|
|
|
|
|
use kernel\console\ConsoleController;
|
|
|
|
use kernel\helpers\Files;
|
2024-10-17 14:55:00 +03:00
|
|
|
use ZipArchive;
|
2024-10-14 15:52:52 +03:00
|
|
|
|
|
|
|
class KernelController extends ConsoleController
|
|
|
|
{
|
2024-10-17 14:55:00 +03:00
|
|
|
protected Files $files;
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
$this->files = new Files();
|
|
|
|
}
|
2024-10-14 15:52:52 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws \Exception
|
|
|
|
*/
|
|
|
|
public function actionPackKernel(): void
|
|
|
|
{
|
|
|
|
if (!isset($this->argv['path'])) {
|
|
|
|
throw new \Exception('Missing kernel path "--path" specified');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (file_exists(ROOT_DIR . $this->argv['path'])) {
|
|
|
|
|
|
|
|
$tmpKernelDirFull = RESOURCES_DIR . '/tmp/ad/kernel/';
|
|
|
|
|
|
|
|
$fileHelper = new Files();
|
|
|
|
$fileHelper->copy_folder(KERNEL_DIR, $tmpKernelDirFull);
|
|
|
|
|
2024-10-17 16:47:04 +03:00
|
|
|
if (!is_dir(RESOURCES_DIR . '/tmp/kernel')) {
|
|
|
|
mkdir(RESOURCES_DIR . '/tmp/kernel');
|
|
|
|
}
|
|
|
|
$fileHelper->pack($tmpKernelDirFull, RESOURCES_DIR . '/tmp/kernel/kernel.igk');
|
2024-10-14 15:52:52 +03:00
|
|
|
|
|
|
|
$fileHelper->recursiveRemoveDir($tmpKernelDirFull);
|
|
|
|
$this->out->r("Ядро заархивировано", 'green');
|
|
|
|
} else {
|
|
|
|
$this->out->r("Ядро не найдено", 'red');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-17 14:55:00 +03:00
|
|
|
/**
|
|
|
|
* @throws \Exception
|
|
|
|
*/
|
|
|
|
public function actionUpdateKernel()
|
|
|
|
{
|
|
|
|
if (!isset($this->argv['path'])) {
|
|
|
|
throw new \Exception('Missing kernel path "--path" specified');
|
|
|
|
}
|
|
|
|
|
|
|
|
$path = $this->argv['path'];
|
|
|
|
|
|
|
|
if (file_exists(ROOT_DIR . $path)) {
|
|
|
|
$zip = new ZipArchive;
|
|
|
|
$tmpKernelDir = md5(time());
|
|
|
|
$res = $zip->open(ROOT_DIR . $path);
|
|
|
|
if ($res === TRUE) {
|
|
|
|
$tmpKernelDirFull = RESOURCES_DIR . '/tmp/kernel/' . $tmpKernelDir . "/";
|
|
|
|
$zip->extractTo($tmpKernelDirFull);
|
|
|
|
$zip->close();
|
2024-10-17 16:47:04 +03:00
|
|
|
$this->files->recursiveRemoveKernelDir();
|
2024-10-17 14:55:00 +03:00
|
|
|
$this->files->copy_folder($tmpKernelDirFull , ROOT_DIR . "/kernel");
|
|
|
|
$this->files->recursiveRemoveDir($tmpKernelDirFull);
|
|
|
|
$this->out->r('Ядро обновлено.', 'green');
|
|
|
|
} else {
|
|
|
|
$this->out->r('unable to open zip archive', 'red');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$this->out->r("Модуль не найден", 'red');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function test()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-10-14 15:52:52 +03:00
|
|
|
}
|