From e6968b320e50e2a4ccc836b50fd1d66f8f4c4234 Mon Sep 17 00:00:00 2001 From: Florian DAL FITTO Date: Sun, 27 Aug 2023 22:29:26 +0200 Subject: [PATCH] [K6.2] Store notifications mail in database to be sent by CRON #9555 --- src/admin/install/kunena.install.upgrade.xml | 19 ++++++++++ .../sql/install/mysql/create_tables.utf8.sql | 14 +++++++ .../src/Forum/Message/KunenaMessage.php | 38 ++++++++++++++++++- 3 files changed, 70 insertions(+), 1 deletion(-) diff --git a/src/admin/install/kunena.install.upgrade.xml b/src/admin/install/kunena.install.upgrade.xml index 6cdf4b4b098..7cada6d907d 100644 --- a/src/admin/install/kunena.install.upgrade.xml +++ b/src/admin/install/kunena.install.upgrade.xml @@ -217,6 +217,25 @@ ALTER TABLE `#__kunena_users` DROP `karma_time`; + + + CREATE TABLE IF NOT EXISTS `#__kunena_mails_queue` +( + `id` int(11) NOT NULL auto_increment, + `subject` varchar(150) NOT NULL, + `message_id` int(11) NULL, + `sent_to` varchar(200) NOT NULL, + `message_url` varchar(150) NOT NULL, + `is_sent` int(11) NULL, + PRIMARY KEY (id), +) + ENGINE = InnoDB + DEFAULT CHARSET = utf8mb4 + DEFAULT COLLATE = utf8mb4_unicode_ci; + + diff --git a/src/admin/sql/install/mysql/create_tables.utf8.sql b/src/admin/sql/install/mysql/create_tables.utf8.sql index 0a5cb162718..c5e66e76992 100644 --- a/src/admin/sql/install/mysql/create_tables.utf8.sql +++ b/src/admin/sql/install/mysql/create_tables.utf8.sql @@ -214,6 +214,20 @@ CREATE TABLE IF NOT EXISTS `#__kunena_messages_text` ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 DEFAULT COLLATE = utf8mb4_unicode_ci; + +CREATE TABLE IF NOT EXISTS `#__kunena_mails_queue` +( + `id` int(11) NOT NULL auto_increment, + `subject` varchar(150) NOT NULL, + `message_id` int(11) NULL, + `sent_to` varchar(200) NOT NULL, + `message_url` varchar(150) NOT NULL, + `is_sent` int(11) NULL, + PRIMARY KEY (id), +) + ENGINE = InnoDB + DEFAULT CHARSET = utf8mb4 + DEFAULT COLLATE = utf8mb4_unicode_ci; CREATE TABLE IF NOT EXISTS `#__kunena_polls` ( diff --git a/src/libraries/kunena/src/Forum/Message/KunenaMessage.php b/src/libraries/kunena/src/Forum/Message/KunenaMessage.php index 6274fae0013..6a8599ca39c 100644 --- a/src/libraries/kunena/src/Forum/Message/KunenaMessage.php +++ b/src/libraries/kunena/src/Forum/Message/KunenaMessage.php @@ -439,6 +439,7 @@ public function newReply($fields = [], $useridfromparent = 0, $safefields = null public function sendNotification($url = null, $approved = false) { $config = KunenaFactory::getConfig(); + $db = Factory::getDbo(); if (!$config->sendEmails) { return false; @@ -548,10 +549,45 @@ public function sendNotification($url = null, $approved = false) KunenaEmail::send($mail, $receivers[0]); } + // Store the mails data for all subscribers in mail queue + $columns = array('subject', 'message_id', 'sent_to', 'message_url'); + + $values = array($subject, $this->id, $receivers[1], $url); + + $query = $db->getQuery(true) + ->insert($db->quoteName('#__mails_queue')) + ->columns($db->quoteName($columns)) + ->values(implode(',', $values)); + + $db->setQuery($query); + + try { + $db->execute(); + } catch (ExecutionFailureException $e) { + KunenaError::displayDatabaseError($e); + } + + // Store the mails data for all moderators in mail queue + $columns = array('subject', 'message_id', 'sent_to', 'message_url'); + + $values = array($subject, $this->id, $receivers[0], $url); + + $query = $db->getQuery(true) + ->insert($db->quoteName('#__mails_queue')) + ->columns($db->quoteName($columns)) + ->values(implode(',', $values)); + + $db->setQuery($query); + + try { + $db->execute(); + } catch (ExecutionFailureException $e) { + KunenaError::displayDatabaseError($e); + } + // Update subscriptions. if ($once && $sentusers) { $sentusers = implode(',', $sentusers); - $db = Factory::getDbo(); $query = $db->getQuery(true) ->update('#__kunena_user_topics') ->set('subscribed=2')