sync: try to remove old exercice without any player try
This commit is contained in:
parent
c05609f85f
commit
7f2ae673d0
@ -106,7 +106,7 @@ func SyncExercices(i Importer, theme fic.Theme) []string {
|
|||||||
for k, _ := range dmap {
|
for k, _ := range dmap {
|
||||||
dmap_keys = append(dmap_keys, fmt.Sprintf("%d", k))
|
dmap_keys = append(dmap_keys, fmt.Sprintf("%d", k))
|
||||||
}
|
}
|
||||||
errs = append(errs, fmt.Sprintf("%q: Unable to find required dependancy %q (available at time of processing: %s)", edir, p.Dependencies[0].Id, strings.Join(dmap_keys, ",")))
|
errs = append(errs, fmt.Sprintf("%q: Unable to find required dependancy %d (available at time of processing: %s)", edir, p.Dependencies[0].Id, strings.Join(dmap_keys, ",")))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -162,7 +162,7 @@ func SyncExercices(i Importer, theme fic.Theme) []string {
|
|||||||
if exercices, err := theme.GetExercices(); err == nil {
|
if exercices, err := theme.GetExercices(); err == nil {
|
||||||
for _, ex := range exercices {
|
for _, ex := range exercices {
|
||||||
if _, ok := emap[ex.Title]; !ok {
|
if _, ok := emap[ex.Title]; !ok {
|
||||||
ex.Delete()
|
ex.DeleteCascade()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -190,6 +190,52 @@ func (e Exercice) Delete() (int64, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeleteCascade the challenge from the database, including inner content but not player content.
|
||||||
|
func (e Exercice) DeleteCascade() (int64, error) {
|
||||||
|
if _, err := DBExec("UPDATE exercices SET id_depend = NULL WHERE id_depend = ?", e.Id); err != nil {
|
||||||
|
return 0, err
|
||||||
|
} else if _, err := DBExec("DELETE FROM exercice_files_deps WHERE id_file IN (SELECT id_file FROM exercice_files WHERE id_exercice = ?)", e.Id); err != nil {
|
||||||
|
return 0, err
|
||||||
|
} else if _, err := DBExec("DELETE FROM exercice_files WHERE id_exercice = ?", e.Id); err != nil {
|
||||||
|
return 0, err
|
||||||
|
} else if _, err := DBExec("DELETE FROM exercice_hints WHERE id_exercice = ?", e.Id); err != nil {
|
||||||
|
return 0, err
|
||||||
|
} else if _, err := DBExec("DELETE FROM exercice_flags_deps WHERE id_flag IN (SELECT id_flag FROM exercice_flags WHERE id_exercice = ?)", e.Id); err != nil {
|
||||||
|
return 0, err
|
||||||
|
} else if _, err := DBExec("DELETE FROM exercice_flags_choices WHERE id_flag IN (SELECT id_flag FROM exercice_flags WHERE id_exercice = ?)", e.Id); err != nil {
|
||||||
|
return 0, err
|
||||||
|
} else if _, err := DBExec("DELETE FROM exercice_flags WHERE id_exercice = ?", e.Id); err != nil {
|
||||||
|
return 0, err
|
||||||
|
} else if _, err := DBExec("DELETE FROM mcq_entries WHERE id_mcq IN (SELECT id_mcq FROM exercice_flags WHERE id_exercice = ?)", e.Id); err != nil {
|
||||||
|
return 0, err
|
||||||
|
} else if _, err := DBExec("DELETE FROM exercice_mcq WHERE id_exercice = ?", e.Id); err != nil {
|
||||||
|
return 0, err
|
||||||
|
} else if _, err := DBExec("DELETE FROM exercice_tags WHERE id_exercice = ?", e.Id); err != nil {
|
||||||
|
return 0, err
|
||||||
|
} else {
|
||||||
|
return e.Delete()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteDeep the challenge from the database, including player content.
|
||||||
|
func (e Exercice) DeleteDeep() (int64, error) {
|
||||||
|
if _, err := DBExec("DELETE FROM mcq_found WHERE id_mcq IN (SELECT id_mcq FROM exercice_mcq WHERE id_exercice = ?)", e.Id); err != nil {
|
||||||
|
return 0, err
|
||||||
|
} else if _, err := DBExec("DELETE FROM flag_found WHERE id_flag IN (SELECT id_flag FROM exercice_flags WHERE id_exercice = ?)", e.Id); err != nil {
|
||||||
|
return 0, err
|
||||||
|
} else if _, err := DBExec("DELETE FROM team_hints WHERE id_hint IN (SELECT id_hint FROM exercice_hints WHERE id_exercice = ?)", e.Id); err != nil {
|
||||||
|
return 0, err
|
||||||
|
} else if _, err := DBExec("DELETE FROM team_wchoices WHERE id_flag IN (SELECT id_flag FROM exercice_flags WHERE id_exercice = ?)", e.Id); err != nil {
|
||||||
|
return 0, err
|
||||||
|
} else if _, err := DBExec("DELETE FROM exercice_solved WHERE id_exercice = ?", e.Id); err != nil {
|
||||||
|
return 0, err
|
||||||
|
} else if _, err := DBExec("DELETE FROM exercice_tries WHERE id_exercice = ?", e.Id); err != nil {
|
||||||
|
return 0, err
|
||||||
|
} else {
|
||||||
|
return e.DeleteCascade()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// GetLevel returns the number of dependancy challenges.
|
// GetLevel returns the number of dependancy challenges.
|
||||||
func (e Exercice) GetLevel() (int, error) {
|
func (e Exercice) GetLevel() (int, error) {
|
||||||
dep := e.Depend
|
dep := e.Depend
|
||||||
|
Loading…
Reference in New Issue
Block a user