diff --git a/kernel/console/controllers/KernelController.php b/kernel/console/controllers/KernelController.php index 13efa75..e6a3a2a 100644 --- a/kernel/console/controllers/KernelController.php +++ b/kernel/console/controllers/KernelController.php @@ -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'); } diff --git a/kernel/controllers/ModuleController.php b/kernel/controllers/ModuleController.php index e0fc983..8ce4d4e 100644 --- a/kernel/controllers/ModuleController.php +++ b/kernel/controllers/ModuleController.php @@ -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 diff --git a/kernel/helpers/Files.php b/kernel/helpers/Files.php index e05a3a1..2360dd7 100644 --- a/kernel/helpers/Files.php +++ b/kernel/helpers/Files.php @@ -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); } } diff --git a/kernel/helpers/Version.php b/kernel/helpers/Version.php new file mode 100644 index 0000000..3380436 --- /dev/null +++ b/kernel/helpers/Version.php @@ -0,0 +1,16 @@ + intval($version) * 100, + 2 => intval($version) * 10, + 3 => intval($version), + }; + } +} \ No newline at end of file diff --git a/kernel/manifest.json b/kernel/manifest.json index 3cccfd0..6521135 100644 --- a/kernel/manifest.json +++ b/kernel/manifest.json @@ -1,6 +1,6 @@ { "name": "Kernel", - "version": "0.1", + "version": "0.1.1", "author": "ITGuild", "slug": "kernel", "type": "kernel", diff --git a/kernel/modules/module_shop_client/controllers/ModuleShopClientController.php b/kernel/modules/module_shop_client/controllers/ModuleShopClientController.php index 3612132..5ad60cd 100644 --- a/kernel/modules/module_shop_client/controllers/ModuleShopClientController.php +++ b/kernel/modules/module_shop_client/controllers/ModuleShopClientController.php @@ -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); diff --git a/kernel/modules/module_shop_client/views/kernel_update.php b/kernel/modules/module_shop_client/views/kernel_update.php index 0bbe204..ca520f4 100644 --- a/kernel/modules/module_shop_client/views/kernel_update.php +++ b/kernel/modules/module_shop_client/views/kernel_update.php @@ -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', ]) diff --git a/kernel/services/KernelService.php b/kernel/services/KernelService.php index 3caf8ec..28c42fc 100644 --- a/kernel/services/KernelService.php +++ b/kernel/services/KernelService.php @@ -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); diff --git a/kernel/services/ModuleService.php b/kernel/services/ModuleService.php index 7beb721..3d769fa 100644 --- a/kernel/services/ModuleService.php +++ b/kernel/services/ModuleService.php @@ -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; } }