adapt-authoring-adaptframework 1.9.6 → 1.9.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/AdaptFrameworkImport.js +22 -10
- package/package.json +1 -1
|
@@ -446,7 +446,15 @@ class AdaptFrameworkImport {
|
|
|
446
446
|
* @return {Promise}
|
|
447
447
|
*/
|
|
448
448
|
async loadContentFile (filePath) {
|
|
449
|
-
|
|
449
|
+
let contents
|
|
450
|
+
try {
|
|
451
|
+
contents = await FWUtils.readJson(filePath)
|
|
452
|
+
} catch (e) {
|
|
453
|
+
if (e.constructor.name === 'SyntaxError') {
|
|
454
|
+
throw App.instance.errors.FILE_SYNTAX_ERROR.setData({ path: filePath.replace(this.path, ''), message: e.message })
|
|
455
|
+
}
|
|
456
|
+
throw e
|
|
457
|
+
}
|
|
450
458
|
if (contents._type === 'course') {
|
|
451
459
|
this.contentJson.course = contents
|
|
452
460
|
return
|
|
@@ -679,19 +687,26 @@ class AdaptFrameworkImport {
|
|
|
679
687
|
* @return {Promise}
|
|
680
688
|
*/
|
|
681
689
|
async importCourseData () {
|
|
690
|
+
const stringifyError = e => {
|
|
691
|
+
return e?.data?.schemaName ? `${e.data.schemaName} ${e.data.data._id} ${e.data.errors}` : App.instance.lang.translate(undefined, e)
|
|
692
|
+
}
|
|
682
693
|
/**
|
|
683
694
|
* Note: the execution order is important here
|
|
684
695
|
* - config requires course to exist
|
|
685
696
|
* - Defaults cannot be applied until the config exists
|
|
686
697
|
* - Everything else requires course + config to exist
|
|
687
698
|
*/
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
699
|
+
try {
|
|
700
|
+
const course = await this.importContentObject({ ...this.contentJson.course, tags: this.tags })
|
|
701
|
+
/* config */ await this.importContentObject(this.contentJson.config)
|
|
702
|
+
// we need to run an update with the same data to make sure all extension schema settings are applied
|
|
703
|
+
await this.importContentObject({ ...this.contentJson.course, _id: course._id }, { isUpdate: true })
|
|
704
|
+
} catch (e) {
|
|
705
|
+
throw App.instance.errors.FW_IMPORT_CONTENT_FAILED.setData({ errors: stringifyError(e) })
|
|
706
|
+
}
|
|
693
707
|
const { sorted, hierarchy } = await this.getSortedData()
|
|
694
708
|
const errors = []
|
|
709
|
+
|
|
695
710
|
for (const ids of sorted) {
|
|
696
711
|
for (const _id of ids) {
|
|
697
712
|
try {
|
|
@@ -701,10 +716,7 @@ class AdaptFrameworkImport {
|
|
|
701
716
|
...itemJson // note that JSON sort order will override the deduced one
|
|
702
717
|
})
|
|
703
718
|
} catch (e) {
|
|
704
|
-
errors.push(e
|
|
705
|
-
? `${e.data.schemaName} ${_id} ${e.data.errors}`
|
|
706
|
-
: App.instance.lang.translate(undefined, e)
|
|
707
|
-
)
|
|
719
|
+
errors.push(stringifyError(e))
|
|
708
720
|
}
|
|
709
721
|
}
|
|
710
722
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "adapt-authoring-adaptframework",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.8",
|
|
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",
|