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
|
|
|
|
|
|
|
|
import "time"
|
|
|
|
|
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
|
|
|
|
for rows.Next() {
|
|
|
|
err := rows.Scan(&uid)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-09-18 17:03:52 +00:00
|
|
|
_, err = replaceScheduleGroupStmt.Exec(uid, 0, 0, time.Now(), false)
|
2017-08-27 09:33:45 +00:00
|
|
|
if err != nil {
|
|
|
|
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 {
|
|
|
|
return err
|
|
|
|
}
|
2017-09-15 22:20:01 +00:00
|
|
|
_ = users.Reload(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
|
|
|
|
var lastUpdateStr string
|
2017-09-18 17:03:52 +00:00
|
|
|
err := getSyncStmt.QueryRow().Scan(&lastUpdateStr)
|
2017-09-10 16:57:22 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-09-18 17:03:52 +00:00
|
|
|
lastUpdate, err = time.Parse("2006-01-02 15:04:05", lastUpdateStr)
|
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 {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// TODO: Resync the groups
|
|
|
|
// TODO: Resync the permissions
|
|
|
|
err = LoadSettings()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = LoadWordFilters()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|