u
This commit is contained in:
parent
33f7d7ac8a
commit
bc34ed2e39
8 changed files with 43 additions and 17 deletions
|
@ -8,7 +8,7 @@ let segments = require('./segments');
|
|||
let subscriptions = require('./subscriptions');
|
||||
let shortid = require('shortid');
|
||||
|
||||
let allowedKeys = ['description', 'from', 'address', 'subject', 'template', 'template_url', 'list', 'segment', 'html', 'text'];
|
||||
let allowedKeys = ['description', 'from', 'address', 'subject', 'template', 'source_url', 'list', 'segment', 'html', 'text'];
|
||||
|
||||
module.exports.list = (start, limit, callback) => {
|
||||
db.getConnection((err, connection) => {
|
||||
|
@ -107,7 +107,11 @@ module.exports.filter = (request, callback) => {
|
|||
});
|
||||
};
|
||||
|
||||
processQuery(false);
|
||||
processQuery({
|
||||
// only find normal campaigns at this point
|
||||
where: '`type`=?',
|
||||
values: [1]
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.getByCid = (cid, callback) => {
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
{
|
||||
"schemaVersion": 6
|
||||
"schemaVersion": 7
|
||||
}
|
||||
|
|
|
@ -84,20 +84,20 @@ router.get('/:campaign/:list/:subscription', (req, res, next) => {
|
|||
});
|
||||
};
|
||||
|
||||
if (campaign.templateUrl) {
|
||||
if (campaign.sourceUrl) {
|
||||
let form = tools.getMessageLinks(serviceUrl, campaign, list, subscription);
|
||||
Object.keys(subscription.mergeTags).forEach(key => {
|
||||
form[key] = subscription.mergeTags[key];
|
||||
});
|
||||
request.post({
|
||||
url: campaign.templateUrl,
|
||||
url: campaign.sourceUrl,
|
||||
form
|
||||
}, (err, httpResponse, body) => {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
if (httpResponse.statusCode !== 200) {
|
||||
return next(new Error('Received status code ' + httpResponse.statusCode + ' from ' + campaign.templateUrl));
|
||||
return next(new Error('Received status code ' + httpResponse.statusCode + ' from ' + campaign.sourceUrl));
|
||||
}
|
||||
renderAndShow(body && body.toString(), false);
|
||||
});
|
||||
|
|
|
@ -22,8 +22,9 @@ function findUnsent(callback) {
|
|||
return callback(err);
|
||||
}
|
||||
|
||||
let query = 'SELECT `id`, `list`, `segment` FROM `campaigns` WHERE `status`=? AND (`scheduled` IS NULL OR `scheduled` <= NOW()) LIMIT 1';
|
||||
connection.query(query, [2], (err, rows) => {
|
||||
// Find "normal" campaigns. Ignore RSS and drip campaigns at this point
|
||||
let query = 'SELECT `id`, `list`, `segment` FROM `campaigns` WHERE `status`=? AND (`scheduled` IS NULL OR `scheduled` <= NOW()) AND `type`=? LIMIT 1';
|
||||
connection.query(query, [2, 1], (err, rows) => {
|
||||
if (err) {
|
||||
connection.release();
|
||||
return callback(err);
|
||||
|
@ -232,20 +233,20 @@ function formatMessage(message, callback) {
|
|||
});
|
||||
};
|
||||
|
||||
if (campaign.templateUrl) {
|
||||
if (campaign.sourceUrl) {
|
||||
let form = tools.getMessageLinks(configItems.serviceUrl, campaign, list, message.subscription);
|
||||
Object.keys(message.subscription.mergeTags).forEach(key => {
|
||||
form[key] = message.subscription.mergeTags[key];
|
||||
});
|
||||
request.post({
|
||||
url: campaign.templateUrl,
|
||||
url: campaign.sourceUrl,
|
||||
form
|
||||
}, (err, httpResponse, body) => {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
if (httpResponse.statusCode !== 200) {
|
||||
return callback(new Error('Received status code ' + httpResponse.statusCode + ' from ' + campaign.templateUrl));
|
||||
return callback(new Error('Received status code ' + httpResponse.statusCode + ' from ' + campaign.sourceUrl));
|
||||
}
|
||||
renderAndSend(body && body.toString(), '', false);
|
||||
});
|
||||
|
|
|
@ -1,12 +1,19 @@
|
|||
'use strict';
|
||||
|
||||
// This script re-calculates timezone offsets once a day
|
||||
// This script re-calculates timezone offsets once a day.
|
||||
// We need this to be able to send messages using subscriber's local time
|
||||
// The best option would be to use built-in timezone data of MySQL but
|
||||
// the availability of timezone data is not guaranteed as it's an optional add on.
|
||||
// So instead we keep a list of timezone offsets in a table that we can use to
|
||||
// JOIN with subscription table. Subscription table includes timezone name for
|
||||
// a subscriber and tzoffset table includes offset from UTC in minutes
|
||||
|
||||
let moment = require('moment-timezone');
|
||||
let db = require('../lib/db');
|
||||
let lastCheck = false;
|
||||
let log = require('npmlog');
|
||||
|
||||
let lastCheck = false;
|
||||
|
||||
function updateTimezoneOffsets(callback) {
|
||||
log.verbose('UTC', 'Updating timezone offsets');
|
||||
db.getConnection((err, connection) => {
|
||||
|
|
14
setup/sql/upgrade-00007.sql
Normal file
14
setup/sql/upgrade-00007.sql
Normal file
|
@ -0,0 +1,14 @@
|
|||
# Header section
|
||||
# Define incrementing schema version number
|
||||
SET @schema_version = '7';
|
||||
|
||||
# Rename template_url to source_url in order to use this field for different kind of urls, eg. for RSS url
|
||||
ALTER TABLE `campaigns` CHANGE COLUMN `template_url` `source_url` varchar(255) CHARACTER SET ascii DEFAULT NULL;
|
||||
# Add new column type that defines what kind of campaign is it. A normal campaign, (1), RSS (2) or drip (3)
|
||||
ALTER TABLE `campaigns` ADD COLUMN `type` tinyint(4) unsigned NOT NULL DEFAULT '1' AFTER `cid`;
|
||||
CREATE INDEX type_index ON `campaigns` (`type`);
|
||||
|
||||
# Footer section
|
||||
LOCK TABLES `settings` WRITE;
|
||||
INSERT INTO `settings` (`key`, `value`) VALUES('db_schema_version', @schema_version) ON DUPLICATE KEY UPDATE `value`=@schema_version;
|
||||
UNLOCK TABLES;
|
|
@ -72,7 +72,7 @@
|
|||
Or alternatively use an URL as the message content source:
|
||||
</p>
|
||||
<div>
|
||||
<input type="url" class="form-control" name="template-url" id="template-url" value="{{templateUrl}}" placeholder="http://example.com/message-render.php">
|
||||
<input type="url" class="form-control" name="source-url" id="source-url" value="{{sourceUrl}}" placeholder="http://example.com/message-render.php">
|
||||
<span class="help-block">If a message is sent then this URL will be POSTed to using Merge Tags as POST body. Use this if you want to generate the HTML message yourself</span>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -106,11 +106,11 @@
|
|||
Template Settings
|
||||
</legend>
|
||||
|
||||
{{#if templateUrl}}
|
||||
{{#if sourceUrl}}
|
||||
<div class="form-group">
|
||||
<label for="template-url" class="col-sm-2 control-label">Template URL</label>
|
||||
<label for="source-url" class="col-sm-2 control-label">Template URL</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="url" class="form-control" name="template-url" id="template-url" value="{{templateUrl}}" placeholder="http://example.com/message-render.php">
|
||||
<input type="url" class="form-control" name="source-url" id="source-url" value="{{sourceUrl}}" placeholder="http://example.com/message-render.php">
|
||||
<span class="help-block">If a message is sent then this URL will be POSTed to using Merge Tags as POST body. Use this if you want to generate the HTML message yourself</span>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue