IcingaCommandArgumentTable: branch-specific fixes
This commit is contained in:
parent
83617b22e8
commit
fe97970dc3
|
@ -2,6 +2,11 @@
|
||||||
|
|
||||||
namespace Icinga\Module\Director\Web\Table;
|
namespace Icinga\Module\Director\Web\Table;
|
||||||
|
|
||||||
|
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;
|
||||||
use Icinga\Module\Director\Objects\IcingaCommand;
|
use Icinga\Module\Director\Objects\IcingaCommand;
|
||||||
use gipfl\IcingaWeb2\Link;
|
use gipfl\IcingaWeb2\Link;
|
||||||
use gipfl\IcingaWeb2\Table\ZfQueryBasedTable;
|
use gipfl\IcingaWeb2\Table\ZfQueryBasedTable;
|
||||||
|
@ -11,20 +16,19 @@ class IcingaCommandArgumentTable extends ZfQueryBasedTable
|
||||||
/** @var IcingaCommand */
|
/** @var IcingaCommand */
|
||||||
protected $command;
|
protected $command;
|
||||||
|
|
||||||
protected $searchColumns = array(
|
/** @var Branch */
|
||||||
|
protected $branch;
|
||||||
|
|
||||||
|
protected $searchColumns = [
|
||||||
'ca.argument_name',
|
'ca.argument_name',
|
||||||
'ca.argument_value',
|
'ca.argument_value',
|
||||||
);
|
];
|
||||||
|
|
||||||
public static function create(IcingaCommand $command)
|
public function __construct(IcingaCommand $command, Branch $branch)
|
||||||
{
|
|
||||||
$self = new static($command->getConnection());
|
|
||||||
$self->command = $command;
|
|
||||||
return $self;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function assemble()
|
|
||||||
{
|
{
|
||||||
|
$this->command = $command;
|
||||||
|
$this->branch = $branch;
|
||||||
|
parent::__construct($command->getConnection());
|
||||||
$this->getAttributes()->set('data-base-target', '_self');
|
$this->getAttributes()->set('data-base-target', '_self');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +36,7 @@ class IcingaCommandArgumentTable extends ZfQueryBasedTable
|
||||||
{
|
{
|
||||||
return $this::row([
|
return $this::row([
|
||||||
Link::create($row->argument_name, 'director/command/arguments', [
|
Link::create($row->argument_name, 'director/command/arguments', [
|
||||||
'argument_id' => $row->id,
|
'argument' => $row->argument_name,
|
||||||
'name' => $this->command->getObjectName()
|
'name' => $this->command->getObjectName()
|
||||||
]),
|
]),
|
||||||
$row->argument_value
|
$row->argument_value
|
||||||
|
@ -49,6 +53,27 @@ class IcingaCommandArgumentTable extends ZfQueryBasedTable
|
||||||
|
|
||||||
public function prepareQuery()
|
public function prepareQuery()
|
||||||
{
|
{
|
||||||
|
$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([]);
|
||||||
|
}
|
||||||
return $this->db()->select()->from(
|
return $this->db()->select()->from(
|
||||||
['ca' => 'icinga_command_argument'],
|
['ca' => 'icinga_command_argument'],
|
||||||
[
|
[
|
||||||
|
@ -58,7 +83,7 @@ class IcingaCommandArgumentTable extends ZfQueryBasedTable
|
||||||
]
|
]
|
||||||
)->where(
|
)->where(
|
||||||
'ca.command_id = ?',
|
'ca.command_id = ?',
|
||||||
$this->command->get('id')
|
$id
|
||||||
)->order('ca.sort_order')->order('ca.argument_name')->limit(100);
|
)->order('ca.sort_order')->order('ca.argument_name')->limit(100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue