2017-07-20 22:29:00 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\Web\Table;
|
|
|
|
|
2021-10-05 23:15:39 +02:00
|
|
|
use Icinga\Data\DataArray\ArrayDatasource;
|
|
|
|
use Icinga\Module\Director\Data\Json;
|
|
|
|
use Icinga\Module\Director\Db;
|
|
|
|
use Icinga\Module\Director\Db\Branch\Branch;
|
|
|
|
use Icinga\Module\Director\Db\Branch\BranchModificationStore;
|
2017-07-20 22:29:00 +02:00
|
|
|
use Icinga\Module\Director\Objects\IcingaCommand;
|
2019-05-02 13:23:06 +02:00
|
|
|
use gipfl\IcingaWeb2\Link;
|
|
|
|
use gipfl\IcingaWeb2\Table\ZfQueryBasedTable;
|
2017-07-20 22:29:00 +02:00
|
|
|
|
|
|
|
class IcingaCommandArgumentTable extends ZfQueryBasedTable
|
|
|
|
{
|
|
|
|
/** @var IcingaCommand */
|
|
|
|
protected $command;
|
|
|
|
|
2021-10-05 23:15:39 +02:00
|
|
|
/** @var Branch */
|
|
|
|
protected $branch;
|
|
|
|
|
|
|
|
protected $searchColumns = [
|
2017-07-21 08:23:52 +02:00
|
|
|
'ca.argument_name',
|
|
|
|
'ca.argument_value',
|
2021-10-05 23:15:39 +02:00
|
|
|
];
|
2017-07-20 22:29:00 +02:00
|
|
|
|
2021-10-05 23:15:39 +02:00
|
|
|
public function __construct(IcingaCommand $command, Branch $branch)
|
2017-07-20 22:29:00 +02:00
|
|
|
{
|
2021-10-05 23:15:39 +02:00
|
|
|
$this->command = $command;
|
|
|
|
$this->branch = $branch;
|
|
|
|
parent::__construct($command->getConnection());
|
2018-05-05 00:24:49 +02:00
|
|
|
$this->getAttributes()->set('data-base-target', '_self');
|
2017-07-20 22:29:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function renderRow($row)
|
|
|
|
{
|
|
|
|
return $this::row([
|
2017-07-21 12:07:28 +02:00
|
|
|
Link::create($row->argument_name, 'director/command/arguments', [
|
2021-10-05 23:15:39 +02:00
|
|
|
'argument' => $row->argument_name,
|
|
|
|
'name' => $this->command->getObjectName()
|
2017-07-21 12:07:28 +02:00
|
|
|
]),
|
2017-07-20 22:29:00 +02:00
|
|
|
$row->argument_value
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getColumnsToBeRendered()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
$this->translate('Argument'),
|
|
|
|
$this->translate('Value'),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function prepareQuery()
|
|
|
|
{
|
2021-10-05 23:15:39 +02:00
|
|
|
$db = $this->db();
|
|
|
|
if ($this->branch->isBranch()) {
|
|
|
|
return (new ArrayDatasource((array) $this->command->arguments()->toPlainObject()))->select();
|
|
|
|
/** @var Db $connection */
|
|
|
|
$connection = $this->connection();
|
|
|
|
$store = new BranchModificationStore($connection, 'command');
|
|
|
|
$modification = $store->loadOptionalModificationByName(
|
|
|
|
$this->command->getObjectName(),
|
|
|
|
$this->branch->getUuid()
|
|
|
|
);
|
|
|
|
if ($modification) {
|
|
|
|
$props = $modification->getProperties()->jsonSerialize();
|
|
|
|
if (isset($props->arguments)) {
|
|
|
|
return new ArrayDatasource((array) $this->command->arguments()->toPlainObject());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$id = $this->command->get('id');
|
|
|
|
if ($id === null) {
|
|
|
|
return new ArrayDatasource([]);
|
|
|
|
}
|
2017-07-20 22:29:00 +02:00
|
|
|
return $this->db()->select()->from(
|
|
|
|
['ca' => 'icinga_command_argument'],
|
2017-07-21 12:07:28 +02:00
|
|
|
[
|
|
|
|
'id' => 'ca.id',
|
|
|
|
'argument_name' => "COALESCE(ca.argument_name, '(none)')",
|
|
|
|
'argument_value' => 'ca.argument_value',
|
|
|
|
]
|
2017-07-20 22:29:00 +02:00
|
|
|
)->where(
|
|
|
|
'ca.command_id = ?',
|
2021-10-05 23:15:39 +02:00
|
|
|
$id
|
2017-07-21 08:23:52 +02:00
|
|
|
)->order('ca.sort_order')->order('ca.argument_name')->limit(100);
|
2017-07-20 22:29:00 +02:00
|
|
|
}
|
|
|
|
}
|