adapt-authoring-adaptframework 2.0.7 → 2.0.9

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.
@@ -431,6 +431,7 @@ class AdaptFrameworkImport {
431
431
  if (pluginData[type] !== undefined) return type
432
432
  }
433
433
  }
434
+ this.configEnabledPlugins = this.contentJson.config?._enabledPlugins ?? []
434
435
  await Promise.all(usedPluginPaths.map(async p => {
435
436
  const bowerJson = await readJson(`${p}/bower.json`)
436
437
  const { name, version, targetAttribute } = bowerJson
@@ -613,6 +614,17 @@ class AdaptFrameworkImport {
613
614
  */
614
615
  async importCoursePlugins () {
615
616
  this.installedPlugins = (await this.contentplugin.find({})).reduce((m, p) => Object.assign(m, { [p.name]: p }), {})
617
+ const missingFromBoth = this.configEnabledPlugins.filter(p =>
618
+ !this.usedContentPlugins[p] && !this.installedPlugins[p]
619
+ )
620
+ if (missingFromBoth.length) {
621
+ if (this.settings.isDryRun) {
622
+ this.statusReport.error.push({ code: 'MISSING_PLUGINS', data: missingFromBoth })
623
+ return
624
+ }
625
+ throw App.instance.errors.FW_IMPORT_MISSING_PLUGINS
626
+ .setData({ plugins: missingFromBoth.join(', ') })
627
+ }
616
628
  const pluginsToInstall = []
617
629
  const pluginsToUpdate = []
618
630
 
@@ -858,38 +870,67 @@ class AdaptFrameworkImport {
858
870
  * @return {Promise}
859
871
  */
860
872
  async cleanUp (error) {
861
- if (!this.settings.removeSource) {
862
- return
873
+ if (error) {
874
+ await this.rollback()
863
875
  }
864
- try {
865
- const tasks = [fs.rm(this.path, { recursive: true })]
866
- if (error) {
867
- // Uninstall newly installed plugins
868
- tasks.push(Promise.all(Object.values(this.newContentPlugins).map(p => this.contentplugin.uninstallPlugin(p._id))))
869
- // Restore updated plugins to their original versions
870
- if (Object.keys(this.updatedContentPlugins).length > 0) {
871
- tasks.push(this.restoreUpdatedPlugins())
872
- }
873
- // Delete imported assets
874
- tasks.push(Promise.all(Object.values(this.assetMap).map(a => this.assets.delete({ _id: a }))))
875
- // Delete newly created tags
876
- if (this.newTagIds.length > 0) {
877
- const tags = await App.instance.waitForModule('tags')
878
- tasks.push(Promise.all(this.newTagIds.map(id => tags.delete({ _id: id }))))
879
- }
880
- let _courseId
881
- try {
882
- _courseId = parseObjectId(this.idMap[this.contentJson.course._id])
883
- } catch (e) {}
884
- if (_courseId) {
885
- tasks.push(
886
- this.content.deleteMany({ _courseId }),
887
- this.courseassets.deleteMany({ courseId: _courseId })
888
- )
889
- }
876
+ if (this.settings.removeSource) {
877
+ try {
878
+ await fs.rm(this.path, { recursive: true })
879
+ } catch (e) {} // ignore source removal errors
880
+ }
881
+ }
882
+
883
+ /**
884
+ * Rolls back all changes made during a failed import
885
+ * @return {Promise}
886
+ */
887
+ async rollback () {
888
+ log('info', 'rolling back failed import')
889
+ const tasks = []
890
+ // Uninstall newly installed plugins
891
+ if (this.contentplugin) {
892
+ tasks.push(...Object.values(this.newContentPlugins).map(p =>
893
+ this.contentplugin.uninstallPlugin(p._id)
894
+ .catch(e => log('warn', `failed to uninstall plugin '${p.name}'`, e))
895
+ ))
896
+ }
897
+ // Restore updated plugins to their original versions
898
+ if (Object.keys(this.updatedContentPlugins).length) {
899
+ tasks.push(this.restoreUpdatedPlugins())
900
+ }
901
+ // Delete imported assets
902
+ if (this.assets) {
903
+ tasks.push(...Object.values(this.assetMap).map(id =>
904
+ this.assets.delete({ _id: id })
905
+ .catch(e => log('warn', `failed to delete asset '${id}'`, e))
906
+ ))
907
+ }
908
+ // Delete newly created tags
909
+ if (this.newTagIds.length) {
910
+ try {
911
+ const tags = await App.instance.waitForModule('tags')
912
+ tasks.push(...this.newTagIds.map(id =>
913
+ tags.delete({ _id: id })
914
+ .catch(e => log('warn', `failed to delete tag '${id}'`, e))
915
+ ))
916
+ } catch (e) {
917
+ log('warn', 'failed to load tags module for rollback', e)
890
918
  }
891
- await Promise.allSettled(tasks)
892
- } catch (e) {} // ignore any thrown errors
919
+ }
920
+ // Delete course content and course assets
921
+ if (this.content) {
922
+ try {
923
+ const _courseId = parseObjectId(this.idMap[this.contentJson.course._id])
924
+ tasks.push(
925
+ this.content.deleteMany({ _courseId })
926
+ .catch(e => log('warn', 'failed to delete course content', e)),
927
+ this.courseassets.deleteMany({ courseId: _courseId })
928
+ .catch(e => log('warn', 'failed to delete course assets', e))
929
+ )
930
+ } catch (e) {} // courseId not available, no content to roll back
931
+ }
932
+ await Promise.allSettled(tasks)
933
+ log('info', 'rollback complete')
893
934
  }
894
935
 
895
936
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adapt-authoring-adaptframework",
3
- "version": "2.0.7",
3
+ "version": "2.0.9",
4
4
  "description": "Adapt framework integration for the Adapt authoring tool",
5
5
  "homepage": "https://github.com/adapt-security/adapt-authoring-adaptframework",
6
6
  "license": "GPL-3.0",
@@ -17,6 +17,7 @@
17
17
  "adapt-authoring-core": "^2.0.0",
18
18
  "adapt-authoring-courseassets": "^1.0.3",
19
19
  "adapt-authoring-coursetheme": "^1.0.2",
20
+ "adapt-authoring-mongodb": "^3.0.0",
20
21
  "adapt-authoring-spoortracking": "^1.0.2",
21
22
  "adapt-cli": "^3.3.3",
22
23
  "adapt-octopus": "^0.1.2",
@@ -33,7 +34,6 @@
33
34
  "adapt-authoring-auth": "^2.0.0",
34
35
  "adapt-authoring-jsonschema": "^1.1.5",
35
36
  "adapt-authoring-middleware": "^1.0.1",
36
- "adapt-authoring-mongodb": "^3.0.0",
37
37
  "adapt-authoring-server": "^2.0.0",
38
38
  "adapt-authoring-tags": "^1.0.1"
39
39
  },