mirror of
https://github.com/drakkan/sftpgo.git
synced 2024-11-25 00:50:31 +00:00
shared providers: allow to immediately re-add soft-deleted event rules
Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
parent
9d7e30807d
commit
3b2002d9ef
2 changed files with 10 additions and 0 deletions
|
@ -3133,6 +3133,12 @@ func sqlCommonAddEventRule(rule *EventRule, dbHandle *sql.DB) error {
|
|||
defer cancel()
|
||||
|
||||
return sqlCommonExecuteTx(ctx, dbHandle, func(tx *sql.Tx) error {
|
||||
if config.IsShared == 1 {
|
||||
_, err := tx.ExecContext(ctx, getRemoveSoftDeletedRuleQuery(), rule.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
q := getAddEventRuleQuery()
|
||||
_, err := tx.ExecContext(ctx, q, rule.Name, rule.Description, util.GetTimeAsMsSinceEpoch(time.Now()),
|
||||
util.GetTimeAsMsSinceEpoch(time.Now()), rule.Trigger, string(conditions))
|
||||
|
|
|
@ -895,6 +895,10 @@ func getDeleteEventRuleQuery(softDelete bool) string {
|
|||
return fmt.Sprintf(`DELETE FROM %s WHERE name = %s`, sqlTableEventsRules, sqlPlaceholders[0])
|
||||
}
|
||||
|
||||
func getRemoveSoftDeletedRuleQuery() string {
|
||||
return fmt.Sprintf(`DELETE FROM %s WHERE name = %s AND deleted_at > 0`, sqlTableEventsRules, sqlPlaceholders[0])
|
||||
}
|
||||
|
||||
func getClearRuleActionMappingQuery() string {
|
||||
return fmt.Sprintf(`DELETE FROM %s WHERE rule_id = (SELECT id FROM %s WHERE name = %s)`, sqlTableRulesActionsMapping,
|
||||
sqlTableEventsRules, sqlPlaceholders[0])
|
||||
|
|
Loading…
Reference in a new issue