From 045bd837b761ef353f2ed265670e9d2432ee4ab5 Mon Sep 17 00:00:00 2001 From: stasbilay02 Date: Mon, 16 Dec 2024 14:21:37 +0300 Subject: [PATCH 1/6] kernel pack --- kernel/console/controllers/KernelController.php | 16 ++++++++++++---- kernel/manifest.json | 3 +++ 2 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 kernel/manifest.json diff --git a/kernel/console/controllers/KernelController.php b/kernel/console/controllers/KernelController.php index 147d84f..13efa75 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(KERNEL_DIR, $tmpKernelDirFull); + $this->files->copy_folder(ROOT_DIR . $this->argv['path'], $tmpKernelDirFull); $this->out->r("Ядро скопировано во временную папку", 'green'); } else { $this->out->r("Ядро не найдено", 'red'); @@ -65,11 +65,19 @@ class KernelController extends ConsoleController $this->out->r("/composer.json не найден", 'red'); } - if (!is_dir(RESOURCES_DIR . '/tmp/app')) { - mkdir(RESOURCES_DIR . '/tmp/app'); + if (!is_dir(RESOURCES_DIR . '/tmp/kernel')) { + mkdir(RESOURCES_DIR . '/tmp/kernel'); + } + + if (file_exists(KERNEL_DIR . '/manifest.json')) { + $manifest = json_decode(file_get_contents(KERNEL_DIR . '/manifest.json'), true); + $version = $manifest['version'] ?? ''; + $this->files->pack(RESOURCES_DIR . '/tmp/ad/kernel/', RESOURCES_DIR . '/tmp/kernel/kernel_v' . $version . '.igk'); + } + else { + $this->files->pack(RESOURCES_DIR . '/tmp/ad/kernel/', RESOURCES_DIR . '/tmp/kernel/kernel.igk'); } - $this->files->pack(RESOURCES_DIR . '/tmp/ad/kernel/', RESOURCES_DIR . '/tmp/kernel/kernel.igk'); $this->files->recursiveRemoveDir(RESOURCES_DIR . '/tmp/ad/kernel/'); } diff --git a/kernel/manifest.json b/kernel/manifest.json new file mode 100644 index 0000000..25031b0 --- /dev/null +++ b/kernel/manifest.json @@ -0,0 +1,3 @@ +{ + "version": "0.2" +} \ No newline at end of file From 2e4fc0496bf46756acfe9fb2bf8cd954e79fddc4 Mon Sep 17 00:00:00 2001 From: stasbilay02 Date: Tue, 17 Dec 2024 12:23:45 +0300 Subject: [PATCH 2/6] kernel update with igfs --- kernel/manifest.json | 9 +- .../ModuleShopClientController.php | 48 +++++++--- .../routs/module_shop_client.php | 4 + .../module_shop_client/views/index.php | 29 ++++-- .../views/kernel_update.php | 39 ++++++++ kernel/services/KernelService.php | 88 +++++++++++++++++++ kernel/services/ModuleService.php | 12 +-- 7 files changed, 199 insertions(+), 30 deletions(-) create mode 100644 kernel/modules/module_shop_client/views/kernel_update.php create mode 100644 kernel/services/KernelService.php diff --git a/kernel/manifest.json b/kernel/manifest.json index 25031b0..65282d4 100644 --- a/kernel/manifest.json +++ b/kernel/manifest.json @@ -1,3 +1,8 @@ { - "version": "0.2" -} \ No newline at end of file + "name": "Kernel", + "version": "0.2", + "author": "ITGuild", + "slug": "kernel", + "type": "kernel", + "description": "Kernel" +} diff --git a/kernel/modules/module_shop_client/controllers/ModuleShopClientController.php b/kernel/modules/module_shop_client/controllers/ModuleShopClientController.php index a83f465..f2f3f95 100644 --- a/kernel/modules/module_shop_client/controllers/ModuleShopClientController.php +++ b/kernel/modules/module_shop_client/controllers/ModuleShopClientController.php @@ -14,6 +14,7 @@ use kernel\helpers\SMTP; use kernel\Mailing; use kernel\modules\module_shop_client\services\ModuleShopClientService; use kernel\Request; +use kernel\services\KernelService; use kernel\services\ModuleService; use kernel\services\ModuleShopService; use kernel\services\TokenService; @@ -24,6 +25,7 @@ class ModuleShopClientController extends AdminController protected Client $client; protected ModuleService $moduleService; + protected KernelService $kernelService; protected function init(): void { @@ -32,6 +34,7 @@ class ModuleShopClientController extends AdminController $this->client = new Client(); $this->moduleService = new ModuleService(); + $this->kernelService = new KernelService(); } /** @@ -55,6 +58,7 @@ class ModuleShopClientController extends AdminController 'page_number' => $page_number, 'module_count' => $module_count, 'per_page' => $per_page, + 'kernelService' => new KernelService(), ]); } else { $this->cgView->render("module_shop_error_connection.php"); @@ -112,6 +116,36 @@ class ModuleShopClientController extends AdminController $this->redirect('/admin/module_shop_client', 302); } + public function actionRenderKernelUpdateForm(): void + { + $this->cgView->render("kernel_update.php"); + } + + #[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); + foreach ($modules_info as $module) { + if ($module['slug'] === 'kernel') { + $path = $module['path_to_archive']; + } + } + if (isset($path)) { + Files::uploadByUrl($_ENV['MODULE_SHOP_URL'] . $path, RESOURCES_DIR . "/tmp/kernel"); + if ($this->kernelService->updateKernel('/resources/tmp/kernel/' . basename($path))) { + Flash::setMessage("success", "Ядро успешно обновлено."); + } else { + Flash::setMessage("error", "Ошибка обновления ядра."); + } + } else { + Flash::setMessage("error", "Ошибка обновления ядра."); + } + + $this->redirect('/admin/module_shop_client', 302); + } + #[NoReturn] public function actionDelete(): void { $request = new Request(); @@ -131,13 +165,6 @@ class ModuleShopClientController extends AdminController $request = new Request(); $address = $request->post("email"); -// $mailing = new Mailing(); -// $mailing->send_html("login_by_code.php", ['code' => mt_rand(100000, 999999)], [ -// 'address' => $address, -// 'subject' => "Код авторизации", -// "from_name" => $_ENV['APP_NAME'] -// ]); - $moduleShopService = new ModuleShopService(); $result = $moduleShopService->email_auth($address); @@ -153,13 +180,6 @@ class ModuleShopClientController extends AdminController $request = new Request(); $code = $request->post("code"); -// $mailing = new Mailing(); -// $mailing->send_html("login_by_code.php", ['code' => mt_rand(100000, 999999)], [ -// 'address' => $address, -// 'subject' => "Код авторизации", -// "from_name" => $_ENV['APP_NAME'] -// ]); - $moduleShopService = new ModuleShopService(); $result = $moduleShopService->code_check($code); diff --git a/kernel/modules/module_shop_client/routs/module_shop_client.php b/kernel/modules/module_shop_client/routs/module_shop_client.php index 5004486..7e7a00a 100644 --- a/kernel/modules/module_shop_client/routs/module_shop_client.php +++ b/kernel/modules/module_shop_client/routs/module_shop_client.php @@ -17,6 +17,10 @@ App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){ App::$collector->get('/update', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionUpdate']); App::$collector->post('/auth', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionAuth']); App::$collector->post('/code_check', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionCodeCheck']); + App::$collector->group(["prefix" => "kernel"], function (RouteCollector $router) { + App::$collector->get('/update_form', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionRenderKernelUpdateForm']); + App::$collector->post('/update', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionKernelUpdate']); + }); }); }); }); \ No newline at end of file diff --git a/kernel/modules/module_shop_client/views/index.php b/kernel/modules/module_shop_client/views/index.php index bfe766d..da38552 100644 --- a/kernel/modules/module_shop_client/views/index.php +++ b/kernel/modules/module_shop_client/views/index.php @@ -5,6 +5,7 @@ * @var int $page_number * @var int $per_page * @var \kernel\services\ModuleService $moduleService + * @var \kernel\services\KernelService $kernelService */ use Itguild\Tables\ListJsonTable; @@ -37,21 +38,23 @@ $table->addAction(function ($row, $url) use ($moduleService) { }); $table->addAction(function ($row, $url) use ($moduleService){ - if ($moduleService->isInstall($row['slug'])){ - $url = "$url/delete/?slug=" . $row['slug']; + if ($row['slug'] !== 'kernel') { + if ($moduleService->isInstall($row['slug'])) { + $url = "$url/delete/?slug=" . $row['slug']; - return \kernel\widgets\IconBtn\IconBtnDeleteWidget::create(['url' => $url])->run(); - } - else { - $url = "$url/install/?id=" . $row['id']; + return \kernel\widgets\IconBtn\IconBtnDeleteWidget::create(['url' => $url])->run(); + } else { + $url = "$url/install/?id=" . $row['id']; - return \kernel\widgets\IconBtn\IconBtnInstallWidget::create(['url' => $url])->run(); + return \kernel\widgets\IconBtn\IconBtnInstallWidget::create(['url' => $url])->run(); + } } + return null; }); -$table->addAction(function ($row, $url) use ($moduleService){ +$table->addAction(function ($row, $url) use ($moduleService, $kernelService){ $slug = $row['slug']; - if ($moduleService->isInstall($slug)){ + if ($moduleService->isInstall($slug)) { if (!$moduleService->isLastVersion($slug)) { $url = "$url/update/?slug=" . $slug; @@ -59,6 +62,14 @@ $table->addAction(function ($row, $url) use ($moduleService){ } } + if ($slug === 'kernel') { + if (!$kernelService->isLastVersion()) { + $url = "$url/kernel/update_form/"; + + return \kernel\widgets\IconBtn\IconBtnUpdateWidget::create(['url' => $url])->run(); + } + } + return false; }); diff --git a/kernel/modules/module_shop_client/views/kernel_update.php b/kernel/modules/module_shop_client/views/kernel_update.php new file mode 100644 index 0000000..0bbe204 --- /dev/null +++ b/kernel/modules/module_shop_client/views/kernel_update.php @@ -0,0 +1,39 @@ +run(); + +echo \kernel\helpers\Html::h(2, "Выберите нужные файлы для обновления"); + +$form = new ActiveForm(); +$form->beginForm("/admin/module_shop_client/kernel/update/", enctype: 'multipart/form-data'); + +$form->field(\itguild\forms\inputs\Select::class, "files[]", [ + 'class' => "form-control", + 'multiple' => "multiple", +]) + ->setLabel("Дополнительные файлы") + ->setOptions([ + '.env.example' => '.env.example', + 'bootstrap.php' => 'bootstrap', + 'composer.json' => 'composer.json', + ]) + ->render(); +?> + +
+
+ field(\itguild\forms\inputs\Button::class, name: "btn-submit", params: [ + 'class' => "btn btn-primary ", + 'value' => 'Отправить', + 'typeInput' => 'submit' + ]) + ->render(); + ?> +
+ +
+endForm(); \ No newline at end of file diff --git a/kernel/services/KernelService.php b/kernel/services/KernelService.php new file mode 100644 index 0000000..45d0d5b --- /dev/null +++ b/kernel/services/KernelService.php @@ -0,0 +1,88 @@ +moduleService = new ModuleService(); + $this->files = new Files(); + } + + public function getKernelInfo(): false|array|string + { + $info = []; + $info['path'] = KERNEL_DIR; + if (file_exists(KERNEL_DIR . "/manifest.json")) { + $manifest = json_decode(file_get_contents(KERNEL_DIR . "/manifest.json"), true); + $manifest = getConst($manifest); + $info = array_merge($info, $manifest); + } + + return $info; + } + + public function isLastVersion(): bool + { + if ($this->moduleService->isServerAvailable()) { + $modules_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug'); + + $modules_info = json_decode($modules_info->getBody()->getContents(), true); + + $kernel_info = $this->getKernelInfo(); + foreach ($modules_info as $mod) { + if ($mod['slug'] === $kernel_info['slug'] && $mod['version'] === $kernel_info['version']) { + return true; + } + } + } + + return false; + } + + public function updateKernel(string $path): bool + { + $request = new Request(); + $files = $request->post('files'); + Debug::dd($files); + + $zip = new ZipArchive; + if (file_exists($path)) { + $tmpKernelDir = md5(time()); + $res = $zip->open($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"); + + foreach ($files as $file) { + if ($file === 'bootstrap') { + $this->files->recursiveRemoveDir(ROOT_DIR . '/bootstrap'); + $this->files->copy_folder($tmpKernelDirFull . 'bootstrap' , ROOT_DIR . '/bootstrap'); + } + copy($tmpKernelDirFull . $file , ROOT_DIR . '/' . $file); + } + + $this->files->recursiveRemoveDir($tmpKernelDirFull); + + return true; + } + } + + return false; + } +} \ No newline at end of file diff --git a/kernel/services/ModuleService.php b/kernel/services/ModuleService.php index 27c511a..7beb721 100644 --- a/kernel/services/ModuleService.php +++ b/kernel/services/ModuleService.php @@ -10,7 +10,6 @@ use kernel\helpers\Files; use kernel\helpers\Manifest; use kernel\helpers\RESTClient; use kernel\models\Option; -use MongoDB\Driver\Session; use ZipArchive; class ModuleService @@ -448,6 +447,7 @@ class ModuleService $modules_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug'); $modules_info = json_decode($modules_info->getBody()->getContents(), true); + $mod_info = $this->getModuleInfoBySlug($slug); foreach ($modules_info as $mod) { if ($mod['slug'] === $mod_info['slug'] && $mod['version'] === $mod_info['version']) { @@ -481,10 +481,12 @@ class ModuleService } $modules_info = json_decode($modules_info->getBody()->getContents(), true); - $mod_info = $this->getModuleInfoBySlug($slug); - foreach ($modules_info as $mod) { - if ($mod['slug'] === $mod_info['slug']) { - return true; + if (isset($modules_info)) { + $mod_info = $this->getModuleInfoBySlug($slug); + foreach ($modules_info as $mod) { + if ($mod['slug'] === $mod_info['slug']) { + return true; + } } } } From e6455165b3e53effe6faa56bf87905930a48b513 Mon Sep 17 00:00:00 2001 From: stasbilay02 Date: Tue, 17 Dec 2024 12:41:30 +0300 Subject: [PATCH 3/6] some fix --- .../controllers/ModuleShopClientController.php | 1 - kernel/services/KernelService.php | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/kernel/modules/module_shop_client/controllers/ModuleShopClientController.php b/kernel/modules/module_shop_client/controllers/ModuleShopClientController.php index f2f3f95..d2d9b7e 100644 --- a/kernel/modules/module_shop_client/controllers/ModuleShopClientController.php +++ b/kernel/modules/module_shop_client/controllers/ModuleShopClientController.php @@ -12,7 +12,6 @@ use kernel\helpers\Files; use kernel\helpers\RESTClient; use kernel\helpers\SMTP; use kernel\Mailing; -use kernel\modules\module_shop_client\services\ModuleShopClientService; use kernel\Request; use kernel\services\KernelService; use kernel\services\ModuleService; diff --git a/kernel/services/KernelService.php b/kernel/services/KernelService.php index 45d0d5b..c5c5368 100644 --- a/kernel/services/KernelService.php +++ b/kernel/services/KernelService.php @@ -59,9 +59,9 @@ class KernelService Debug::dd($files); $zip = new ZipArchive; - if (file_exists($path)) { + if (file_exists(ROOT_DIR . $path)) { $tmpKernelDir = md5(time()); - $res = $zip->open($path); + $res = $zip->open(ROOT_DIR . $path); if ($res === TRUE) { $tmpKernelDirFull = RESOURCES_DIR . '/tmp/kernel/' . $tmpKernelDir . "/"; $zip->extractTo($tmpKernelDirFull); From bbc7eafc3d0f273340cfbaa28c00940244b75c71 Mon Sep 17 00:00:00 2001 From: stasbilay02 Date: Tue, 17 Dec 2024 12:47:45 +0300 Subject: [PATCH 4/6] fix --- kernel/services/KernelService.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/kernel/services/KernelService.php b/kernel/services/KernelService.php index c5c5368..b1520a9 100644 --- a/kernel/services/KernelService.php +++ b/kernel/services/KernelService.php @@ -56,8 +56,7 @@ class KernelService { $request = new Request(); $files = $request->post('files'); - Debug::dd($files); - + $zip = new ZipArchive; if (file_exists(ROOT_DIR . $path)) { $tmpKernelDir = md5(time()); From e152e0f193585d81da2c0131db6148f784fd5329 Mon Sep 17 00:00:00 2001 From: stasbilay02 Date: Tue, 17 Dec 2024 13:02:25 +0300 Subject: [PATCH 5/6] some --- kernel/services/KernelService.php | 1 + 1 file changed, 1 insertion(+) diff --git a/kernel/services/KernelService.php b/kernel/services/KernelService.php index b1520a9..3caf8ec 100644 --- a/kernel/services/KernelService.php +++ b/kernel/services/KernelService.php @@ -77,6 +77,7 @@ class KernelService } $this->files->recursiveRemoveDir($tmpKernelDirFull); + unlink(ROOT_DIR . $path); return true; } From aa913293ef8db322cb9407909b62339a66163a75 Mon Sep 17 00:00:00 2001 From: stasbilay02 Date: Wed, 18 Dec 2024 12:27:29 +0300 Subject: [PATCH 6/6] admine theme --- kernel/manifest.json | 2 +- .../ModuleShopClientController.php | 2 + .../routs/module_shop_client.php | 4 ++ .../module_shop_client/views/index.php | 24 ++++++++++- kernel/services/AdminThemeService.php | 43 +++++++++++++++++++ 5 files changed, 73 insertions(+), 2 deletions(-) diff --git a/kernel/manifest.json b/kernel/manifest.json index 65282d4..3cccfd0 100644 --- a/kernel/manifest.json +++ b/kernel/manifest.json @@ -1,6 +1,6 @@ { "name": "Kernel", - "version": "0.2", + "version": "0.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 d2d9b7e..3612132 100644 --- a/kernel/modules/module_shop_client/controllers/ModuleShopClientController.php +++ b/kernel/modules/module_shop_client/controllers/ModuleShopClientController.php @@ -13,6 +13,7 @@ use kernel\helpers\RESTClient; use kernel\helpers\SMTP; use kernel\Mailing; use kernel\Request; +use kernel\services\AdminThemeService; use kernel\services\KernelService; use kernel\services\ModuleService; use kernel\services\ModuleShopService; @@ -58,6 +59,7 @@ class ModuleShopClientController extends AdminController 'module_count' => $module_count, 'per_page' => $per_page, 'kernelService' => new KernelService(), + 'adminThemeService' => new AdminThemeService(), ]); } else { $this->cgView->render("module_shop_error_connection.php"); diff --git a/kernel/modules/module_shop_client/routs/module_shop_client.php b/kernel/modules/module_shop_client/routs/module_shop_client.php index 7e7a00a..cd1a960 100644 --- a/kernel/modules/module_shop_client/routs/module_shop_client.php +++ b/kernel/modules/module_shop_client/routs/module_shop_client.php @@ -21,6 +21,10 @@ App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){ App::$collector->get('/update_form', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionRenderKernelUpdateForm']); App::$collector->post('/update', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionKernelUpdate']); }); + App::$collector->group(["prefix" => "admin_theme"], function (RouteCollector $router) { + App::$collector->get('/install', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionAdminThemeInstall']); + App::$collector->post('/update', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionAdminThemeUpdate']); + }); }); }); }); \ No newline at end of file diff --git a/kernel/modules/module_shop_client/views/index.php b/kernel/modules/module_shop_client/views/index.php index da38552..72ab7cd 100644 --- a/kernel/modules/module_shop_client/views/index.php +++ b/kernel/modules/module_shop_client/views/index.php @@ -6,6 +6,7 @@ * @var int $per_page * @var \kernel\services\ModuleService $moduleService * @var \kernel\services\KernelService $kernelService + * @var \kernel\services\AdminThemeService $adminThemeService */ use Itguild\Tables\ListJsonTable; @@ -52,7 +53,7 @@ $table->addAction(function ($row, $url) use ($moduleService){ return null; }); -$table->addAction(function ($row, $url) use ($moduleService, $kernelService){ +$table->addAction(function ($row, $url) use ($moduleService) { $slug = $row['slug']; if ($moduleService->isInstall($slug)) { if (!$moduleService->isLastVersion($slug)) { @@ -62,6 +63,11 @@ $table->addAction(function ($row, $url) use ($moduleService, $kernelService){ } } + return false; +}); + +$table->addAction(function ($row, $url) use ($kernelService) { + $slug = $row['slug']; if ($slug === 'kernel') { if (!$kernelService->isLastVersion()) { $url = "$url/kernel/update_form/"; @@ -73,6 +79,22 @@ $table->addAction(function ($row, $url) use ($moduleService, $kernelService){ return false; }); +$table->addAction(function ($row, $url) use ($adminThemeService) { + $type = $row['type']; + $slug = $row['slug']; + if ($type === 'admin_theme') { + if ($adminThemeService->isInstall($slug)) { + if (!$adminThemeService->isLastVersion($slug)) { + $url = "$url/admin_theme/update/"; + + return \kernel\widgets\IconBtn\IconBtnUpdateWidget::create(['url' => $url])->run(); + } + } + } + + return false; +}); + \kernel\widgets\ModuleTabsWidget::create()->run(); $table->create(); diff --git a/kernel/services/AdminThemeService.php b/kernel/services/AdminThemeService.php index c833cbb..457fa02 100644 --- a/kernel/services/AdminThemeService.php +++ b/kernel/services/AdminThemeService.php @@ -2,20 +2,24 @@ namespace kernel\services; +use DirectoryIterator; use kernel\helpers\Debug; use kernel\helpers\Manifest; +use kernel\helpers\RESTClient; use kernel\models\Option; class AdminThemeService { protected Option $option; protected string $active_theme; + protected ModuleService $moduleService; public function __construct() { $this->option = new Option(); $this->findActiveAdminTheme(); + $this->moduleService = new ModuleService(); } public function findActiveAdminTheme(): void @@ -56,4 +60,43 @@ class AdminThemeService return $info; } + public function isInstall(string $slug): bool + { + $adminThemePaths = Option::where("key", "admin_theme_paths")->first(); + $dirs = []; + if ($adminThemePaths) { + $path = json_decode($adminThemePaths->value); + foreach ($path->paths as $p) { + $dirs[] = getConst($p); + } + } + foreach ($dirs as $dir) { + foreach (new DirectoryIterator($dir) as $fileInfo) { + if ($fileInfo->isDot()) continue; + if ($this->getAdminThemeInfo($fileInfo->getPathname())['slug'] === $slug) { + return true; + } + } + } + + return false; + } + + public function isLastVersion(string $slug): bool + { + if ($this->moduleService->isServerAvailable()) { + $modules_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug'); + + $modules_info = json_decode($modules_info->getBody()->getContents(), true); + + $themeInfo = $this->getAdminThemeInfo($slug); + foreach ($modules_info as $mod) { + if ($mod['slug'] === $themeInfo['slug'] && $mod['version'] === $themeInfo['version']) { + return true; + } + } + } + + return false; + } } \ No newline at end of file