adapt-authoring-adaptframework 2.0.8 → 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.
- package/lib/AdaptFrameworkImport.js +71 -30
- package/package.json +1 -1
|
@@ -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 (
|
|
862
|
-
|
|
873
|
+
if (error) {
|
|
874
|
+
await this.rollback()
|
|
863
875
|
}
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
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
|
-
|
|
892
|
-
|
|
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.
|
|
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",
|