v1.19.1
This commit is contained in:
parent
0896e9f9cf
commit
bd20e16d73
2 changed files with 1 additions and 100 deletions
|
@ -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);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "mailtrain",
|
"name": "mailtrain",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "1.19.0",
|
"version": "1.19.1",
|
||||||
"description": "Self hosted email newsletter app",
|
"description": "Self hosted email newsletter app",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue