From 653c94cf16d29c1f9f3035f8ca659a5e2f75ed36 Mon Sep 17 00:00:00 2001 From: Rias Date: Mon, 21 May 2018 10:35:08 +0200 Subject: [PATCH] No longer queue notifications --- CHANGELOG.md | 4 ++ composer.json | 2 +- src/Notifications.php | 23 +++--------- src/jobs/SendNotification.php | 69 ----------------------------------- 4 files changed, 10 insertions(+), 88 deletions(-) delete mode 100644 src/jobs/SendNotification.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 2bd4028..5cad64a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## 1.1.0 - 2018-05-21 +### Changed +- Notifications are no longer queued as this causes a lot of issues with serialization. Will find a better solution for this in the future. + ## 1.0.6 - 2018-03-06 ### Added - Notification now extends the Craft base model for easier configuration diff --git a/composer.json b/composer.json index 81a5043..9a1e73f 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "rias/craft-notifications", "description": "Send notifications across a variety of delivery channels, including mail and Slack. Notifications may also be stored in a database so they may be displayed in your web interface.", "type": "craft-plugin", - "version": "1.0.6", + "version": "1.1.0", "keywords": [ "craft", "cms", diff --git a/src/Notifications.php b/src/Notifications.php index 875fe68..699e0dc 100644 --- a/src/Notifications.php +++ b/src/Notifications.php @@ -19,7 +19,6 @@ use craft\console\Application as ConsoleApplication; use craft\web\twig\variables\CraftVariable; use yii\base\Event; -use yii\queue\serializers\PhpSerializer; /** * Craft plugins are very much like little applications in and of themselves. We’ve made @@ -91,24 +90,12 @@ function (Event $event) { $notificationSettings['class'], $notificationSettings['event'], function (Event $event) use ($notificationSettings) { - try { - // Make sure the event can be serialized - $serializer = new PhpSerializer(); - $serializer->serialize($event); + /* @var Notification $notification */ + $notification = $notificationSettings['notification']; - // Create a queue job to send the notification if the notification should be queued - Craft::$app->queue->push(new SendNotification([ - 'notificationSettings' => $notificationSettings, - 'event' => $event, - ])); - } catch (\Exception $e) { // Don't queue the notification if it cannot be serialized - /* @var Notification $notification */ - $notification = $notificationSettings['notification']; - - Notifications::$plugin->notificationsService->send( - new $notification(['event' => $event]) - ); - } + Notifications::$plugin->notificationsService->send( + new $notification(['event' => $event]) + ); } ); } diff --git a/src/jobs/SendNotification.php b/src/jobs/SendNotification.php deleted file mode 100644 index 0993448..0000000 --- a/src/jobs/SendNotification.php +++ /dev/null @@ -1,69 +0,0 @@ -notificationSettings['notification']; - - Notifications::$plugin->notificationsService->send( - new $notification(['event' => $this->event]) - ); - } - - // Protected Methods - // ========================================================================= - /** - * @inheritdoc - */ - protected function defaultDescription(): string - { - return Craft::t('notifications', 'Sending notifications'); - } -}