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,27 +728,19 @@ module.exports.delete = (id, callback) => {
|
|||
}
|
||||
|
||||
connection.query('DELETE FROM campaigns WHERE id=? LIMIT 1', [id], (err, result) => {
|
||||
connection.release();
|
||||
if (err) {
|
||||
connection.release();
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
let affected = result && result.affectedRows || 0;
|
||||
|
||||
connection.query('DELETE FROM links WHERE campaign=?', [id], err => {
|
||||
connection.release();
|
||||
removeCampaignTables(id, err => {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
removeCampaignTables(id, err => {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
caches.cache.delete('sender queue');
|
||||
return callback(null, affected);
|
||||
});
|
||||
caches.cache.delete('sender queue');
|
||||
return callback(null, affected);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -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,31 +13,23 @@ let log = require('npmlog');
|
|||
let urllib = require('url');
|
||||
let he = require('he');
|
||||
|
||||
module.exports.resolve = (campaignCid, linkCid, callback) => {
|
||||
campaigns.getByCid(campaignCid, (err, campaign) => {
|
||||
module.exports.resolve = (linkCid, callback) => {
|
||||
db.getConnection((err, connection) => {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
if (!campaign) {
|
||||
return callback(null, false);
|
||||
}
|
||||
db.getConnection((err, connection) => {
|
||||
let query = 'SELECT id, url FROM links WHERE `cid`=? LIMIT 1';
|
||||
connection.query(query, [linkCid], (err, rows) => {
|
||||
connection.release();
|
||||
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) => {
|
||||
connection.release();
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (rows && rows.length) {
|
||||
return callback(null, rows[0].id, rows[0].url);
|
||||
}
|
||||
if (rows && rows.length) {
|
||||
return callback(null, rows[0].id, rows[0].url);
|
||||
}
|
||||
|
||||
return callback(null, false);
|
||||
});
|
||||
return callback(null, false);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
@ -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,23 +30,27 @@ 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) => {
|
||||
router.get('/:campaign/:list/:subscription/:link', (req, res) => {
|
||||
|
||||
let notFound = () => {
|
||||
res.status(404);
|
||||
return res.render('archive/view', {
|
||||
layout: 'archive/layout',
|
||||
message: 'Oops, we couldn\'t find a link for the URL you clicked',
|
||||
campaign: {
|
||||
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);
|
||||
res.status(404);
|
||||
return res.render('archive/view', {
|
||||
layout: 'archive/layout',
|
||||
message: 'Oops, we couldn\'t find a link for the URL you clicked',
|
||||
campaign: {
|
||||
subject: 'Error 404'
|
||||
}
|
||||
});
|
||||
|
||||
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