2020-07-01 17:16:24 +02:00
|
|
|
package query
|
|
|
|
|
|
|
|
import (
|
2020-07-07 10:51:55 +02:00
|
|
|
"strings"
|
|
|
|
|
2020-07-01 17:16:24 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/entity"
|
|
|
|
)
|
|
|
|
|
2020-07-07 10:51:55 +02:00
|
|
|
// Errors returns the error log filtered with an optional search string.
|
2022-04-03 12:37:43 +02:00
|
|
|
func Errors(limit, offset int, search string) (results entity.Errors, err error) {
|
2020-07-01 17:16:24 +02:00
|
|
|
stmt := Db()
|
|
|
|
|
2022-04-03 12:37:43 +02:00
|
|
|
search = strings.TrimSpace(search)
|
2020-07-07 10:51:55 +02:00
|
|
|
|
2022-04-03 12:37:43 +02:00
|
|
|
if search == "error" || search == "errors" {
|
2020-07-14 18:00:32 +02:00
|
|
|
stmt = stmt.Where("error_level = 'error'")
|
2022-04-03 12:37:43 +02:00
|
|
|
} else if search == "warning" || search == "warnings" {
|
2020-07-14 18:00:32 +02:00
|
|
|
stmt = stmt.Where("error_level = 'warning'")
|
2022-04-03 12:37:43 +02:00
|
|
|
} else if len(search) >= 3 {
|
|
|
|
stmt = stmt.Where("error_message LIKE ?", "%"+search+"%")
|
2020-07-07 10:51:55 +02:00
|
|
|
}
|
|
|
|
|
2020-07-01 17:16:24 +02:00
|
|
|
err = stmt.Order("error_time DESC").Limit(limit).Offset(offset).Find(&results).Error
|
|
|
|
|
|
|
|
return results, err
|
|
|
|
}
|
2022-04-03 12:37:43 +02:00
|
|
|
|
|
|
|
// DeleteErrors removes all entries from the errors table.
|
|
|
|
func DeleteErrors() (err error) {
|
|
|
|
return UnscopedDb().Delete(entity.Error{}).Error
|
|
|
|
}
|