diff --git a/helpers/system_notification.php b/helpers/system_notification.php index a2cfd6b..a91044e 100644 --- a/helpers/system_notification.php +++ b/helpers/system_notification.php @@ -7,6 +7,12 @@ * Date: 2/12/20 * Time: 11:00 */ +if (!function_exists('_sn_helper_error_message_')) { + function _sn_helper_error_message_($e): string + { + return 'Error File: ' . $e->getFile() . ' - Line: ' . $e->getLine() . ' - Code: ' . $e->getCode() . ' - Message: ' . $e->getMessage(); + } +} if (!function_exists('system_notification_to_mantis')) { /** * Hàm gửi thông báo, cảnh báo hệ thống tới Mantis Bug Tracker diff --git a/src/ProjectInterface.php b/src/ProjectInterface.php index 14254ca..ac2bf2f 100644 --- a/src/ProjectInterface.php +++ b/src/ProjectInterface.php @@ -17,8 +17,8 @@ */ interface ProjectInterface { - const VERSION = '3.0.7'; - const LAST_MODIFIED = '2022-03-15'; + const VERSION = '3.0.8'; + const LAST_MODIFIED = '2022-08-15'; const AUTHOR_NAME = 'Hung Nguyen'; const AUTHOR_EMAIL = 'dev@nguyenanhung.com'; const PROJECT_NAME = 'Monitor Connector'; diff --git a/src/SystemNotification.php b/src/SystemNotification.php index 7696321..53336c4 100644 --- a/src/SystemNotification.php +++ b/src/SystemNotification.php @@ -57,16 +57,14 @@ public static function mantis(array $sdkConfig = array(), string $module = '', s ->setMonitorPassword($options['monitorPassword']) ->setProjectId($options['monitorProjectId']) ->mantis($monitorProjectName . $title . ' - ' . $module, $description); - return true; } } catch (Exception $e) { if (function_exists('log_message')) { - log_message('error', 'Error Message: ' . $e->getMessage()); + log_message('error', _sn_helper_error_message_($e)); log_message('error', 'Error Trace As String: ' . $e->getTraceAsString()); } } - return false; } @@ -103,16 +101,14 @@ public static function slack(array $sdkConfig = array(), string $module = '', st $handle->setAttachMessage($attachMessage); } $handle->send(); - return true; } } catch (Exception $e) { if (function_exists('log_message')) { - log_message('error', 'Error Message: ' . $e->getMessage()); + log_message('error', _sn_helper_error_message_($e)); log_message('error', 'Error Trace As String: ' . $e->getTraceAsString()); } } - return false; } @@ -143,20 +139,15 @@ public static function telegram(array $sdkConfig = array(), string $module = '', $chatId = $config['default_chat_id'] ?? null; } $handle = new TelegramMessenger(); - $handle->setSdkConfig($sdkConfig) - ->setChatId($chatId) - ->setMessage($message) - ->sendMessage(); - + $handle->setSdkConfig($sdkConfig)->setChatId($chatId)->setMessage($message)->sendMessage(); return true; } } catch (Exception $e) { if (function_exists('log_message')) { - log_message('error', 'Error Message: ' . $e->getMessage()); + log_message('error', _sn_helper_error_message_($e)); log_message('error', 'Error Trace As String: ' . $e->getTraceAsString()); } } - return false; } @@ -191,20 +182,15 @@ public static function google_chat(array $sdkConfig = array(), string $module = $access_key = $config['access_key'] ?? null; $access_token = $config['access_token'] ?? null; $handle = new Notifier(); - $handle->setSpaceId($chatId) - ->setKey($access_key) - ->setToken($access_token) - ->setMessage($message); - + $handle->setSpaceId($chatId)->setKey($access_key)->setToken($access_token)->setMessage($message); return $handle->send(); } } catch (Exception $e) { if (function_exists('log_message')) { - log_message('error', 'Error Message: ' . $e->getMessage()); + log_message('error', _sn_helper_error_message_($e)); log_message('error', 'Error Trace As String: ' . $e->getTraceAsString()); } } - return false; } @@ -234,18 +220,15 @@ public static function teams(array $sdkConfig = array(), string $module = '', st $title = $monitorProjectName . $module; $textMessage = $message; $teams = new MicrosoftTeamsConnector(); - $teams->setWebHook($webhookUrl) - ->simpleMessage($title, $textMessage); - + $teams->setWebHook($webhookUrl)->simpleMessage($title, $textMessage); return true; } } catch (Exception $e) { if (function_exists('log_message')) { - log_message('error', 'Error Message: ' . $e->getMessage()); + log_message('error', _sn_helper_error_message_($e)); log_message('error', 'Error Trace As String: ' . $e->getTraceAsString()); } } - return false; } }