2022-09-27 09:53:51 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Icinga\Module\Businessprocess\Forms;
|
|
|
|
|
|
|
|
|
|
use Icinga\Module\Businessprocess\BpConfig;
|
|
|
|
|
use Icinga\Module\Businessprocess\Modification\ProcessChanges;
|
2023-08-09 04:13:36 -04:00
|
|
|
use Icinga\Module\Businessprocess\Web\Form\BpConfigBaseForm;
|
2022-09-27 09:53:51 -04:00
|
|
|
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
|
|
|
|
|
use Icinga\Web\Session\SessionNamespace;
|
|
|
|
|
use ipl\Html\Html;
|
|
|
|
|
use ipl\Sql\Connection as IcingaDbConnection;
|
|
|
|
|
|
2023-08-09 04:13:36 -04:00
|
|
|
class CleanupNodeForm extends BpConfigBaseForm
|
2022-09-27 09:53:51 -04:00
|
|
|
{
|
|
|
|
|
/** @var MonitoringBackend|IcingaDbConnection */
|
|
|
|
|
protected $backend;
|
|
|
|
|
|
|
|
|
|
/** @var BpConfig */
|
|
|
|
|
protected $bp;
|
|
|
|
|
|
|
|
|
|
/** @var SessionNamespace */
|
|
|
|
|
protected $session;
|
|
|
|
|
|
|
|
|
|
public function setup()
|
|
|
|
|
{
|
|
|
|
|
$this->addHtml(Html::tag('h2', $this->translate('Cleanup missing nodes')));
|
|
|
|
|
|
|
|
|
|
$this->addElement('checkbox', 'cleanup_all', [
|
|
|
|
|
'class' => 'autosubmit',
|
|
|
|
|
'label' => $this->translate('Cleanup all missing nodes'),
|
|
|
|
|
'description' => $this->translate('Remove all missing nodes from config')
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
if ($this->getSentValue('cleanup_all') !== '1') {
|
|
|
|
|
$this->addElement('multiselect', 'nodes', [
|
|
|
|
|
'label' => $this->translate('Select nodes to cleanup'),
|
|
|
|
|
'required' => true,
|
|
|
|
|
'size' => 8,
|
|
|
|
|
'multiOptions' => $this->bp->getMissingChildren()
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function onSuccess()
|
|
|
|
|
{
|
|
|
|
|
$changes = ProcessChanges::construct($this->bp, $this->session);
|
|
|
|
|
|
2024-04-22 04:51:06 -04:00
|
|
|
/** @var string[] $nodesToCleanup */
|
2022-09-27 09:53:51 -04:00
|
|
|
$nodesToCleanup = $this->getValue('cleanup_all') === '1'
|
|
|
|
|
? array_keys($this->bp->getMissingChildren())
|
|
|
|
|
: $this->getValue('nodes');
|
|
|
|
|
|
2024-04-22 04:51:06 -04:00
|
|
|
$nodeName = null;
|
2022-09-27 09:53:51 -04:00
|
|
|
foreach ($nodesToCleanup as $nodeName) {
|
|
|
|
|
$node = $this->bp->getNode($nodeName);
|
|
|
|
|
$changes->deleteNode($node);
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-22 04:51:06 -04:00
|
|
|
|
|
|
|
|
$count = count($nodesToCleanup);
|
|
|
|
|
$this->setSuccessMessage(sprintf(
|
|
|
|
|
$this->translatePlural(
|
|
|
|
|
'Successfully removed missing node %s',
|
|
|
|
|
'Successfully removed %d missing nodes',
|
|
|
|
|
$count
|
|
|
|
|
),
|
|
|
|
|
$count === 1 ? $nodeName : $count
|
|
|
|
|
));
|
|
|
|
|
|
2022-09-27 09:53:51 -04:00
|
|
|
unset($changes);
|
|
|
|
|
|
|
|
|
|
parent::onSuccess();
|
|
|
|
|
}
|
|
|
|
|
}
|