Basket: load by name

This commit is contained in:
Thomas Gelf 2018-10-09 14:09:11 +02:00
parent 5c3e220d4b
commit bea52a3091
4 changed files with 24 additions and 25 deletions

View File

@ -24,15 +24,15 @@ class BasketController extends ActionController
protected function basketTabs()
{
$uuid = $this->params->get('uuid');
$name = $this->params->get('name');
return $this->tabs()->add('show', [
'label' => $this->translate('Basket'),
'url' => 'director/basket',
'urlParams' => ['uuid' => $uuid]
'urlParams' => ['name' => $name]
])->add('snapshots', [
'label' => $this->translate('Snapshots'),
'url' => 'director/basket/snapshots',
'urlParams' => ['uuid' => $uuid]
'urlParams' => ['name' => $name]
]);
}
@ -49,8 +49,7 @@ class BasketController extends ActionController
['class' => 'icon-left-big']
)
);
$uuid = hex2bin($this->params->get('uuid'));
$basket = Basket::load($uuid, $this->db());
$basket = $this->requireBasket();
$this->basketTabs()->activate('show');
$this->addTitle($basket->get('basket_name'));
if ($basket->isEmpty()) {
@ -86,12 +85,11 @@ class BasketController extends ActionController
*/
public function snapshotsAction()
{
$uuid = $this->params->get('uuid');
if ($uuid === null || $uuid === '') {
$name = $this->params->get('name');
if ($name === null || $name === '') {
$basket = null;
} else {
$uuid = hex2bin($uuid);
$basket = Basket::load($uuid, $this->db());
$basket = Basket::load($name, $this->db());
}
if ($basket === null) {
$this->addTitle($this->translate('Basket Snapshots'));
@ -124,11 +122,9 @@ class BasketController extends ActionController
*/
public function snapshotAction()
{
$hexUuid = $this->params->getRequired('uuid');
$binUuid = hex2bin($hexUuid);
$basket = Basket::load($binUuid, $this->db());
$basket = $this->requireBasket();
$snapshot = BasketSnapshot::load([
'basket_uuid' => $binUuid,
'basket_uuid' => $basket->get('uuid'),
'ts_create' => $this->params->getRequired('ts'),
], $this->db());
$snapSum = bin2hex($snapshot->get('content_checksum'));
@ -143,7 +139,7 @@ class BasketController extends ActionController
Link::create(
$this->translate('Show Basket'),
'director/basket',
['uuid' => $hexUuid],
['name' => $basket->get('basket_name')],
['data-base-target' => '_next']
),
Link::create(
@ -186,7 +182,7 @@ class BasketController extends ActionController
$table->setAttribute('data-base-target', '_next');
foreach ($objects as $key => $object) {
$linkParams = [
'uuid' => $hexUuid,
'name' => $basket->get('basket_name'),
'checksum' => $this->params->get('checksum'),
'ts' => $this->params->get('ts'),
'type' => $type,
@ -238,10 +234,9 @@ class BasketController extends ActionController
*/
public function snapshotobjectAction()
{
$hexUuid = $this->params->getRequired('uuid');
$binUuid = hex2bin($hexUuid);
$basket = $this->requireBasket();
$snapshot = BasketSnapshot::load([
'basket_uuid' => $binUuid,
'basket_uuid' => $basket->get('uuid'),
'ts_create' => $this->params->getRequired('ts'),
], $this->db());
$snapshotUrl = $this->url()->without('type')->without('key')->setPath('director/basket/snapshot');
@ -256,7 +251,7 @@ class BasketController extends ActionController
$type,
$key,
Link::create(
substr($hexUuid, 0, 7),
substr(bin2hex( $snapshot->get('content_checksum')), 0, 7),
$snapshotUrl,
null,
['data-base-target' => '_next']
@ -301,4 +296,9 @@ class BasketController extends ActionController
)->setHtmlRenderer('Inline')
);
}
protected function requireBasket()
{
return Basket::load($this->params->getRequired('name'), $this->db());
}
}

View File

@ -4,6 +4,7 @@ namespace Icinga\Module\Director\DirectorObject\Automation;
use Icinga\Module\Director\Core\Json;
use Icinga\Module\Director\Data\Db\DbObject;
use Icinga\Module\Director\Db;
/**
* Class Basket
@ -28,7 +29,7 @@ class Basket extends DbObject
protected $table = 'director_basket';
protected $keyName = 'uuid';
protected $keyName = 'basket_name';
protected $chosenObjects = [];

View File

@ -31,8 +31,6 @@ class BasketSnapshotTable extends ZfQueryBasedTable
public function renderRow($row)
{
$this->splitByDay($row->ts_create_seconds);
$hexUuid = bin2hex($row->uuid);
$link = $this->linkToSnapshot($this->renderSummary($row->summary), $row);
if ($this->basket === null) {
@ -41,7 +39,7 @@ class BasketSnapshotTable extends ZfQueryBasedTable
new Link(
Html::tag('strong', $row->basket_name),
'director/basket',
['uuid' => $hexUuid]
['name' => $row->basket_name]
),
Html::tag('br'),
$link,
@ -91,7 +89,7 @@ class BasketSnapshotTable extends ZfQueryBasedTable
return new Link($caption, 'director/basket/snapshot', [
'checksum' => bin2hex($row->content_checksum),
'ts' => $row->ts_create,
'uuid' => bin2hex($row->uuid),
'name' => $row->basket_name,
]);
}

View File

@ -18,7 +18,7 @@ class BasketTable extends ZfQueryBasedTable
new Link(
$row->basket_name,
'director/basket',
['uuid' => $hexUuid]
['name' => $row->basket_name]
),
$row->cnt_snapshots
]);