is server available

This commit is contained in:
Kavalar 2024-12-02 16:38:05 +03:00
parent a1bed2d9f2
commit 13978449a2
2 changed files with 21 additions and 4 deletions

View File

@ -17,6 +17,8 @@ class ModuleService
{
protected array $errors = [];
protected null|bool $serverAvailable = null;
/**
* @param string $module
* @return false|array|string
@ -442,7 +444,7 @@ class ModuleService
public function isLastVersion(string $slug): bool
{
try {
if ($this->isServerAvailable()){
$modules_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug');
$modules_info = json_decode($modules_info->getBody()->getContents(), true);
@ -452,8 +454,6 @@ class ModuleService
return true;
}
}
} catch (\Exception $e) {
throw new \Exception("Не удалось получить доступ к магазину модулей");
}
return false;
@ -482,4 +482,21 @@ class ModuleService
return $modules_info;
}
public function isServerAvailable(): bool
{
if (null !== $this->serverAvailable){
return $this->serverAvailable;
}
try {
RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug');
$this->serverAvailable = true;
return true;
} catch (\Exception $e) {
$this->serverAvailable = false;
return false;
}
}
}

View File

@ -75,7 +75,7 @@ $table->addAction(function ($row) use ($moduleService){
return false;
});
if ($moduleService->isActive('module_shop_client')) {
if ($moduleService->isActive('module_shop_client') && $moduleService->isServerAvailable()) {
ModuleTabsWidget::create()->run();
}