mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender.git
synced 2025-07-16 09:38:49 +02:00
55 lines
1.2 KiB
Go
55 lines
1.2 KiB
Go
package ical
|
|
|
|
import (
|
|
"encoding/json"
|
|
"github.com/pocketbase/dbx"
|
|
"github.com/pocketbase/pocketbase"
|
|
"htwkalender/model"
|
|
)
|
|
|
|
//update ical feed json
|
|
//add uuid field
|
|
//remove module name field
|
|
|
|
func MigrateFeedJson(app *pocketbase.PocketBase) {
|
|
|
|
var feeds []model.Feed
|
|
|
|
err := app.Dao().DB().Select("*").From("feed").All(&feeds)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
for _, feed := range feeds {
|
|
|
|
var modules []model.FeedCollection
|
|
|
|
err := json.Unmarshal([]byte(feed.Modules), &modules)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
var uuidFeedCollection model.UUIDFeedCollection
|
|
|
|
for _, module := range modules {
|
|
uuid := searchUUIDForModule(app, module.Name)
|
|
|
|
if uuid != "" {
|
|
uuidFeedCollection = model.UUIDFeedCollection{UUID: uuid, Name: module.Name, Course: module.Course, UserDefinedName: module.UserDefinedName}
|
|
app.Dao().DB().Update("feed", dbx.Params{"modules": uuidFeedCollection}, dbx.NewExp("id = {:id}", dbx.Params{"id": feed.Id}))
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func searchUUIDForModule(app *pocketbase.PocketBase, module string) string {
|
|
var uuid string
|
|
err := app.Dao().DB().Select("uuid").From("module").Where(dbx.NewExp("name = {:name}", dbx.Params{"name": module})).One(&uuid)
|
|
if err != nil {
|
|
return ""
|
|
}
|
|
return uuid
|
|
}
|