mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Ensure generateSlug gets transaction for tags
fixes #2460 - add transacting to tag saving - add same to users while we're here
This commit is contained in:
parent
3ee6987aa9
commit
438cbab68e
2 changed files with 14 additions and 8 deletions
|
@ -8,13 +8,17 @@ Tag = ghostBookshelf.Model.extend({
|
|||
|
||||
tableName: 'tags',
|
||||
|
||||
saving: function () {
|
||||
saving: function (newPage, attr, options) {
|
||||
/*jshint unused:false*/
|
||||
|
||||
var self = this;
|
||||
|
||||
ghostBookshelf.Model.prototype.saving.apply(this, arguments);
|
||||
|
||||
if (!this.get('slug')) {
|
||||
// Generating a slug requires a db call to look for conflicting slugs
|
||||
return ghostBookshelf.Model.generateSlug(Tag, this.get('name'))
|
||||
if (this.hasChanged('slug') || !this.get('slug')) {
|
||||
// Pass the new slug through the generator to strip illegal characters, detect duplicates
|
||||
return ghostBookshelf.Model.generateSlug(Tag, this.get('slug') || this.get('name'),
|
||||
{transacting: options.transacting})
|
||||
.then(function (slug) {
|
||||
self.set({slug: slug});
|
||||
});
|
||||
|
|
|
@ -38,7 +38,9 @@ User = ghostBookshelf.Model.extend({
|
|||
|
||||
tableName: 'users',
|
||||
|
||||
saving: function () {
|
||||
saving: function (newPage, attr, options) {
|
||||
/*jshint unused:false*/
|
||||
|
||||
var self = this;
|
||||
// disabling sanitization until we can implement a better version
|
||||
// this.set('name', this.sanitize('name'));
|
||||
|
@ -49,14 +51,14 @@ User = ghostBookshelf.Model.extend({
|
|||
|
||||
ghostBookshelf.Model.prototype.saving.apply(this, arguments);
|
||||
|
||||
if (!this.get('slug')) {
|
||||
if (this.hasChanged('slug') || !this.get('slug')) {
|
||||
// Generating a slug requires a db call to look for conflicting slugs
|
||||
return ghostBookshelf.Model.generateSlug(User, this.get('name'))
|
||||
return ghostBookshelf.Model.generateSlug(User, this.get('slug') || this.get('name'),
|
||||
{transacting: options.transacting})
|
||||
.then(function (slug) {
|
||||
self.set({slug: slug});
|
||||
});
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
posts: function () {
|
||||
|
|
Loading…
Add table
Reference in a new issue