Do not delete url pointers from database when resetting campaign
This commit is contained in:
parent
f7617ec06e
commit
06aea61827
4 changed files with 41 additions and 52 deletions
|
@ -728,19 +728,12 @@ module.exports.delete = (id, callback) => {
|
|||
}
|
||||
|
||||
connection.query('DELETE FROM campaigns WHERE id=? LIMIT 1', [id], (err, result) => {
|
||||
if (err) {
|
||||
connection.release();
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
let affected = result && result.affectedRows || 0;
|
||||
|
||||
connection.query('DELETE FROM links WHERE campaign=?', [id], err => {
|
||||
connection.release();
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
removeCampaignTables(id, err => {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
|
@ -751,7 +744,6 @@ module.exports.delete = (id, callback) => {
|
|||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.send = (id, scheduled, callback) => {
|
||||
|
@ -841,7 +833,7 @@ module.exports.reset = (id, callback) => {
|
|||
}
|
||||
|
||||
caches.cache.delete('sender queue');
|
||||
connection.query('DELETE FROM links WHERE campaign=?', [id], err => {
|
||||
connection.query('UPDATE links SET `clicks`=0 WHERE campaign=?', [id], err => {
|
||||
if (err) {
|
||||
connection.release();
|
||||
return callback(err);
|
||||
|
|
|
@ -13,20 +13,13 @@ let log = require('npmlog');
|
|||
let urllib = require('url');
|
||||
let he = require('he');
|
||||
|
||||
module.exports.resolve = (campaignCid, linkCid, callback) => {
|
||||
campaigns.getByCid(campaignCid, (err, campaign) => {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
if (!campaign) {
|
||||
return callback(null, false);
|
||||
}
|
||||
module.exports.resolve = (linkCid, callback) => {
|
||||
db.getConnection((err, connection) => {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
let query = 'SELECT id, url FROM links WHERE `campaign`=? AND `cid`=? LIMIT 1';
|
||||
connection.query(query, [campaign.id, linkCid], (err, rows) => {
|
||||
let query = 'SELECT id, url FROM links WHERE `cid`=? LIMIT 1';
|
||||
connection.query(query, [linkCid], (err, rows) => {
|
||||
connection.release();
|
||||
if (err) {
|
||||
return callback(err);
|
||||
|
@ -39,7 +32,6 @@ module.exports.resolve = (campaignCid, linkCid, callback) => {
|
|||
return callback(null, false);
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.countClick = (remoteIp, campaignCid, listCid, subscriptionCid, linkId, callback) => {
|
||||
|
@ -47,6 +39,9 @@ module.exports.countClick = (remoteIp, campaignCid, listCid, subscriptionCid, li
|
|||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
if(!data){
|
||||
return callback(null, false);
|
||||
}
|
||||
db.getConnection((err, connection) => {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
|
|
10
package.json
10
package.json
|
@ -33,12 +33,12 @@
|
|||
"body-parser": "^1.15.1",
|
||||
"bounce-handler": "^7.3.2-fork.0",
|
||||
"compression": "^1.6.2",
|
||||
"config": "^1.20.4",
|
||||
"config": "^1.21.0",
|
||||
"connect-flash": "^0.1.1",
|
||||
"connect-redis": "^3.0.2",
|
||||
"cookie-parser": "^1.4.3",
|
||||
"csurf": "^1.9.0",
|
||||
"csv-parse": "^1.1.0",
|
||||
"csv-parse": "^1.1.1",
|
||||
"escape-html": "^1.0.3",
|
||||
"express": "^4.13.4",
|
||||
"express-session": "^1.13.0",
|
||||
|
@ -57,11 +57,11 @@
|
|||
"moment-timezone": "^0.5.4",
|
||||
"morgan": "^1.7.0",
|
||||
"multer": "^1.1.0",
|
||||
"mysql": "^2.10.2",
|
||||
"mysql": "^2.11.1",
|
||||
"nodemailer": "^2.4.2",
|
||||
"nodemailer-openpgp": "^1.0.2",
|
||||
"npmlog": "^2.0.4",
|
||||
"openpgp": "^2.3.0",
|
||||
"npmlog": "^3.0.0",
|
||||
"openpgp": "^2.3.2",
|
||||
"passport": "^0.3.2",
|
||||
"passport-local": "^1.0.0",
|
||||
"request": "^2.72.0",
|
||||
|
|
|
@ -30,14 +30,9 @@ router.get('/:campaign/:list/:subscription', (req, res) => {
|
|||
res.end(trackImg);
|
||||
});
|
||||
|
||||
router.get('/:campaign/:list/:subscription/:link', (req, res, next) => {
|
||||
links.resolve(req.params.campaign, req.params.link, (err, linkId, url) => {
|
||||
if (err) {
|
||||
req.flash('danger', err.message || err);
|
||||
return res.redirect('/');
|
||||
}
|
||||
if (!linkId || !url) {
|
||||
log.error('Redirect', 'Unresolved URL: <%s>', req.url);
|
||||
router.get('/:campaign/:list/:subscription/:link', (req, res) => {
|
||||
|
||||
let notFound = () => {
|
||||
res.status(404);
|
||||
return res.render('archive/view', {
|
||||
layout: 'archive/layout',
|
||||
|
@ -46,7 +41,16 @@ router.get('/:campaign/:list/:subscription/:link', (req, res, next) => {
|
|||
subject: 'Error 404'
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
links.resolve(req.params.link, (err, linkId, url) => {
|
||||
if (err) {
|
||||
req.flash('danger', err.message || err);
|
||||
return res.redirect('/');
|
||||
}
|
||||
if (!linkId || !url) {
|
||||
log.error('Redirect', 'Unresolved URL: <%s>', req.url);
|
||||
return notFound();
|
||||
}
|
||||
links.countClick(req.ip, req.params.campaign, req.params.list, req.params.subscription, linkId, (err, status) => {
|
||||
if (err) {
|
||||
|
@ -70,9 +74,8 @@ router.get('/:campaign/:list/:subscription/:link', (req, res, next) => {
|
|||
}
|
||||
|
||||
if (!list) {
|
||||
err = new Error('Not Found');
|
||||
err.status = 404;
|
||||
return next(err);
|
||||
log.error('Redirect', 'Could not resolve list for merge tags: <%s>', req.url);
|
||||
return notFound();
|
||||
}
|
||||
|
||||
settings.get('serviceUrl', (err, serviceUrl) => {
|
||||
|
@ -88,9 +91,8 @@ router.get('/:campaign/:list/:subscription/:link', (req, res, next) => {
|
|||
}
|
||||
|
||||
if (!subscription) {
|
||||
err = new Error('Not Found');
|
||||
err.status = 404;
|
||||
return next(err);
|
||||
log.error('Redirect', 'Could not resolve subscription for merge tags: <%s>', req.url);
|
||||
return notFound();
|
||||
}
|
||||
|
||||
url = tools.formatMessage(serviceUrl, {
|
||||
|
|
Loading…
Reference in a new issue