mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Fix importer adds the same tags to every post
fixes #2234 - updateTags used tags that were overwritten by an async operation
This commit is contained in:
parent
819d82ac9e
commit
b1c35a9b6c
1 changed files with 6 additions and 6 deletions
|
@ -11,8 +11,7 @@ var _ = require('lodash'),
|
||||||
ghostBookshelf = require('./base'),
|
ghostBookshelf = require('./base'),
|
||||||
|
|
||||||
Post,
|
Post,
|
||||||
Posts,
|
Posts;
|
||||||
myTags;
|
|
||||||
|
|
||||||
Post = ghostBookshelf.Model.extend({
|
Post = ghostBookshelf.Model.extend({
|
||||||
|
|
||||||
|
@ -50,7 +49,7 @@ Post = ghostBookshelf.Model.extend({
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
// keep tags for 'saved' event
|
// keep tags for 'saved' event
|
||||||
myTags = this.get('tags');
|
this.myTags = this.get('tags');
|
||||||
|
|
||||||
ghostBookshelf.Model.prototype.saving.call(this);
|
ghostBookshelf.Model.prototype.saving.call(this);
|
||||||
|
|
||||||
|
@ -92,9 +91,10 @@ Post = ghostBookshelf.Model.extend({
|
||||||
|
|
||||||
updateTags: function (newPost, attr, options) {
|
updateTags: function (newPost, attr, options) {
|
||||||
/*jslint unparam:true*/
|
/*jslint unparam:true*/
|
||||||
|
var self = this;
|
||||||
options = options || {};
|
options = options || {};
|
||||||
|
|
||||||
if (!myTags) {
|
if (!this.myTags) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ Post = ghostBookshelf.Model.extend({
|
||||||
|
|
||||||
// First find any tags which have been removed
|
// First find any tags which have been removed
|
||||||
_.each(existingTags, function (existingTag) {
|
_.each(existingTags, function (existingTag) {
|
||||||
if (!_.some(myTags, function (newTag) { return newTag.name === existingTag.name; })) {
|
if (!_.some(self.myTags, function (newTag) { return newTag.name === existingTag.name; })) {
|
||||||
tagsToDetach.push(existingTag.id);
|
tagsToDetach.push(existingTag.id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -118,7 +118,7 @@ Post = ghostBookshelf.Model.extend({
|
||||||
}
|
}
|
||||||
|
|
||||||
// Next check if new tags are all exactly the same as what is set on the model
|
// Next check if new tags are all exactly the same as what is set on the model
|
||||||
_.each(myTags, function (newTag) {
|
_.each(self.myTags, function (newTag) {
|
||||||
if (!_.some(existingTags, function (existingTag) { return newTag.name === existingTag.name; })) {
|
if (!_.some(existingTags, function (existingTag) { return newTag.name === existingTag.name; })) {
|
||||||
// newTag isn't on this post yet
|
// newTag isn't on this post yet
|
||||||
tagsToAttach.push(newTag);
|
tagsToAttach.push(newTag);
|
||||||
|
|
Loading…
Add table
Reference in a new issue