Skip to content

Commit

Permalink
[K6.2] Store notifications mail in database to be sent by CRON #9555
Browse files Browse the repository at this point in the history
  • Loading branch information
xillibit committed Aug 27, 2023
1 parent 38f3d08 commit e6968b3
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/admin/install/kunena.install.upgrade.xml
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,25 @@
</query>
<query mode="silenterror">ALTER TABLE `#__kunena_users` DROP `karma_time`;</query>
</version>
<version version="6.2.0-DEV"
versiondate="2023-08-27"
versionname="Internal">
<query mode="silenterror">
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;
</query>
</version>
<version version="@kunenaversion@"
versiondate="@kunenaversiondate@"
versionname="@kunenaversionname@">
Expand Down
14 changes: 14 additions & 0 deletions src/admin/sql/install/mysql/create_tables.utf8.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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`
(
Expand Down
38 changes: 37 additions & 1 deletion src/libraries/kunena/src/Forum/Message/KunenaMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit e6968b3

Please sign in to comment.