Sync global-autoresponder current state
This commit is contained in:
@@ -11,12 +11,41 @@ return static function (AppContext $ctx): void {
|
||||
throw new RuntimeException($ctx->t('Rule not found'));
|
||||
}
|
||||
$next = ['enabled' => empty($rule['enabled'])];
|
||||
enforce_rule_backend_constraints($ctx, $id, $next);
|
||||
if (!empty($next['enabled'])) {
|
||||
$conflict = find_active_rule_conflict($ctx, $id);
|
||||
$conflictAction = $ctx->post('conflict_action');
|
||||
$conflictRuleId = $ctx->post('conflict_rule_id');
|
||||
if ($conflict !== null && ($conflictAction !== 'replace' || $conflictRuleId !== (string)($conflict['id'] ?? ''))) {
|
||||
render_rules_index($ctx, [], [], render_toggle_conflict_modal($ctx, $rule, $conflict));
|
||||
return;
|
||||
}
|
||||
if ($conflict !== null) {
|
||||
toggle_rule_replacing_active($ctx, $id, (string)($conflict['id'] ?? ''));
|
||||
Http::redirect($ctx->url('index.html', ['status' => 'toggled']));
|
||||
return;
|
||||
}
|
||||
}
|
||||
$ctx->rules->update($ctx->daUser->username(), $id, $next);
|
||||
$ctx->syncActiveBackend();
|
||||
$ctx->syncDirectAdminVacations();
|
||||
Http::redirect($ctx->url('index.html', ['status' => 'toggled']));
|
||||
} catch (Throwable $e) {
|
||||
PluginLogger::exception($e, 'TOGGLE');
|
||||
throw $e;
|
||||
}
|
||||
};
|
||||
|
||||
function toggle_rule_replacing_active(AppContext $ctx, string $targetId, string $activeId): void
|
||||
{
|
||||
if ($activeId === '') {
|
||||
throw new RuntimeException($ctx->t('Rule not found'));
|
||||
}
|
||||
$ctx->rules->update($ctx->daUser->username(), $activeId, ['enabled' => false]);
|
||||
$ctx->rules->update($ctx->daUser->username(), $targetId, ['enabled' => true]);
|
||||
try {
|
||||
$ctx->syncDirectAdminVacations();
|
||||
} catch (Throwable $syncError) {
|
||||
$ctx->rules->update($ctx->daUser->username(), $targetId, ['enabled' => false]);
|
||||
$ctx->rules->update($ctx->daUser->username(), $activeId, ['enabled' => true]);
|
||||
throw $syncError;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user