2024-10-14 15:52:52 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace kernel\console\controllers;
|
|
|
|
|
|
|
|
use kernel\console\ConsoleController;
|
|
|
|
use kernel\helpers\Files;
|
2024-10-23 16:16:47 +03:00
|
|
|
use ZipArchive;
|
2024-10-14 15:52:52 +03:00
|
|
|
|
|
|
|
class KernelController extends ConsoleController
|
|
|
|
{
|
2024-10-23 16:16:47 +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'])) {
|
2024-10-23 16:16:47 +03:00
|
|
|
$tmpKernelDirFull = RESOURCES_DIR . '/tmp/ad/kernel/kernel';
|
|
|
|
$this->files->copy_folder(KERNEL_DIR, $tmpKernelDirFull);
|
|
|
|
$this->out->r("Ядро скопировано во временную папку", 'green');
|
|
|
|
} else {
|
|
|
|
$this->out->r("Ядро не найдено", 'red');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (file_exists(ROOT_DIR . '/bootstrap')) {
|
|
|
|
$tmpBootstrapDirFull = RESOURCES_DIR . '/tmp/ad/kernel/bootstrap';
|
|
|
|
$this->files->copy_folder(ROOT_DIR . '/bootstrap', $tmpBootstrapDirFull);
|
|
|
|
$this->out->r("/bootstrap скопирован во временную папку", 'green');
|
|
|
|
} else {
|
|
|
|
$this->out->r("/bootstrap не найден", 'red');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (file_exists(ROOT_DIR . '/.env.example')) {
|
|
|
|
$tmpEnvDirFull = RESOURCES_DIR . '/tmp/ad/kernel/env.example';
|
|
|
|
copy(ROOT_DIR . '/.env.example', $tmpEnvDirFull);
|
|
|
|
$this->out->r("/.env.example скопирован во временную папку", 'green');
|
|
|
|
} else {
|
|
|
|
$this->out->r("/.env.example не найден", 'red');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (file_exists(ROOT_DIR . '/composer.json')) {
|
|
|
|
$tmpComposerDirFull = RESOURCES_DIR . '/tmp/ad/kernel/composer.json';
|
|
|
|
copy(ROOT_DIR . '/composer.json', $tmpComposerDirFull);
|
|
|
|
$this->out->r("/composer.json скопирован во временную папку", 'green');
|
|
|
|
} else {
|
|
|
|
$this->out->r("/composer.json не найден", 'red');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_dir(RESOURCES_DIR . '/tmp/app')) {
|
|
|
|
mkdir(RESOURCES_DIR . '/tmp/app');
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->files->pack(RESOURCES_DIR . '/tmp/ad/kernel/', RESOURCES_DIR . '/tmp/kernel/kernel.igk');
|
|
|
|
$this->files->recursiveRemoveDir(RESOURCES_DIR . '/tmp/ad/kernel/');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws \Exception
|
|
|
|
*/
|
|
|
|
public function actionUpdateKernel(): void
|
|
|
|
{
|
|
|
|
if (!isset($this->argv['path'])) {
|
|
|
|
throw new \Exception('Missing kernel path "--path" specified');
|
|
|
|
}
|
|
|
|
|
|
|
|
$zip = new ZipArchive;
|
|
|
|
if (file_exists(ROOT_DIR . $this->argv['path'])) {
|
|
|
|
$tmpKernelDir = md5(time());
|
|
|
|
$res = $zip->open(ROOT_DIR . $this->argv['path']);
|
|
|
|
if ($res === TRUE) {
|
|
|
|
$tmpKernelDirFull = RESOURCES_DIR . '/tmp/kernel/' . $tmpKernelDir . "/";
|
|
|
|
$zip->extractTo($tmpKernelDirFull);
|
|
|
|
$zip->close();
|
|
|
|
$this->files->recursiveRemoveKernelDir();
|
|
|
|
$this->files->copy_folder($tmpKernelDirFull . 'kernel' , ROOT_DIR . "/kernel");
|
2024-10-14 15:52:52 +03:00
|
|
|
|
2024-10-23 16:16:47 +03:00
|
|
|
if (isset($this->argv['bootstrap'])) {
|
|
|
|
$this->files->recursiveRemoveDir(ROOT_DIR . '/bootstrap');
|
|
|
|
$this->files->copy_folder($tmpKernelDirFull . 'bootstrap' , ROOT_DIR . '/bootstrap');
|
|
|
|
}
|
2024-10-14 15:52:52 +03:00
|
|
|
|
2024-10-23 16:16:47 +03:00
|
|
|
if (isset($this->argv['env'])) {
|
|
|
|
copy($tmpKernelDirFull . 'env.example', ROOT_DIR . '/.env.example');
|
|
|
|
}
|
2024-10-14 15:52:52 +03:00
|
|
|
|
2024-10-23 16:16:47 +03:00
|
|
|
if (isset($this->argv['composer'])) {
|
|
|
|
copy($tmpKernelDirFull . 'composer.json', ROOT_DIR . '/composer.json');
|
|
|
|
}
|
2024-10-14 15:52:52 +03:00
|
|
|
|
2024-10-23 16:16:47 +03:00
|
|
|
$this->files->recursiveRemoveDir($tmpKernelDirFull);
|
|
|
|
$this->out->r('Ядро обновлено.', 'green');
|
|
|
|
} else {
|
|
|
|
$this->out->r('unable to open zip archive', 'red');
|
|
|
|
}
|
2024-10-14 15:52:52 +03:00
|
|
|
} else {
|
2024-10-23 16:16:47 +03:00
|
|
|
$this->out->r("archive not found", 'red');
|
2024-10-14 15:52:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|