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