admin/sync: import theme introductions

This commit is contained in:
nemunaire 2017-12-21 22:17:41 +01:00
parent 39b57119fe
commit ea3f3b709d
4 changed files with 34 additions and 22 deletions

View file

@ -40,24 +40,31 @@ func SyncThemes(i Importer) []string {
errs = append(errs, err.Error())
} else {
for _, tname := range themes {
if authors, err := getAuthors(i, tname); err != nil {
var authors []string
var intro string
var theme fic.Theme
if authors, err = getAuthors(i, tname); err != nil {
errs = append(errs, fmt.Sprintf("%q: unable to get AUTHORS: %s", tname, err))
continue
} else if theme, err := fic.GetThemeByName(tname); err != nil {
if _, err := fic.CreateTheme(tname, strings.Join(authors, ", ")); err != nil {
} else if intro, err = getFileContent(i, path.Join(tname, "introduction.txt")); err != nil {
errs = append(errs, fmt.Sprintf("%q: unable to get introduction: %s", tname, err))
} else if theme, err = fic.GetThemeByName(tname); err != nil {
if _, err := fic.CreateTheme(tname, strings.Join(authors, ", "), intro); err != nil {
errs = append(errs, fmt.Sprintf("%q: an error occurs during add: %s", tname, err))
continue
}
} else {
authors_str := strings.Join(authors, ", ")
}
if theme.Name != tname || theme.Authors != authors_str {
theme.Name = tname
theme.Authors = authors_str
if _, err := theme.Update(); err != nil {
errs = append(errs, fmt.Sprintf("%q: an error occurs during update: %s", tname, err))
continue
}
authors_str := strings.Join(authors, ", ")
if theme.Name != tname || theme.Authors != authors_str || theme.Intro != intro {
theme.Name = tname
theme.Authors = authors_str
theme.Intro = intro
if _, err := theme.Update(); err != nil {
errs = append(errs, fmt.Sprintf("%q: an error occurs during update: %s", tname, err))
continue
}
}
}