2017-09-13 15:09:13 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Gosora Task System
|
|
|
|
* Copyright Azareal 2017 - 2018
|
|
|
|
*
|
|
|
|
*/
|
2017-11-11 04:06:16 +00:00
|
|
|
package common
|
2017-08-27 09:33:45 +00:00
|
|
|
|
2017-10-16 07:32:58 +00:00
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"time"
|
2017-11-11 04:06:16 +00:00
|
|
|
|
|
|
|
"../query_gen/lib"
|
2017-10-16 07:32:58 +00:00
|
|
|
)
|
2017-08-27 09:33:45 +00:00
|
|
|
|
2017-09-10 16:57:22 +00:00
|
|
|
var lastSync time.Time
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
lastSync = time.Now()
|
|
|
|
}
|
|
|
|
|
2017-11-11 04:06:16 +00:00
|
|
|
func HandleExpiredScheduledGroups() error {
|
|
|
|
getExpiredScheduledGroups, err := qgen.Builder.SimpleSelect("users_groups_scheduler", "uid", "UTC_TIMESTAMP() > revert_at AND temporary = 1", "", "")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
rows, err := getExpiredScheduledGroups.Query()
|
2017-08-27 09:33:45 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
|
|
|
|
var uid int
|
|
|
|
for rows.Next() {
|
|
|
|
err := rows.Scan(&uid)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-10-21 00:27:47 +00:00
|
|
|
|
|
|
|
// Sneaky way of initialising a *User, please use the methods on the UserStore instead
|
2017-11-11 04:06:16 +00:00
|
|
|
user := BlankUser()
|
2017-10-21 00:27:47 +00:00
|
|
|
user.ID = uid
|
|
|
|
err = user.RevertGroupUpdate()
|
2017-08-27 09:33:45 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rows.Err()
|
|
|
|
}
|
2017-09-10 16:57:22 +00:00
|
|
|
|
2017-11-11 04:06:16 +00:00
|
|
|
func HandleServerSync() error {
|
2017-09-10 16:57:22 +00:00
|
|
|
var lastUpdate time.Time
|
2017-11-11 04:06:16 +00:00
|
|
|
getSync, err := qgen.Builder.SimpleSelect("sync", "last_update", "", "", "")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = getSync.QueryRow().Scan(&lastUpdate)
|
2017-09-10 16:57:22 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if lastUpdate.After(lastSync) {
|
|
|
|
// TODO: A more granular sync
|
2017-11-11 04:06:16 +00:00
|
|
|
err = Fstore.LoadForums()
|
2017-09-10 16:57:22 +00:00
|
|
|
if err != nil {
|
2017-10-16 07:32:58 +00:00
|
|
|
log.Print("Unable to reload the forums")
|
2017-09-10 16:57:22 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
// TODO: Resync the groups
|
|
|
|
// TODO: Resync the permissions
|
|
|
|
err = LoadSettings()
|
|
|
|
if err != nil {
|
2017-10-16 07:32:58 +00:00
|
|
|
log.Print("Unable to reload the settings")
|
2017-09-10 16:57:22 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = LoadWordFilters()
|
|
|
|
if err != nil {
|
2017-10-16 07:32:58 +00:00
|
|
|
log.Print("Unable to reload the word filters")
|
2017-09-10 16:57:22 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|