0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

Add migration to modify badly formatted tags

refs #5685, #5709

- cycle through all tags, removing leading commas and trim spaces
- if the string is empty, change to 'tag' - the slug base for this model
- if there is a change, save it
This commit is contained in:
Hannah Wolfe 2015-08-25 18:42:45 +01:00
parent 114696f7e2
commit 95e6b0a59d

View file

@ -239,6 +239,32 @@ to004 = function to004() {
return Promise.resolve();
});
ops.push(upgradeOp);
// add ghost-frontend client if missing
upgradeOp = models.Tag.findAll(options).then(function (tags) {
var tagOps = [];
if (tags) {
tags.each(function (tag) {
var name = tag.get('name'),
updated = name.replace(/^(,+)/, '').trim();
// If we've ended up with an empty string, default to just 'tag'
updated = updated === '' ? 'tag' : updated;
if (name !== updated) {
tagOps.push(tag.save({name: updated}, options));
}
});
if (tagOps.length > 0) {
logInfo('Cleaning ' + tagOps.length + ' malformed tags');
return Promise.all(tagOps);
}
}
return Promise.resolve();
});
ops.push(upgradeOp);
return Promise.all(ops);
};