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{
|
|
||||||
PiwigoId: pwgcat.Id,
|
dbcat, err := db.GetCategoryByPiwigoId(pwgcat.Id)
|
||||||
PiwigoParentId: pwgcat.ParentId,
|
if err == datastore.ErrorRecordNotFound {
|
||||||
Name: pwgcat.Name,
|
logrus.Debugf("Adding category %s", pwgcat.Key)
|
||||||
Key: pwgcat.Key,
|
dbcat = datastore.CategoryData{
|
||||||
|
PiwigoId: pwgcat.Id,
|
||||||
|
}
|
||||||
|
} else if err != nil {
|
||||||
|
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