admin/sync: tiny refactor
This commit is contained in:
parent
5edccf21cd
commit
494ccb740b
@ -60,9 +60,7 @@ func SyncExerciceKeys(i Importer, exercice fic.Exercice) []string {
|
|||||||
return errs
|
return errs
|
||||||
}
|
}
|
||||||
|
|
||||||
func SyncExerciceMCQ(i Importer, exercice fic.Exercice) []string {
|
func SyncExerciceMCQ(i Importer, exercice fic.Exercice) (errs []string) {
|
||||||
var errs []string
|
|
||||||
|
|
||||||
if _, err := exercice.WipeMCQs(); err != nil {
|
if _, err := exercice.WipeMCQs(); err != nil {
|
||||||
errs = append(errs, err.Error())
|
errs = append(errs, err.Error())
|
||||||
return errs
|
return errs
|
||||||
@ -70,7 +68,9 @@ func SyncExerciceMCQ(i Importer, exercice fic.Exercice) []string {
|
|||||||
|
|
||||||
// Unique Choice Questions (checkbox)
|
// Unique Choice Questions (checkbox)
|
||||||
if ucq, err := getFileContent(i, path.Join(exercice.Path, "flags-ucq.txt")); err != nil {
|
if ucq, err := getFileContent(i, path.Join(exercice.Path, "flags-ucq.txt")); err != nil {
|
||||||
|
if i.exists(path.Join(exercice.Path, "flags-ucq.txt")) {
|
||||||
errs = append(errs, fmt.Sprintf("%q: unable to read ucq: %s", path.Base(exercice.Path), err))
|
errs = append(errs, fmt.Sprintf("%q: unable to read ucq: %s", path.Base(exercice.Path), err))
|
||||||
|
}
|
||||||
} else if flag, err := exercice.AddMCQ(""); err != nil {
|
} else if flag, err := exercice.AddMCQ(""); err != nil {
|
||||||
errs = append(errs, fmt.Sprintf("%q: unable to add ucq: %s", path.Base(exercice.Path), err))
|
errs = append(errs, fmt.Sprintf("%q: unable to add ucq: %s", path.Base(exercice.Path), err))
|
||||||
} else {
|
} else {
|
||||||
@ -98,7 +98,9 @@ func SyncExerciceMCQ(i Importer, exercice fic.Exercice) []string {
|
|||||||
|
|
||||||
// Multiple Choice Questions (radio)
|
// Multiple Choice Questions (radio)
|
||||||
if mcq, err := getFileContent(i, path.Join(exercice.Path, "flags-mcq.txt")); err != nil {
|
if mcq, err := getFileContent(i, path.Join(exercice.Path, "flags-mcq.txt")); err != nil {
|
||||||
|
if i.exists(path.Join(exercice.Path, "flags-mcq.txt")) {
|
||||||
errs = append(errs, fmt.Sprintf("%q: unable to read mcq: %s", path.Base(exercice.Path), err))
|
errs = append(errs, fmt.Sprintf("%q: unable to read mcq: %s", path.Base(exercice.Path), err))
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
for nline, quest := range strings.Split(mcq, "\n") {
|
for nline, quest := range strings.Split(mcq, "\n") {
|
||||||
quest_splt := strings.Split(string(quest), "\t")
|
quest_splt := strings.Split(string(quest), "\t")
|
||||||
|
@ -15,11 +15,11 @@ import (
|
|||||||
|
|
||||||
var oneDeepSync sync.Mutex
|
var oneDeepSync sync.Mutex
|
||||||
|
|
||||||
func SyncDeep(i Importer) map[string][]string {
|
func SyncDeep(i Importer) (errs map[string][]string) {
|
||||||
oneDeepSync.Lock()
|
oneDeepSync.Lock()
|
||||||
defer oneDeepSync.Unlock()
|
defer oneDeepSync.Unlock()
|
||||||
|
|
||||||
errs := map[string][]string{}
|
errs = map[string][]string{}
|
||||||
|
|
||||||
errs["_date"] = []string{fmt.Sprintf("%v", time.Now())}
|
errs["_date"] = []string{fmt.Sprintf("%v", time.Now())}
|
||||||
errs["_themes"] = SyncThemes(i)
|
errs["_themes"] = SyncThemes(i)
|
||||||
@ -52,6 +52,8 @@ func SyncDeep(i Importer) map[string][]string {
|
|||||||
|
|
||||||
errs["_date"] = append(errs["_date"], fmt.Sprintf("%v", time.Now()))
|
errs["_date"] = append(errs["_date"], fmt.Sprintf("%v", time.Now()))
|
||||||
|
|
||||||
|
errs["_regeneration"] = []string{}
|
||||||
|
|
||||||
if fdto, err := os.Create("../htdocs-admin/full_import_report.json"); err == nil {
|
if fdto, err := os.Create("../htdocs-admin/full_import_report.json"); err == nil {
|
||||||
defer fdto.Close()
|
defer fdto.Close()
|
||||||
|
|
||||||
@ -59,17 +61,18 @@ func SyncDeep(i Importer) map[string][]string {
|
|||||||
if out, err := json.Marshal(errs); err == nil {
|
if out, err := json.Marshal(errs); err == nil {
|
||||||
fdto.Write(out)
|
fdto.Write(out)
|
||||||
} else {
|
} else {
|
||||||
|
errs["_regeneration"] = append(errs["_regeneration"], err.Error())
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
}
|
}
|
||||||
fdto.Write([]byte(");"))
|
fdto.Write([]byte(");"))
|
||||||
} else {
|
} else {
|
||||||
|
errs["_regeneration"] = append(errs["_regeneration"], err.Error())
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
errs["_regeneration"] = []string{}
|
|
||||||
if err := settings.ForceRegeneration(); err != nil {
|
if err := settings.ForceRegeneration(); err != nil {
|
||||||
errs["_regeneration"] = append(errs["_regeneration"], err.Error())
|
errs["_regeneration"] = append(errs["_regeneration"], err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
return errs
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user