ServiceSetHosts, ImportrunTable: move and refactor
This commit is contained in:
parent
a4abe398ac
commit
531b54391a
|
@ -1,71 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Icinga\Module\Director\Tables;
|
||||
|
||||
use Icinga\Module\Director\Objects\IcingaServiceSet;
|
||||
use Icinga\Module\Director\Web\Table\QuickTable;
|
||||
|
||||
class IcingaServiceSetHostTable extends QuickTable
|
||||
{
|
||||
protected $set;
|
||||
|
||||
protected $searchColumns = array(
|
||||
'host',
|
||||
);
|
||||
|
||||
public function getColumns()
|
||||
{
|
||||
return array(
|
||||
'id' => 'h.id',
|
||||
'host' => 'h.object_name',
|
||||
'object_type' => 'h.object_type',
|
||||
);
|
||||
}
|
||||
|
||||
public function setServiceSet(IcingaServiceSet $set)
|
||||
{
|
||||
$this->set = $set;
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function getActionUrl($row)
|
||||
{
|
||||
$params = array(
|
||||
'name' => $row->host
|
||||
);
|
||||
|
||||
return $this->url('director/host', $params);
|
||||
}
|
||||
|
||||
public function getTitles()
|
||||
{
|
||||
$view = $this->view();
|
||||
return array(
|
||||
'host' => $view->translate('Hostname'),
|
||||
);
|
||||
}
|
||||
|
||||
public function getUnfilteredQuery()
|
||||
{
|
||||
return $this->db()->select()->from(
|
||||
array('h' => 'icinga_host'),
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('ssh' => 'icinga_service_set'),
|
||||
'ssh.host_id = h.id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('ssih' => 'icinga_service_set_inheritance'),
|
||||
'ssih.service_set_id = ssh.id',
|
||||
array()
|
||||
)->order('h.object_name');
|
||||
}
|
||||
|
||||
public function getBaseQuery()
|
||||
{
|
||||
return $this->getUnfilteredQuery()->where(
|
||||
'ssih.parent_service_set_id = ?',
|
||||
$this->set->id
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Icinga\Module\Director\Tables;
|
||||
|
||||
use Icinga\Module\Director\Web\Table\QuickTable;
|
||||
|
||||
class ImportrunTable extends QuickTable
|
||||
{
|
||||
protected $searchColumns = array(
|
||||
'source_name',
|
||||
);
|
||||
|
||||
public function getColumns()
|
||||
{
|
||||
$columns = array(
|
||||
'id' => 'r.id',
|
||||
'source_id' => 's.id',
|
||||
'source_name' => 's.source_name',
|
||||
'start_time' => 'r.start_time',
|
||||
'rowset' => 'LOWER(HEX(rs.checksum))',
|
||||
'cnt_rows' => 'COUNT(rsr.row_checksum)',
|
||||
);
|
||||
|
||||
if ($this->connection->isPgsql()) {
|
||||
$columns['rowset'] = "LOWER(ENCODE(rs.checksum, 'hex'))";
|
||||
}
|
||||
|
||||
return $columns;
|
||||
}
|
||||
|
||||
protected function getActionUrl($row)
|
||||
{
|
||||
return $this->url('director/importrun', array('id' => $row->id));
|
||||
}
|
||||
|
||||
public function getTitles()
|
||||
{
|
||||
$view = $this->view();
|
||||
return array(
|
||||
'source_name' => $view->translate('Source name'),
|
||||
'start_time' => $view->translate('Timestamp'),
|
||||
'cnt_rows' => $view->translate('Imported rows'),
|
||||
);
|
||||
}
|
||||
|
||||
public function count()
|
||||
{
|
||||
$db = $this->db();
|
||||
return $db->fetchOne(
|
||||
$db->select()->from(
|
||||
array('sub' => $this->getBaseQuery()->columns($this->getColumns())),
|
||||
'COUNT(*)'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function getBaseQuery()
|
||||
{
|
||||
// TODO: Store row count to rowset
|
||||
return $this->db()->select()->from(
|
||||
array('s' => 'import_source'),
|
||||
array()
|
||||
)->join(
|
||||
array('r' => 'import_run'),
|
||||
'r.source_id = s.id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('rs' => 'imported_rowset'),
|
||||
'rs.checksum = r.rowset_checksum',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('rsr' => 'imported_rowset_row'),
|
||||
'rs.checksum = rsr.rowset_checksum',
|
||||
array()
|
||||
)->group('r.id')->group('s.id')->group('rs.checksum')
|
||||
->order('r.start_time DESC');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
namespace Icinga\Module\Director\Web\Table;
|
||||
|
||||
use Icinga\Module\Director\Objects\IcingaServiceSet;
|
||||
use ipl\Html\Link;
|
||||
use ipl\Web\Table\ZfQueryBasedTable;
|
||||
|
||||
class IcingaServiceSetHostTable extends ZfQueryBasedTable
|
||||
{
|
||||
protected $set;
|
||||
|
||||
protected $searchColumns = array(
|
||||
'host',
|
||||
);
|
||||
|
||||
public static function load(IcingaServiceSet $set)
|
||||
{
|
||||
$table = new static($set->getConnection());
|
||||
$table->set = $set;
|
||||
return $table;
|
||||
}
|
||||
|
||||
public function renderRow($row)
|
||||
{
|
||||
return $this::row([
|
||||
Link::create(
|
||||
$row->host,
|
||||
'director/host',
|
||||
['name' => $row->host]
|
||||
)
|
||||
]);
|
||||
}
|
||||
|
||||
public function getColumnsToBeRendered()
|
||||
{
|
||||
return [
|
||||
$this->translate('Hostname'),
|
||||
];
|
||||
}
|
||||
|
||||
public function prepareQuery()
|
||||
{
|
||||
return $this->db()->select()->from(
|
||||
['h' => 'icinga_host'],
|
||||
[
|
||||
'id' => 'h.id',
|
||||
'host' => 'h.object_name',
|
||||
'object_type' => 'h.object_type',
|
||||
]
|
||||
)->joinLeft(
|
||||
['ssh' => 'icinga_service_set'],
|
||||
'ssh.host_id = h.id',
|
||||
[]
|
||||
)->joinLeft(
|
||||
['ssih' => 'icinga_service_set_inheritance'],
|
||||
'ssih.service_set_id = ssh.id',
|
||||
[]
|
||||
)->where(
|
||||
'ssih.parent_service_set_id = ?',
|
||||
$this->set->id
|
||||
)->order('h.object_name');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
<?php
|
||||
|
||||
namespace Icinga\Module\Director\Web\Table;
|
||||
|
||||
use Icinga\Module\Director\Objects\ImportSource;
|
||||
use ipl\Html\Link;
|
||||
use ipl\Web\Table\ZfQueryBasedTable;
|
||||
|
||||
class ImportrunTable extends ZfQueryBasedTable
|
||||
{
|
||||
use DbHelper;
|
||||
|
||||
/** @var ImportSource */
|
||||
protected $source;
|
||||
|
||||
protected $searchColumns = [
|
||||
'source_name',
|
||||
];
|
||||
|
||||
public static function load(ImportSource $source)
|
||||
{
|
||||
$table = new static($source->getConnection());
|
||||
$table->source = $source;
|
||||
return $table;
|
||||
}
|
||||
|
||||
public function getColumnsToBeRendered()
|
||||
{
|
||||
return [
|
||||
$this->translate('Source name'),
|
||||
$this->translate('Timestamp'),
|
||||
$this->translate('Imported rows'),
|
||||
];
|
||||
}
|
||||
|
||||
public function renderRow($row)
|
||||
{
|
||||
return $this::row([
|
||||
Link::create(
|
||||
$row->source_name,
|
||||
'director/importrun',
|
||||
['id' => $row->id]
|
||||
),
|
||||
$row->start_time,
|
||||
$row->cnt_rows
|
||||
]);
|
||||
}
|
||||
|
||||
public function prepareQuery()
|
||||
{
|
||||
$db = $this->db();
|
||||
$columns = array(
|
||||
'id' => 'r.id',
|
||||
'source_id' => 's.id',
|
||||
'source_name' => 's.source_name',
|
||||
'start_time' => 'r.start_time',
|
||||
'rowset' => 'LOWER(HEX(rs.checksum))',
|
||||
'cnt_rows' => 'COUNT(rsr.row_checksum)',
|
||||
);
|
||||
|
||||
if ($this->isPgsql()) {
|
||||
$columns['rowset'] = "LOWER(ENCODE(rs.checksum, 'hex'))";
|
||||
}
|
||||
|
||||
// TODO: Store row count to rowset
|
||||
$query = $db->select()->from(
|
||||
['s' => 'import_source'],
|
||||
$columns
|
||||
)->join(
|
||||
['r' => 'import_run'],
|
||||
'r.source_id = s.id',
|
||||
[]
|
||||
)->joinLeft(
|
||||
['rs' => 'imported_rowset'],
|
||||
'rs.checksum = r.rowset_checksum',
|
||||
[]
|
||||
)->joinLeft(
|
||||
['rsr' => 'imported_rowset_row'],
|
||||
'rs.checksum = rsr.rowset_checksum',
|
||||
[]
|
||||
)->group('r.id')->group('s.id')->group('rs.checksum')
|
||||
->order('r.start_time DESC');
|
||||
|
||||
if ($this->source) {
|
||||
$query->where('r.source_id = ?', $this->source->getId());
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue