version fix

This commit is contained in:
Билай Станислав 2024-12-18 15:24:25 +03:00
parent aa913293ef
commit a0a99de862
6 changed files with 59 additions and 12 deletions

View File

@ -1,7 +1,7 @@
<?php <?php
$secure_config = [ $secure_config = [
'web_auth_type' => 'email_code', // login_password, email_code 'web_auth_type' => 'login_password', // login_password, email_code
'token_type' => 'hash', // random_bytes, md5, crypt, hash, JWT 'token_type' => 'hash', // random_bytes, md5, crypt, hash, JWT
'token_expired_time' => "+30 days", // +1 day 'token_expired_time' => "+30 days", // +1 day
]; ];

View File

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

View File

@ -7,11 +7,33 @@ use ZipArchive;
class Files class Files
{ {
public function copy_folder($d1, $d2): void public function copy_folder($d1, $d2, int $permissions = 0774, bool $recursive = true): void
{ {
if (is_dir($d1)) { if (is_dir($d1)) {
if (!file_exists($d2)){ if (!file_exists($d2)){
$_d2 = mkdir($d2, permissions: 0774, recursive: true); $_d2 = mkdir($d2, permissions: $permissions, recursive: $recursive);
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);
}
}
public function copyKernelFolder($d1, $d2, int $permissions = 0774, bool $recursive = true): void
{
if (is_dir($d1)) {
if (!file_exists($d2)){
$_d2 = mkdir($d2, permissions: $permissions, recursive: $recursive);
if (!$_d2) { if (!$_d2) {
return; return;
} }
@ -20,7 +42,7 @@ class Files
$d = dir($d1); $d = dir($d1);
while (false !== ($entry = $d->read())) { while (false !== ($entry = $d->read())) {
if ($entry != '.' && $entry != '..' && $entry != 'app_modules') { if ($entry != '.' && $entry != '..' && $entry != 'app_modules') {
$this->copy_folder("$d1/$entry", "$d2/$entry"); $this->copyKernelFolder("$d1/$entry", "$d2/$entry");
} }
} }
$d->close(); $d->close();

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

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

View File

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