adapt-authoring-content 2.1.6 → 2.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/ContentModule.js +21 -14
- package/package.json +1 -1
package/lib/ContentModule.js
CHANGED
|
@@ -115,8 +115,8 @@ class ContentModule extends AbstractApiModule {
|
|
|
115
115
|
return this.update({ _id: doc._id }, { _courseId: doc._id.toString() })
|
|
116
116
|
}
|
|
117
117
|
await Promise.all([
|
|
118
|
-
options.updateSortOrder !== false && this.updateSortOrder(doc, data),
|
|
119
|
-
options.updateEnabledPlugins !== false && this.updateEnabledPlugins(doc)
|
|
118
|
+
options.updateSortOrder !== false && this.updateSortOrder(doc, data, options, mongoOptions),
|
|
119
|
+
options.updateEnabledPlugins !== false && this.updateEnabledPlugins(doc, {}, options, mongoOptions)
|
|
120
120
|
])
|
|
121
121
|
return doc
|
|
122
122
|
}
|
|
@@ -133,8 +133,8 @@ class ContentModule extends AbstractApiModule {
|
|
|
133
133
|
throw e
|
|
134
134
|
}
|
|
135
135
|
await Promise.all([
|
|
136
|
-
this.updateSortOrder(doc, data),
|
|
137
|
-
this.updateEnabledPlugins(doc, data._enabledPlugins ? { forceUpdate: true } : {})
|
|
136
|
+
this.updateSortOrder(doc, data, options, mongoOptions),
|
|
137
|
+
this.updateEnabledPlugins(doc, data._enabledPlugins ? { forceUpdate: true } : {}, options, mongoOptions)
|
|
138
138
|
])
|
|
139
139
|
return doc
|
|
140
140
|
}
|
|
@@ -150,12 +150,19 @@ class ContentModule extends AbstractApiModule {
|
|
|
150
150
|
}
|
|
151
151
|
const descendants = await getDescendants(q => this.find(q), targetDoc)
|
|
152
152
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
153
|
+
// bulk-delete descendants directly to avoid per-item memory overhead and hook storms
|
|
154
|
+
if (descendants.length > 0) {
|
|
155
|
+
const mongodb = await this.app.waitForModule('mongodb')
|
|
156
|
+
await mongodb.deleteMany(this.collectionName, { _id: { $in: descendants.map(d => d._id) } }, mongoOptions)
|
|
157
|
+
}
|
|
158
|
+
// delete target via super.delete to trigger deleteHook middleware (e.g. multilang)
|
|
159
|
+
await super.delete({ _id: targetDoc._id }, options, mongoOptions)
|
|
160
|
+
if (descendants.length > 0 && options.invokePostHook !== false) {
|
|
161
|
+
await this.postDeleteHook.invoke(descendants)
|
|
162
|
+
}
|
|
156
163
|
await Promise.all([
|
|
157
|
-
this.updateEnabledPlugins(targetDoc),
|
|
158
|
-
this.updateSortOrder(targetDoc)
|
|
164
|
+
this.updateEnabledPlugins(targetDoc, {}, options, mongoOptions),
|
|
165
|
+
this.updateSortOrder(targetDoc, undefined, options, mongoOptions)
|
|
159
166
|
])
|
|
160
167
|
return [targetDoc, ...descendants]
|
|
161
168
|
}
|
|
@@ -272,7 +279,7 @@ class ContentModule extends AbstractApiModule {
|
|
|
272
279
|
* @param {Object} updateData The update data
|
|
273
280
|
* @return {Promise}
|
|
274
281
|
*/
|
|
275
|
-
async updateSortOrder (item, updateData) {
|
|
282
|
+
async updateSortOrder (item, updateData, parentOptions, parentMongoOptions) {
|
|
276
283
|
// some exceptions which don't need a _sortOrder
|
|
277
284
|
if (item._type === 'config' || item._type === 'course' || !item._parentId) {
|
|
278
285
|
return
|
|
@@ -284,7 +291,7 @@ class ContentModule extends AbstractApiModule {
|
|
|
284
291
|
}
|
|
285
292
|
return Promise.all(siblings.map(async (s, i) => {
|
|
286
293
|
const _sortOrder = i + 1
|
|
287
|
-
if (s._sortOrder !== _sortOrder) return super.update({ _id: s._id }, { _sortOrder })
|
|
294
|
+
if (s._sortOrder !== _sortOrder) return super.update({ _id: s._id }, { _sortOrder }, parentOptions, parentMongoOptions)
|
|
288
295
|
}))
|
|
289
296
|
}
|
|
290
297
|
|
|
@@ -295,7 +302,7 @@ class ContentModule extends AbstractApiModule {
|
|
|
295
302
|
* @param {Boolean} options.forceUpdate Forces an update of defaults regardless of whether the _enabledPlugins list has changed
|
|
296
303
|
* @return {Promise}
|
|
297
304
|
*/
|
|
298
|
-
async updateEnabledPlugins ({ _courseId }, options = {}) {
|
|
305
|
+
async updateEnabledPlugins ({ _courseId }, options = {}, parentOptions, parentMongoOptions) {
|
|
299
306
|
const [contentplugin, jsonschema] = await this.app.waitForModule('contentplugin', 'jsonschema')
|
|
300
307
|
const contentItems = await this.find({ _courseId })
|
|
301
308
|
const config = contentItems.find(c => c._type === 'config')
|
|
@@ -330,12 +337,12 @@ class ContentModule extends AbstractApiModule {
|
|
|
330
337
|
}, types)
|
|
331
338
|
}, [])
|
|
332
339
|
// update config._enabledPlugins
|
|
333
|
-
await super.update({ _courseId, _type: 'config' }, { _enabledPlugins })
|
|
340
|
+
await super.update({ _courseId, _type: 'config' }, { _enabledPlugins }, parentOptions, parentMongoOptions)
|
|
334
341
|
// update other affected content objects to ensure new defaults are applied
|
|
335
342
|
// note: due to the complex data, each must be updated separately rather than using updateMany
|
|
336
343
|
if (types.length > 0) {
|
|
337
344
|
const toUpdate = await super.find({ _courseId, _type: { $in: types } }, {})
|
|
338
|
-
return Promise.all(toUpdate.map(c => super.update({ _id: c._id }, {})))
|
|
345
|
+
return Promise.all(toUpdate.map(c => super.update({ _id: c._id }, {}, parentOptions, parentMongoOptions)))
|
|
339
346
|
}
|
|
340
347
|
}
|
|
341
348
|
|