From f68b16c58af941fe989bc6f23386fe5df8a6c1e0 Mon Sep 17 00:00:00 2001 From: Guga Date: Mon, 30 Mar 2020 21:29:36 -0300 Subject: [PATCH 1/2] Fix docs in database messages --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5f762fd..4445fa7 100644 --- a/README.md +++ b/README.md @@ -124,7 +124,7 @@ class InvoicePaid implements NotificationInterface public function exportForDatabase() { return \Yii::createObject([ - 'class' => '\tuyakhov\notifications\messages\DatabaseChannel', + 'class' => '\tuyakhov\notifications\messages\DatabaseMessage', 'subject' => "Invoice has been paid", 'body' => "Your invoice #{$this->invoice->id} has been paid", 'data' => [ @@ -212,4 +212,4 @@ foreach($model->unreadNotifications as $notification) { $notification->isUnread(); $notification->isRead(); } -``` \ No newline at end of file +``` From 9073d9e426ff58a6dc0bb536e1e84a5cd66e077d Mon Sep 17 00:00:00 2001 From: Guga Date: Mon, 30 Mar 2020 21:29:56 -0300 Subject: [PATCH 2/2] Add log when erro occur in send notification --- src/Notifier.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Notifier.php b/src/Notifier.php index 0eeac13..1e1ed72 100644 --- a/src/Notifier.php +++ b/src/Notifier.php @@ -63,7 +63,7 @@ class Notifier extends Component /** * Sends the given notifications through available channels to the given notifiable entities. * You may pass an array in order to send multiple notifications to multiple recipients. - * + * * @param array|NotifiableInterface $recipients the recipients that can receive given notifications. * @param array|NotificationInterface $notifications the notification that should be delivered. * @return void @@ -77,14 +77,14 @@ public function send($recipients, $notifications) */ $recipients = [$recipients]; } - + if (!is_array($notifications)){ /** * @var $notifications NotificationInterface[] */ $notifications = [$notifications]; } - + foreach ($recipients as $recipient) { $channels = array_intersect($recipient->viaChannels(), array_keys($this->channels)); foreach ($notifications as $notification) { @@ -99,6 +99,7 @@ public function send($recipients, $notifications) \Yii::info("Sending notification " . get_class($notification) . " to " . get_class($recipient) . " via {$channel}", __METHOD__); $response = $channelInstance->send($recipient, $notification); } catch (\Exception $e) { + \Yii::error($e->getMessage()); $response = $e; } $this->trigger(self::EVENT_AFTER_SEND, new NotificationEvent([ @@ -128,4 +129,4 @@ protected function getChannelInstance($channel) } return $this->channels[$channel]; } -} \ No newline at end of file +}