From: fomichev Date: Mon, 18 Nov 2024 12:15:32 +0000 (+0300) Subject: Создание константы и метода проверки в TelegramService X-Git-Tag: 1.7~227^2~1 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=6da558a500450f6db5e5e3b7b3cf4870efa9299d;p=erp24_rep%2Fyii-erp24%2F.git Создание константы и метода проверки в TelegramService --- diff --git a/erp24/actions/log/CollectAction.php b/erp24/actions/log/CollectAction.php index d763be9d..c6a8faa6 100755 --- a/erp24/actions/log/CollectAction.php +++ b/erp24/actions/log/CollectAction.php @@ -36,8 +36,8 @@ class CollectAction extends Action return; }*/ - $currentUrl = Yii::$app->request->getHostInfo(); - $isDev = !str_contains($currentUrl, 'erp.erp-flowers.ru'); + + $isDev = TelegramService::isDevelopmentEnvironment(TelegramService::TARGET_PROD_URL); // Формируем сообщение для отправки в Telegram с использованием MarkdownV2 $errorMessage = "⚠️*Ошибка JavaScript Обнаружена*⚠️\n\n"; @@ -45,7 +45,7 @@ class CollectAction extends Action if ($url = $this->controller->request->getReferrer()) { $errorMessage .= "*URL:*\n```" . TelegramService::escapeMarkdownLog($url) . "```\n\n"; - $isDev = !str_contains($url, 'erp.erp-flowers.ru'); + $isDev = !str_contains($url, TelegramService::TARGET_PROD_URL); } if ($createdAt = date('Y-m-d H:i:s', $log->log_time)) { diff --git a/erp24/log/TelegramTarget.php b/erp24/log/TelegramTarget.php index d544fe07..5c410326 100644 --- a/erp24/log/TelegramTarget.php +++ b/erp24/log/TelegramTarget.php @@ -110,7 +110,13 @@ class TelegramTarget extends \yii\log\Target $errorUrl = $message->getUrl(); - $isDev = !str_contains($errorUrl, 'erp.erp-flowers.ru'); + + if(!empty($errorUrl)){ + $isDev = !str_contains($errorUrl, TelegramService::TARGET_PROD_URL); + }else { + $isDev = TelegramService::isDevelopmentEnvironment(TelegramService::TARGET_PROD_URL); + } + // Проверка наличия подобных сообщений diff --git a/erp24/services/InfoLogService.php b/erp24/services/InfoLogService.php index 889a11cd..636a1c02 100644 --- a/erp24/services/InfoLogService.php +++ b/erp24/services/InfoLogService.php @@ -34,8 +34,9 @@ class InfoLogService /* if (!self::shouldSendToTelegram($file, $line, $messageText, $context)) { return; }*/ - $currentUrl = Yii::$app->request->getHostInfo(); - $isDev = !str_contains($currentUrl, 'erp.erp-flowers.ru'); + + $isDev = TelegramService::isDevelopmentEnvironment(TelegramService::TARGET_PROD_URL); + $telegramMessage = "⚠️*Сообщение из InfoLog*⚠️\n\n"; diff --git a/erp24/services/LogService.php b/erp24/services/LogService.php index 1bd860ac..022678f7 100644 --- a/erp24/services/LogService.php +++ b/erp24/services/LogService.php @@ -67,8 +67,8 @@ class LogService return; }*/ - $currentUrl = Yii::$app->request->getHostInfo(); - $isDev = !str_contains($currentUrl, 'erp.erp-flowers.ru'); + + $isDev = TelegramService::isDevelopmentEnvironment(TelegramService::TARGET_PROD_URL); // Форматирование сообщения об ошибке с условным добавлением строк $errorMessage = "⚠️*Ошибка API Обнаружена*⚠️\n\n"; @@ -76,8 +76,7 @@ class LogService // Добавляем строки только если параметры присутствуют if ($url = $apiErrorLog->url) { $errorMessage .= "*URL:*\n```" . TelegramService::escapeMarkdownLog($url) . "```\n\n"; - $errorUrl = $apiErrorLog->url; - $isDev = !str_contains($errorUrl, 'erp.erp-flowers.ru'); + $isDev = !str_contains($url, TelegramService::TARGET_PROD_URL); } if ($createdAt = $apiErrorLog->created_at) { diff --git a/erp24/services/TelegramService.php b/erp24/services/TelegramService.php index 110f5f09..02ca1735 100644 --- a/erp24/services/TelegramService.php +++ b/erp24/services/TelegramService.php @@ -10,6 +10,7 @@ class TelegramService { const TELEGRAM_API_URL = "8063257458:AAGnMf4cxwJWlYLF1wS_arn4PrOaLs9ERQQ"; + const TARGET_PROD_URL = "erp.erp-flowers.ru"; const CHAT_CHANNEL_ID ="-1001861631125"; const CHAT_CHANNEL_ERP_ID ="-1002338329426"; public static function sendMessage($admin_id, $message, $reply_markup = null) { @@ -21,6 +22,12 @@ class TelegramService { return $client->request('GET', $url); } + public static function isDevelopmentEnvironment($prodUrl) : bool + { + $currentUrl = Yii::$app->request->getHostInfo(); + return !str_contains($currentUrl, $prodUrl); + } + public static function sendErrorToTelegramMessage($message,$disableNotification, $isDev) { $botToken = self::TELEGRAM_API_URL;