mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-03 15:53:16 +03:00
🐛 Fixed "undefined" values in member csv export
no issue We missed handling `undefined` values for fields during csv export for memebrs, which causes csv entries as `undefined` for fields that don't exist. It also added need for extra handling of `undefined` entries during csv import. This PR fixes the bug by properly handling empty/undefined values in export
This commit is contained in:
parent
2c52282662
commit
4eeed0d32a
@ -18,8 +18,11 @@ const decorateWithSubscriptions = async function (member) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// NOTE: this method should not exist at all and needs to be cleaned up
|
/** NOTE: this method should not exist at all and needs to be cleaned up
|
||||||
// it was created due to a bug in how CSV is currently created for exports
|
it was created due to a bug in how CSV is currently created for exports
|
||||||
|
Export bug was fixed in 3.6 but method exists to handle older csv exports with undefined
|
||||||
|
**/
|
||||||
|
|
||||||
const cleanupUndefined = (obj) => {
|
const cleanupUndefined = (obj) => {
|
||||||
for (let key in obj) {
|
for (let key in obj) {
|
||||||
if (obj[key] === 'undefined') {
|
if (obj[key] === 'undefined') {
|
||||||
@ -31,7 +34,7 @@ const cleanupUndefined = (obj) => {
|
|||||||
// NOTE: this method can be removed once unique constraints are introduced ref.: https://github.com/TryGhost/Ghost/blob/e277c6b/core/server/data/schema/schema.js#L339
|
// NOTE: this method can be removed once unique constraints are introduced ref.: https://github.com/TryGhost/Ghost/blob/e277c6b/core/server/data/schema/schema.js#L339
|
||||||
const sanitizeInput = (members) => {
|
const sanitizeInput = (members) => {
|
||||||
const customersMap = members.reduce((acc, member) => {
|
const customersMap = members.reduce((acc, member) => {
|
||||||
if (member.stripe_customer_id) {
|
if (member.stripe_customer_id && member.stripe_customer_id !== 'undefined') {
|
||||||
if (acc[member.stripe_customer_id]) {
|
if (acc[member.stripe_customer_id]) {
|
||||||
acc[member.stripe_customer_id] += 1;
|
acc[member.stripe_customer_id] += 1;
|
||||||
} else {
|
} else {
|
||||||
|
@ -10,7 +10,7 @@ module.exports = function formatCSV(data, fields) {
|
|||||||
|
|
||||||
for (i = 0; i < fields.length; i = i + 1) {
|
for (i = 0; i < fields.length; i = i + 1) {
|
||||||
field = fields[i];
|
field = fields[i];
|
||||||
csv += entry[field] !== null ? entry[field] : '';
|
csv += (entry[field] !== null && entry[field] !== undefined) ? entry[field] : '';
|
||||||
if (i !== fields.length - 1) {
|
if (i !== fields.length - 1) {
|
||||||
csv += ',';
|
csv += ',';
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user