This commit is contained in:
Kavalar 2024-12-19 11:01:55 +03:00
commit 7a7241746a
9 changed files with 73 additions and 19 deletions

View File

@ -27,7 +27,7 @@ class KernelController extends ConsoleController
if (file_exists(ROOT_DIR . $this->argv['path'])) {
$tmpKernelDirFull = RESOURCES_DIR . '/tmp/ad/kernel/kernel';
$this->files->copy_folder(ROOT_DIR . $this->argv['path'], $tmpKernelDirFull);
$this->files->copyKernelFolder(ROOT_DIR . $this->argv['path'], $tmpKernelDirFull);
$this->out->r("Ядро скопировано во временную папку", 'green');
} else {
$this->out->r("Ядро не найдено", 'red');
@ -35,7 +35,7 @@ class KernelController extends ConsoleController
if (file_exists(ROOT_DIR . '/bootstrap')) {
$tmpBootstrapDirFull = RESOURCES_DIR . '/tmp/ad/kernel/bootstrap';
$this->files->copy_folder(ROOT_DIR . '/bootstrap', $tmpBootstrapDirFull);
$this->files->copyKernelFolder(ROOT_DIR . '/bootstrap', $tmpBootstrapDirFull);
$this->out->r("/bootstrap скопирован во временную папку", 'green');
} else {
$this->out->r("/bootstrap не найден", 'red');
@ -99,11 +99,11 @@ class KernelController extends ConsoleController
$zip->extractTo($tmpKernelDirFull);
$zip->close();
$this->files->recursiveRemoveKernelDir();
$this->files->copy_folder($tmpKernelDirFull . 'kernel' , ROOT_DIR . "/kernel");
$this->files->copyKernelFolder($tmpKernelDirFull . 'kernel' , ROOT_DIR . "/kernel");
if (isset($this->argv['bootstrap'])) {
$this->files->recursiveRemoveDir(ROOT_DIR . '/bootstrap');
$this->files->copy_folder($tmpKernelDirFull . 'bootstrap' , ROOT_DIR . '/bootstrap');
$this->files->copyKernelFolder($tmpKernelDirFull . 'bootstrap' , ROOT_DIR . '/bootstrap');
copy($tmpKernelDirFull . '/bootstrap.php' , ROOT_DIR . '/bootstrap.php');
}

View File

@ -6,13 +6,9 @@ use DirectoryIterator;
use JetBrains\PhpStorm\NoReturn;
use Josantonius\Session\Facades\Session;
use kernel\AdminController;
use kernel\EntityRelation;
use kernel\helpers\Debug;
use kernel\models\Option;
use kernel\modules\module_shop_client\services\ModuleShopClientService;
use kernel\modules\user\service\UserService;
use kernel\Request;
use kernel\services\MigrationService;
use kernel\services\ModuleService;
class ModuleController extends AdminController

View File

@ -7,11 +7,38 @@ use ZipArchive;
class Files
{
public function copy_folder($d1, $d2): void
public function copy_folder($d1, $d2, int $permissions = 0775, bool $recursive = true): void
{
if (is_dir($d1)) {
if (!file_exists($d2)){
$_d2 = mkdir($d2, permissions: 0774, recursive: true);
$old_mask = umask(0);
$_d2 = mkdir($d2, permissions: $permissions, recursive: $recursive);
umask($old_mask);
if (!$_d2) {
return;
}
}
$d = dir($d1);
while (false !== ($entry = $d->read())) {
if ($entry != '.' && $entry != '..') {
$this->copy_folder("$d1/$entry", "$d2/$entry");
}
}
$d->close();
} else {
copy($d1, $d2);
chmod($d2, permissions: $permissions);
}
}
public function copyKernelFolder($d1, $d2, int $permissions = 0775, bool $recursive = true): void
{
if (is_dir($d1)) {
if (!file_exists($d2)){
$old_mask = umask(0);
$_d2 = mkdir($d2, permissions: $permissions, recursive: $recursive);
umask($old_mask);
if (!$_d2) {
return;
}
@ -20,12 +47,13 @@ class Files
$d = dir($d1);
while (false !== ($entry = $d->read())) {
if ($entry != '.' && $entry != '..' && $entry != 'app_modules') {
$this->copy_folder("$d1/$entry", "$d2/$entry");
$this->copyKernelFolder("$d1/$entry", "$d2/$entry");
}
}
$d->close();
} else {
copy($d1, $d2);
chmod($d2, permissions: $permissions);
}
}

View File

@ -0,0 +1,16 @@
<?php
namespace kernel\helpers;
class Version
{
public static function getIntVersionByString(string $version): int
{
$version = preg_replace('/[^0-9]+/', '', $version);
return match (strlen($version)) {
1 => intval($version) * 100,
2 => intval($version) * 10,
3 => intval($version),
};
}
}

View File

@ -1,6 +1,6 @@
{
"name": "Kernel",
"version": "0.1",
"version": "0.1.1",
"author": "ITGuild",
"slug": "kernel",
"type": "kernel",

View File

@ -124,7 +124,6 @@ class ModuleShopClientController extends AdminController
#[NoReturn] public function actionKernelUpdate(): void
{
$request = new Request();
$modules_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug');
$modules_info = json_decode($modules_info->getBody()->getContents(), true);

View File

@ -15,7 +15,7 @@ $form->field(\itguild\forms\inputs\Select::class, "files[]", [
])
->setLabel("Дополнительные файлы")
->setOptions([
'.env.example' => '.env.example',
'env.example' => 'env.example',
'bootstrap.php' => 'bootstrap',
'composer.json' => 'composer.json',
])

View File

@ -6,6 +6,7 @@ use kernel\helpers\Debug;
use kernel\helpers\Files;
use kernel\helpers\Manifest;
use kernel\helpers\RESTClient;
use kernel\helpers\Version;
use kernel\Request;
use ZipArchive;
@ -42,8 +43,12 @@ class KernelService
$modules_info = json_decode($modules_info->getBody()->getContents(), true);
$kernel_info = $this->getKernelInfo();
$kernelVersion = Version::getIntVersionByString($kernel_info['version']);
foreach ($modules_info as $mod) {
if ($mod['slug'] === $kernel_info['slug'] && $mod['version'] === $kernel_info['version']) {
$modVersion = Version::getIntVersionByString($mod['version']);
if ($mod['slug'] === $kernel_info['slug'] && $modVersion <= $kernelVersion) {
return true;
}
}
@ -66,14 +71,20 @@ class KernelService
$zip->extractTo($tmpKernelDirFull);
$zip->close();
$this->files->recursiveRemoveKernelDir();
$this->files->copy_folder($tmpKernelDirFull . 'kernel' , ROOT_DIR . "/kernel");
$this->files->copyKernelFolder($tmpKernelDirFull . 'kernel' , ROOT_DIR . "/kernel");
foreach ($files as $file) {
if ($file === 'bootstrap') {
if ($file === 'bootstrap.php') {
$this->files->recursiveRemoveDir(ROOT_DIR . '/bootstrap');
$this->files->copy_folder($tmpKernelDirFull . 'bootstrap' , ROOT_DIR . '/bootstrap');
$this->files->copyKernelFolder($tmpKernelDirFull . 'bootstrap' , ROOT_DIR . '/bootstrap');
}
if ($file === 'env.example') {
copy($tmpKernelDirFull . $file , ROOT_DIR . '/.' . $file);
chmod(ROOT_DIR . '/.' . $file, 0775);
continue;
}
copy($tmpKernelDirFull . $file , ROOT_DIR . '/' . $file);
chmod(ROOT_DIR . '/' . $file, 0775);
}
$this->files->recursiveRemoveDir($tmpKernelDirFull);

View File

@ -9,6 +9,7 @@ use kernel\helpers\Debug;
use kernel\helpers\Files;
use kernel\helpers\Manifest;
use kernel\helpers\RESTClient;
use kernel\helpers\Version;
use kernel\models\Option;
use ZipArchive;
@ -449,8 +450,11 @@ class ModuleService
$modules_info = json_decode($modules_info->getBody()->getContents(), true);
$mod_info = $this->getModuleInfoBySlug($slug);
$currentVersion = Version::getIntVersionByString($mod_info['version']);
foreach ($modules_info as $mod) {
if ($mod['slug'] === $mod_info['slug'] && $mod['version'] === $mod_info['version']) {
$modVersion = Version::getIntVersionByString($mod['version']);
if ($mod['slug'] === $mod_info['slug'] && $modVersion <= $currentVersion) {
return true;
}
}