2017-09-13 15:09:13 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Gosora Task System
|
|
|
|
* Copyright Azareal 2017 - 2018
|
|
|
|
*
|
|
|
|
*/
|
2017-08-27 09:33:45 +00:00
|
|
|
package main
|
|
|
|
|
2017-10-16 07:32:58 +00:00
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"time"
|
|
|
|
)
|
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-09-03 04:50:31 +00:00
|
|
|
func handleExpiredScheduledGroups() error {
|
2017-09-18 17:03:52 +00:00
|
|
|
rows, err := getExpiredScheduledGroupsStmt.Query()
|
2017-08-27 09:33:45 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
|
|
|
|
var uid int
|
2017-09-22 02:21:17 +00:00
|
|
|
ucache, ok := users.(UserCache)
|
2017-08-27 09:33:45 +00:00
|
|
|
for rows.Next() {
|
|
|
|
err := rows.Scan(&uid)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-10-16 07:32:58 +00:00
|
|
|
_, err = replaceScheduleGroupStmt.Exec(uid, 0, 0, time.Now(), false, uid)
|
2017-08-27 09:33:45 +00:00
|
|
|
if err != nil {
|
2017-10-16 07:32:58 +00:00
|
|
|
log.Print("Unable to replace the scheduled group")
|
2017-08-27 09:33:45 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-09-18 17:03:52 +00:00
|
|
|
_, err = setTempGroupStmt.Exec(0, uid)
|
2017-08-27 09:33:45 +00:00
|
|
|
if err != nil {
|
2017-10-16 07:32:58 +00:00
|
|
|
log.Print("Unable to reset the tempgroup")
|
2017-08-27 09:33:45 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-09-22 02:21:17 +00:00
|
|
|
if ok {
|
|
|
|
ucache.CacheRemove(uid)
|
|
|
|
}
|
2017-08-27 09:33:45 +00:00
|
|
|
}
|
|
|
|
return rows.Err()
|
|
|
|
}
|
2017-09-10 16:57:22 +00:00
|
|
|
|
|
|
|
func handleServerSync() error {
|
|
|
|
var lastUpdate time.Time
|
2017-10-14 07:39:22 +00:00
|
|
|
err := getSyncStmt.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
|
|
|
|
err = fstore.LoadForums()
|
|
|
|
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
|
|
|
|
}
|