Skip to content

Commit

Permalink
v1.19.1
Browse files Browse the repository at this point in the history
  • Loading branch information
andris9 committed Sep 15, 2016
1 parent 0896e9f commit bd20e16
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 100 deletions.
99 changes: 0 additions & 99 deletions lib/models/subscriptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1116,102 +1116,3 @@ module.exports.listImports = (listId, callback) => {
});
});
};

module.exports.exportList = (listId, request, columns, segmentId, callback) => {
listId = Number(listId) || 0;
segmentId = Number(segmentId) || 0;

if (!listId) {
return callback(new Error('Missing List ID'));
}

let processQuery = queryData => {

db.getConnection((err, connection) => {
if (err) {
return callback(err);
}

let query = 'SELECT COUNT(id) AS total FROM `subscription__' + listId + '`';
let values = [];

if (queryData.where) {
query += ' WHERE ' + queryData.where;
values = values.concat(queryData.values || []);
}

connection.query(query, values, (err, total) => {
if (err) {
connection.release();
return callback(err);
}
total = total && total[0] && total[0].total || 0;

let ordering = [];

if (request.order && request.order.length) {

request.order.forEach(order => {
let orderField = columns[Number(order.column)];
let orderDirection = (order.dir || '').toString().toLowerCase() === 'desc' ? 'DESC' : 'ASC';
if (orderField) {
ordering.push('`' + orderField + '` ' + orderDirection);
}
});
}

if (!ordering.length) {
ordering.push('`email` ASC');
}

let args = [Number(request.length) || 50, Number(request.start) || 0];
let query;


let generator = csvGenerate({
columns: ,
length: 2
});

if (request.search && request.search.value) {
query = 'SELECT SQL_CALC_FOUND_ROWS * FROM `subscription__' + listId + '` WHERE email LIKE ? OR first_name LIKE ? OR last_name LIKE ? ' + (queryData.where ? ' AND (' + queryData.where + ')' : '') + ' ORDER BY ' + ordering.join(', ') + ' LIMIT ? OFFSET ?';

let searchVal = '%' + request.search.value.replace(/\\/g, '\\\\').replace(/([%_])/g, '\\$1') + '%';
args = [searchVal, searchVal, searchVal].concat(queryData.values || []).concat(args);
} else {
query = 'SELECT SQL_CALC_FOUND_ROWS * FROM `subscription__' + listId + '` WHERE 1 ' + (queryData.where ? ' AND (' + queryData.where + ')' : '') + ' ORDER BY ' + ordering.join(', ') + ' LIMIT ? OFFSET ?';
args = [].concat(queryData.values || []).concat(args);
}

connection.query(query, args, (err, rows) => {
if (err) {
connection.release();
return callback(err);
}
connection.query('SELECT FOUND_ROWS() AS total', (err, filteredTotal) => {
connection.release();
if (err) {
return callback(err);
}

let subscriptions = rows.map(row => tools.convertKeys(row));

filteredTotal = filteredTotal && filteredTotal[0] && filteredTotal[0].total || 0;
return callback(null, subscriptions, total, filteredTotal);
});
});
});
});
};

if (segmentId) {
segments.getQuery(segmentId, false, (err, queryData) => {
if (err) {
return callback(err);
}
processQuery(queryData);
});
} else {
processQuery(false);
}
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "mailtrain",
"private": true,
"version": "1.19.0",
"version": "1.19.1",
"description": "Self hosted email newsletter app",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit bd20e16

Please sign in to comment.