diff --git a/ghost/core/core/server/services/collections/BookshelfCollectionsRepository.js b/ghost/core/core/server/services/collections/BookshelfCollectionsRepository.js index 855226d756..09054cf95d 100644 --- a/ghost/core/core/server/services/collections/BookshelfCollectionsRepository.js +++ b/ghost/core/core/server/services/collections/BookshelfCollectionsRepository.js @@ -12,9 +12,12 @@ const {default: ObjectID} = require('bson-objectid'); module.exports = class BookshelfCollectionsRepository { #model; #relationModel; - constructor(model, relationModel) { + /** @type {import('@tryghost/domain-events')} */ + #DomainEvents; + constructor(model, relationModel, DomainEvents) { this.#model = model; this.#relationModel = relationModel; + this.#DomainEvents = DomainEvents; } async createTransaction(cb) { @@ -241,6 +244,12 @@ module.exports = class BookshelfCollectionsRepository { if (collectionPostRelationsToDeleteIds.length > 0) { await this.#relationModel.query().delete().whereIn('id', collectionPostRelationsToDeleteIds).transacting(options.transaction); } + + options.transaction.executionPromise.then(() => { + for (const event of collection.events) { + this.#DomainEvents.dispatch(event); + } + }); } } }; diff --git a/ghost/core/core/server/services/collections/service.js b/ghost/core/core/server/services/collections/service.js index 3bdc9faf72..86f017b869 100644 --- a/ghost/core/core/server/services/collections/service.js +++ b/ghost/core/core/server/services/collections/service.js @@ -12,7 +12,7 @@ class CollectionsServiceWrapper { const DomainEvents = require('@tryghost/domain-events'); const postsRepository = require('./PostsRepository').getInstance(); const models = require('../../models'); - const collectionsRepositoryInMemory = new BookshelfCollectionsRepository(models.Collection, models.CollectionPost); + const collectionsRepositoryInMemory = new BookshelfCollectionsRepository(models.Collection, models.CollectionPost, DomainEvents); const collectionsService = new CollectionsService({ collectionsRepository: collectionsRepositoryInMemory,