23 lines
764 B
PHP
23 lines
764 B
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
return static function (AppContext $ctx): void {
|
|
try {
|
|
$ctx->requirePost();
|
|
$id = $ctx->post('id');
|
|
$ctx->requireCsrf('toggle:' . $id);
|
|
$rule = $ctx->rules->find($ctx->daUser->username(), $id);
|
|
if ($rule === null) {
|
|
throw new RuntimeException($ctx->t('Rule not found'));
|
|
}
|
|
$next = ['enabled' => empty($rule['enabled'])];
|
|
enforce_rule_backend_constraints($ctx, $id, $next);
|
|
$ctx->rules->update($ctx->daUser->username(), $id, $next);
|
|
$ctx->syncActiveBackend();
|
|
Http::redirect($ctx->url('index.html', ['status' => 'toggled']));
|
|
} catch (Throwable $e) {
|
|
PluginLogger::exception($e, 'TOGGLE');
|
|
throw $e;
|
|
}
|
|
};
|