-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSourceController.php
More file actions
64 lines (53 loc) · 2.26 KB
/
Copy pathSourceController.php
File metadata and controls
64 lines (53 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
// SPDX-FileCopyrightText: 2024 Icinga GmbH <https://icinga.com>
// SPDX-License-Identifier: GPL-3.0-or-later
namespace Icinga\Module\Notifications\Controllers;
use Icinga\Module\Notifications\Common\Database;
use Icinga\Module\Notifications\Forms\DeleteSourceForm;
use Icinga\Module\Notifications\Forms\SourceForm;
use Icinga\Web\Notification;
use Icinga\Web\Session;
use ipl\Html\Contract\Form;
use ipl\Sql\Connection;
use ipl\Web\Compat\CompatController;
use ipl\Web\Url;
class SourceController extends CompatController
{
public function init(): void
{
$this->assertPermission('config/modules');
}
public function indexAction(): void
{
$sourceId = (int) $this->params->getRequired('id');
$form = (new SourceForm(Database::get()))
->setCsrfCounterMeasureId(Session::getSession()->getId())
->loadSource($sourceId)
->on(Form::ON_SUBMIT, function (SourceForm $form): never {
Database::get()->transaction(fn () => $form->editSource());
Notification::success(sprintf(
$this->translate('Updated source "%s" successfully'),
$form->getSourceName()
));
$this->switchToSingleColumnLayout();
})->handleRequest($this->getServerRequest());
$this->addTitleTab(sprintf($this->translate('Source: %s'), $form->getSourceName()));
$this->addContent($form);
}
public function deleteAction(): void
{
$sourceId = (int) $this->params->getRequired('id');
$form = (new DeleteSourceForm())
->setCsrfCounterMeasureId(Session::getSession()->getId())
->loadSource($sourceId)
->setAction(Url::fromRequest()->getAbsoluteUrl())
->on(Form::ON_SUBMIT, function (DeleteSourceForm $form): never {
Database::get()->transaction(fn (Connection $db) => $form->removeSource($db));
Notification::success($this->translate('Deleted source successfully'));
$this->switchToSingleColumnLayout();
})
->handleRequest($this->getServerRequest());
$this->setTitle(sprintf($this->translate('Delete Source: %s'), $form->getSourceName()));
$this->addContent($form);
}
}