Fixed unsubscription bug #49
This commit is contained in:
parent
f1ffb5dbbd
commit
9a5d723663
4 changed files with 51 additions and 7 deletions
|
@ -703,7 +703,8 @@ module.exports.changeStatus = (id, listId, campaignId, status, callback) => {
|
|||
});
|
||||
}
|
||||
|
||||
if (!campaignId) {
|
||||
// status change is not related to a campaign or it marks message as bounced etc.
|
||||
if (!campaignId || status > 2) {
|
||||
return connection.commit(err => {
|
||||
if (err) {
|
||||
return connection.rollback(() => {
|
||||
|
@ -716,13 +717,18 @@ module.exports.changeStatus = (id, listId, campaignId, status, callback) => {
|
|||
});
|
||||
}
|
||||
|
||||
connection.query('UPDATE `campaigns` SET `unsubscribed`=`unsubscribed`+1 WHERE `cid`=? LIMIT 1', [campaignId], err => {
|
||||
connection.query('SELECT `id` FROM `campaigns` WHERE `cid`=? LIMIT 1', [campaignId], (err, rows) => {
|
||||
if (err) {
|
||||
return connection.rollback(() => {
|
||||
connection.release();
|
||||
return callback(err);
|
||||
});
|
||||
}
|
||||
|
||||
let campaign = rows && rows[0] || false;
|
||||
|
||||
if (!campaign) {
|
||||
// should not happend
|
||||
return connection.commit(err => {
|
||||
if (err) {
|
||||
return connection.rollback(() => {
|
||||
|
@ -733,6 +739,41 @@ module.exports.changeStatus = (id, listId, campaignId, status, callback) => {
|
|||
connection.release();
|
||||
return callback(null, true);
|
||||
});
|
||||
}
|
||||
|
||||
// we should see only unsubscribe events here but you never know
|
||||
connection.query('UPDATE `campaigns` SET `unsubscribed`=`unsubscribed`' + (status === 2 ? '+' : '-') + '1 WHERE `cid`=? LIMIT 1', [campaignId], err => {
|
||||
if (err) {
|
||||
return connection.rollback(() => {
|
||||
connection.release();
|
||||
return callback(err);
|
||||
});
|
||||
}
|
||||
|
||||
let query = 'UPDATE `campaign__' + campaign.id + '` SET `status`=? WHERE `list`=? AND `subscription`=? LIMIT 1';
|
||||
let values = [status, listId, id];
|
||||
|
||||
// Updated tracker status
|
||||
connection.query(query, values, err => {
|
||||
if (err) {
|
||||
return connection.rollback(() => {
|
||||
connection.release();
|
||||
return callback(err);
|
||||
});
|
||||
}
|
||||
|
||||
return connection.commit(err => {
|
||||
if (err) {
|
||||
return connection.rollback(() => {
|
||||
connection.release();
|
||||
return callback(err);
|
||||
});
|
||||
}
|
||||
connection.release();
|
||||
return callback(null, true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -305,6 +305,7 @@ router.post('/:lcid/manage', passport.parseForm, passport.csrfProtection, (req,
|
|||
subscriptions.update(list.id, req.body.cid, req.body, false, err => {
|
||||
if (err) {
|
||||
req.flash('danger', err.message || err);
|
||||
log.error('Subscription', err);
|
||||
return res.redirect('/subscription/' + encodeURIComponent(req.params.lcid) + '/manage/' + encodeURIComponent(req.body.cid) + '?' + tools.queryParams(req.body));
|
||||
}
|
||||
res.redirect('/subscription/' + req.params.lcid + '/updated-notice');
|
||||
|
@ -324,7 +325,7 @@ router.get('/:lcid/unsubscribe/:ucid', passport.csrfProtection, (req, res, next)
|
|||
}
|
||||
|
||||
subscriptions.get(list.id, req.params.ucid, (err, subscription) => {
|
||||
if (!err && !list) {
|
||||
if (!err && !subscription) {
|
||||
err = new Error('Subscription not found from this list');
|
||||
err.status = 404;
|
||||
}
|
||||
|
@ -360,6 +361,7 @@ router.post('/:lcid/unsubscribe', passport.parseForm, passport.csrfProtection, (
|
|||
subscriptions.unsubscribe(list.id, email, req.body.campaign, (err, subscription) => {
|
||||
if (err) {
|
||||
req.flash('danger', err.message || err);
|
||||
log.error('Subscription', err);
|
||||
return res.redirect('/subscription/' + encodeURIComponent(req.params.lcid) + '/unsubscribe/' + encodeURIComponent(req.body.cid) + '?' + tools.queryParams(req.body));
|
||||
}
|
||||
res.redirect('/subscription/' + req.params.lcid + '/unsubscribe-notice');
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
<div class="panel panel-info">
|
||||
<!-- Default panel contents -->
|
||||
<div class="panel-heading">Subscribers who received the message:</div>
|
||||
<div class="panel-heading">Subscribers who received the message and did not bounce/unsubscribe:</div>
|
||||
<div class="panel-body">
|
||||
<div class="table-responsive">
|
||||
<table data-topic-url="/campaigns/status" data-topic-id="{{id}}/1" data-sort-column="1" data-sort-order="asc" class="table table-bordered table-hover data-table-ajax display nowrap" width="100%" data-row-sort="0,1,1,1,0,1,0">
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
<input type="hidden" name="_csrf" value="{{csrfToken}}">
|
||||
<input type="hidden" name="campaign" value="{{campaign}}">
|
||||
<input type="hidden" name="cid" value="{{cid}}">
|
||||
|
||||
<div class="form-group">
|
||||
<label for="email">Email address</label>
|
||||
|
|
Loading…
Reference in a new issue