WIP: implemented logic to update category
This commit is contained in:
parent
0d7ca76b98
commit
ca2620d426
@ -24,14 +24,27 @@ func SynchronizePiwigoCategories(piwigoApi piwigo.PiwigoCategoryApi, db datastor
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, pwgcat := range categories {
|
for _, pwgcat := range categories {
|
||||||
cat := datastore.CategoryData{
|
|
||||||
|
dbcat, err := db.GetCategoryByPiwigoId(pwgcat.Id)
|
||||||
|
if err == datastore.ErrorRecordNotFound {
|
||||||
|
logrus.Debugf("Adding category %s", pwgcat.Key)
|
||||||
|
dbcat = datastore.CategoryData{
|
||||||
PiwigoId: pwgcat.Id,
|
PiwigoId: pwgcat.Id,
|
||||||
PiwigoParentId: pwgcat.ParentId,
|
}
|
||||||
Name: pwgcat.Name,
|
} else if err != nil {
|
||||||
Key: pwgcat.Key,
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = db.SaveCategory(cat)
|
if dbcat.Name == pwgcat.Name && dbcat.Key == pwgcat.Key && dbcat.PiwigoParentId == pwgcat.ParentId {
|
||||||
|
logrus.Debugf("No changes for category %s", dbcat.Key)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
dbcat.Name = pwgcat.Name
|
||||||
|
dbcat.Key = pwgcat.Key
|
||||||
|
dbcat.PiwigoParentId = pwgcat.ParentId
|
||||||
|
|
||||||
|
err = db.SaveCategory(dbcat)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user