From 2486f7b9d83690ab8ee8938f9fae7e041ec296d0 Mon Sep 17 00:00:00 2001 From: Andris Reinman Date: Wed, 4 May 2016 11:27:46 +0300 Subject: [PATCH] updated transactional messages --- services/feedcheck.js | 61 +++++++--- setup/sql/mailtrain.sql | 4 +- setup/sql/upgrade-00008.sql | 1 + views/emails/confirm-html.hbs | 15 +-- views/emails/password-reset-html.hbs | 108 ++++++++++++++++-- views/emails/subscription-confirmed-html.hbs | 97 +++++++++++++++- views/emails/unsubscribe-confirmed-html.hbs | 113 +++++++++++++++++-- 7 files changed, 353 insertions(+), 46 deletions(-) diff --git a/services/feedcheck.js b/services/feedcheck.js index dff8e9a3..6cd96298 100644 --- a/services/feedcheck.js +++ b/services/feedcheck.js @@ -18,49 +18,80 @@ function feedLoop() { let query = 'SELECT `id`, `source_url`, `from`, `address`, `subject`, `list`, `segment` FROM `campaigns` WHERE `type`=2 AND `status`=6 AND (`last_check` IS NULL OR `last_check`< NOW() - INTERVAL 10 MINUTE) LIMIT 1'; connection.query(query, (err, rows) => { + connection.release(); if (err) { - connection.release(); log.error('Feed', err); return setTimeout(feedLoop, 15 * 1000); } if (!rows || !rows.length) { - connection.release(); return setTimeout(feedLoop, 15 * 1000); } let parent = tools.convertKeys(rows[0]); - let query = 'UPDATE `campaigns` SET `last_check`=NOW() WHERE id=? LIMIT 1'; - connection.query(query, [parent.id], err => { - connection.release(); - if (err) { - log.error('Feed', err); - return setTimeout(feedLoop, 15 * 1000); - } - + updateRssInfo(parent.id, true, false, () => { log.verbose('Feed', 'Checking feed %s (%s)', parent.sourceUrl, parent.id); feed.fetch(parent.sourceUrl, (err, entries) => { if (err) { log.error('Feed', err); - return setTimeout(feedLoop, 1 * 1000); + return updateRssInfo(parent.id, false, 'Feed error: ' + err.message, () => { + setTimeout(feedLoop, 1 * 1000); + }); } checkEntries(parent, entries, (err, result) => { + let message; if (err) { log.error('Feed', err); - } - if (result) { + message = 'Feed error: ' + err.message; + } else if (result) { log.verbose('Feed', 'Added %s new campaigns for %s', result, parent.id); + message = 'Found ' + result + ' new campaing messages from feed'; + } else { + message = 'Found nothing new from the feed'; } - return setTimeout(feedLoop, 1 * 1000); + return updateRssInfo(parent.id, false, message, () => { + setTimeout(feedLoop, 1 * 1000); + }); }); - }); }); }); }); } +function updateRssInfo(id, updateCheck, status, callback) { + db.getConnection((err, connection) => { + if (err) { + log.error('Feed', err.stack); + return callback(err); + } + let query; + let values; + if (updateCheck) { + if (status) { + query = 'UPDATE `campaigns` SET `last_check`=NOW(), `check_status`=? WHERE id=? LIMIT 1'; + values = [status, id]; + } else { + query = 'UPDATE `campaigns` SET `last_check`=NOW() WHERE id=? LIMIT 1'; + values = [id]; + } + } else { + query = 'UPDATE `campaigns` SET `check_status`=? WHERE id=? LIMIT 1'; + values = [status, id]; + } + + connection.query(query, values, (err, result) => { + connection.release(); + if (err) { + log.error('Feed', err); + return callback(err); + } + return callback(null, result.affectedRows); + }); + }); +} + function checkEntries(parent, entries, callback) { let pos = 0; let added = 0; diff --git a/setup/sql/mailtrain.sql b/setup/sql/mailtrain.sql index 814ea075..39922c3d 100644 --- a/setup/sql/mailtrain.sql +++ b/setup/sql/mailtrain.sql @@ -37,10 +37,12 @@ CREATE TABLE `campaigns` ( `template` int(11) unsigned NOT NULL, `source_url` varchar(255) CHARACTER SET ascii DEFAULT NULL, `last_check` timestamp NULL DEFAULT NULL, + `check_status` varchar(255) DEFAULT NULL, `from` varchar(255) DEFAULT '', `address` varchar(255) DEFAULT '', `subject` varchar(255) DEFAULT '', `html` text, + `html_prepared` text, `text` text, `status` tinyint(4) unsigned NOT NULL DEFAULT '1', `scheduled` timestamp NULL DEFAULT NULL, @@ -170,7 +172,7 @@ CREATE TABLE `segments` ( `created` timestamp NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `list` (`list`), - KEY `name` (`name`), + KEY `name` (`name`(191)), CONSTRAINT `segments_ibfk_1` FOREIGN KEY (`list`) REFERENCES `lists` (`id`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; CREATE TABLE `settings` ( diff --git a/setup/sql/upgrade-00008.sql b/setup/sql/upgrade-00008.sql index 78c30bcf..0f9a827e 100644 --- a/setup/sql/upgrade-00008.sql +++ b/setup/sql/upgrade-00008.sql @@ -18,6 +18,7 @@ CREATE TABLE `rss` ( ALTER TABLE `campaigns` ADD COLUMN `parent` int(11) unsigned DEFAULT NULL AFTER `type`; CREATE INDEX parent_index ON `campaigns` (`parent`); ALTER TABLE `campaigns` ADD COLUMN `last_check` timestamp NULL DEFAULT NULL AFTER `source_url`; +ALTER TABLE `campaigns` ADD COLUMN `check_status` varchar(255) NULL DEFAULT NULL AFTER `last_check`; CREATE INDEX check_index ON `campaigns` (`last_check`); ALTER TABLE `campaigns` ADD COLUMN `html_prepared` text AFTER `html`; diff --git a/views/emails/confirm-html.hbs b/views/emails/confirm-html.hbs index 29df5045..92b3dcbd 100644 --- a/views/emails/confirm-html.hbs +++ b/views/emails/confirm-html.hbs @@ -98,22 +98,19 @@ body { -
+

{{title}}

+

Please Confirm Subscription

-

{{title}}

-

Please Confirm Subscription

+

Yes, subscribe me to this list

-

Yes, subscribe me to this list

+

If you received this email by mistake, simply delete it. You won't be subscribed if you don't click the confirmation link above.

-

If you received this email by mistake, simply delete it. You won't be subscribed if you don't click the confirmation link above.

+

For questions about this list, please contact: +
{{contactAddress}}

-

For questions about this list, please contact: -
{{contactAddress}}

- -
diff --git a/views/emails/password-reset-html.hbs b/views/emails/password-reset-html.hbs index adcded21..5fe8dd2f 100644 --- a/views/emails/password-reset-html.hbs +++ b/views/emails/password-reset-html.hbs @@ -4,20 +4,110 @@ Change your password + + + + - +
-

Change your password

+

Change your password

-
+

We have received a password change request for your Mailtrain account {{username}}.

-

We have received a password change request for your Mailtrain account ({{username}}).

- -

- -

If you did not ask to change your password, then you can ignore this email and your password will not be changed.

+

Reset password

+

If you did not ask to change your password, then you can ignore this email and your password will not be changed.

+
- diff --git a/views/emails/subscription-confirmed-html.hbs b/views/emails/subscription-confirmed-html.hbs index e24f9166..241c42cf 100644 --- a/views/emails/subscription-confirmed-html.hbs +++ b/views/emails/subscription-confirmed-html.hbs @@ -4,13 +4,106 @@ {{title}}: Subscription Confirmed - + + + + +

{{title}}

-

Your subscription to our list has been confirmed.

+

Your subscription to our list has been confirmed.

If you want to modify your subscription then you can: diff --git a/views/emails/unsubscribe-confirmed-html.hbs b/views/emails/unsubscribe-confirmed-html.hbs index cba3118d..69c4fbef 100644 --- a/views/emails/unsubscribe-confirmed-html.hbs +++ b/views/emails/unsubscribe-confirmed-html.hbs @@ -4,23 +4,116 @@ {{title}}: You are now unsubscribed + + + + - +

-

{{title}}

+

{{title}}

-

We have removed your email address from our list.

+

We have removed your email address from our list.

-

- If you unsubscribed by mistake, you can re-subscribe at: -

+

+ If you unsubscribed by mistake, you can re-subscribe at: +

-

- -

For questions about this list, please contact: -
{{contactAddress}}

+

Subscribe

+

For questions about this list, please contact: +
{{contactAddress}}

+