tables: remove obsolete code and files

This commit is contained in:
Thomas Gelf 2017-06-22 00:49:03 +02:00
parent 6597cd2027
commit edc887969e
16 changed files with 0 additions and 931 deletions

View File

@ -1,42 +0,0 @@
<?php
namespace Icinga\Module\Director\Tables;
use Icinga\Module\Director\Web\Table\IcingaObjectTable;
class IcingaApiUserTable extends IcingaObjectTable
{
protected $searchColumns = array(
'object_name',
);
public function getColumns()
{
return array(
'id' => 'o.id',
'object_name' => 'o.object_name',
'object_type' => 'o.object_type',
);
}
protected function getActionUrl($row)
{
return $this->url('director/apiuser', array('name' => $row->object_name));
}
public function getTitles()
{
$view = $this->view();
return array(
'object_name' => $view->translate('User'),
);
}
public function getBaseQuery()
{
return $this->db()->select()->from(
array('o' => 'icinga_apiuser'),
array()
);
}
}

View File

@ -1,49 +0,0 @@
<?php
namespace Icinga\Module\Director\Tables;
use Icinga\Module\Director\Web\Table\IcingaObjectTable;
class IcingaCommandTable extends IcingaObjectTable
{
protected $searchColumns = array(
'command',
);
public function getColumns()
{
return array(
'id' => 'c.id',
'command' => 'c.object_name',
'object_type' => 'c.object_type',
'command_line' => 'c.command',
);
}
protected function getActionUrl($row)
{
return $this->url('director/command', array('name' => $row->command));
}
public function getTitles()
{
$view = $this->view();
return array(
'command' => $view->translate('Command'),
'command_line' => $view->translate('Command line'),
);
}
protected function getUnfilteredQuery()
{
return $this->db()->select()->from(
array('c' => 'icinga_command'),
array()
)->order('c.object_name');
}
public function getBaseQuery()
{
return $this->getUnfilteredQuery();
}
}

View File

@ -1,13 +0,0 @@
<?php
namespace Icinga\Module\Director\Tables;
use Icinga\Module\Director\Tables\IcingaCommandTable;
class IcingaCommandTemplateTable extends IcingaCommandTable
{
public function getBaseQuery()
{
return $this->getUnfilteredQuery()->where('c.object_type = ?', 'template');
}
}

View File

@ -1,74 +0,0 @@
<?php
namespace Icinga\Module\Director\Tables;
use Icinga\Module\Director\Web\Table\IcingaObjectTable;
class IcingaEndpointTable extends IcingaObjectTable
{
protected $searchColumns = array(
'endpoint',
);
protected $deploymentEndpoint;
public function getColumns()
{
return array(
'id' => 'e.id',
'endpoint' => 'e.object_name',
'object_type' => 'e.object_type',
'host' => "(CASE WHEN e.host IS NULL THEN NULL ELSE"
. " CONCAT(e.host || ':' || COALESCE(e.port, 5665)) END)",
'zone' => 'z.object_name',
);
}
protected function listTableClasses()
{
return array_merge(array('endpoints'), parent::listTableClasses());
}
protected function getRowClasses($row)
{
if ($row->endpoint === $this->deploymentEndpoint) {
return array('deployment-endpoint', parent::getRowClasses($row));
}
return parent::getRowClasses($row);
}
protected function getActionUrl($row)
{
return $this->url('director/endpoint', array('name' => $row->endpoint));
}
public function getTitles()
{
$view = $this->view();
return array(
'endpoint' => $view->translate('Endpoint'),
'host' => $view->translate('Host'),
'zone' => $view->translate('Zone'),
);
}
public function getBaseQuery()
{
if ($this->deploymentEndpoint === null) {
$c = $this->connection();
if ($c->hasDeploymentEndpoint()) {
$this->deploymentEndpoint = $c->getDeploymentEndpointName();
}
}
return $this->db()->select()->from(
array('e' => 'icinga_endpoint'),
array()
)->joinLeft(
array('z' => 'icinga_zone'),
'e.zone_id = z.id',
array()
);
}
}

View File

@ -1,95 +0,0 @@
<?php
namespace Icinga\Module\Director\Tables;
use Icinga\Module\Director\Tables\IcingaHostTable;
class IcingaHostTemplateTable extends IcingaHostTable
{
protected $searchColumns = array(
'host',
'display_name'
);
public function getTitles()
{
$view = $this->view();
return array(
'host' => $view->translate('Template name'),
);
}
protected function renderAdditionalActions($row)
{
$htm = '';
$view = $this->view();
if ($row->object_type === 'template') {
$htm .= $view->qlink(
'',
'director/host/add?type=object',
array('imports' => $row->host),
array(
'class' => 'icon-plus',
'title' => $view->translate(
'Create a new host based on this template'
)
)
);
/*
// TODO: Not yet
if ($cnt = $row->cnt_child_templates) {
if ((int) $cnt === 1) {
$title = $view->translate('Show one host template using this template');
} else {
$title = sprintf(
$view->translate('Show %d host templates using this template'),
$cnt
);
}
$htm .= $view->qlink(
'',
'director/hosts/bytemplate',
array('name' => $row->host),
array(
'class' => 'icon-sitemap',
'title' => $title
)
);
}
if ($cnt = $row->cnt_child_hosts) {
if ((int) $cnt === 1) {
$title = $view->translate('Show one host using this template');
} else {
$title = sprintf(
$view->translate('Show %d hosts using this template'),
$cnt
);
}
$htm .= $view->qlink(
'',
'director/hosts/bytemplate',
array('name' => $row->host),
array(
'class' => 'icon-host',
'title' => $title
)
);
}
*/
}
return $htm;
}
public function getBaseQuery()
{
return $this->getUnfilteredQuery()->where('h.object_type = ?', 'template');
}
}

View File

@ -1,7 +0,0 @@
<?php
namespace Icinga\Module\Director\Tables;
class IcingaNotificationTemplateTable extends IcingaNotificationTable
{
}

View File

@ -1,136 +0,0 @@
<?php
namespace Icinga\Module\Director\Tables;
use Icinga\Data\Filter\Filter;
use Icinga\Exception\IcingaException;
use Icinga\Module\Director\IcingaConfig\AssignRenderer;
use Icinga\Module\Director\Web\Table\QuickTable;
class IcingaServiceTable extends QuickTable
{
protected $searchColumns = array(
'service',
);
public function getColumns()
{
return array(
'id' => 's.id',
'service' => 's.object_name',
'object_type' => 's.object_type',
'check_command_id' => 's.check_command_id',
);
}
protected function listTableClasses()
{
return array_merge(array('assignment-table'), parent::listTableClasses());
}
protected function getActionUrl($row)
{
// TODO: Remove once we got a separate apply table
if ($row->object_type === 'apply') {
$params['id'] = $row->id;
} else {
$params = array('name' => $row->service);
}
return $this->url('director/service', $params);
}
protected function renderRow($row)
{
$v = $this->view();
$extra = $this->appliedOnes($row->id);
$htm = " <tr" . $this->getRowClassesString($row) . ">\n";
$htm .= '<td>' . $v->qlink($row->service, $this->getActionUrl($row));
if (empty($extra)) {
if ($row->check_command_id) {
$htm .= ' ' . $v->qlink(
'Create apply-rule',
'director/service/add',
array('apply' => $row->service),
array('class' => 'icon-plus')
);
}
} else {
$htm .= '. Related apply rules: <table class="apply-rules">';
foreach ($extra as $service) {
$href = $v->url('director/service', array('id' => $service->id));
$htm .= "<tr href=\"$href\">";
try {
$prettyFilter = AssignRenderer::forFilter(
Filter::fromQueryString($service->assign_filter)
)->renderAssign();
} catch (IcingaException $e) {
// ignore errors in filter rendering
$prettyFilter = 'Error in Filter rendering: ' . $e->getMessage();
}
$htm .= "<td><a href=\"$href\">" . $service->object_name . '</a></td>';
$htm .= '<td>' . $prettyFilter . '</td>';
$htm .= '<tr>';
}
$htm .= '</table>';
$htm .= $v->qlink(
'Add more',
'director/service/add',
array('apply' => $row->service),
array('class' => 'icon-plus')
);
}
$htm .= '</td>';
return $htm . " </tr>\n";
}
public function getTitles()
{
$view = $this->view();
return array(
'service' => $view->translate('Servicename'),
);
}
public function getUnfilteredQuery()
{
$query = $this->db()->select()->from(
array('s' => 'icinga_service'),
array()
);
return $query;
}
protected function appliedOnes($id)
{
$db = $this->db();
$query = $db->select()->from(
array('s' => 'icinga_service'),
array(
'id' => 's.id',
'object_name' => 's.object_name',
'assign_filter' => 's.assign_filter',
)
)->join(
array('i' => 'icinga_service_inheritance'),
'i.service_id = s.id',
array()
)->where('i.parent_service_id = ?', $id)
->where('s.object_type = ?', 'apply')
->where('s.service_set_id IS NULL');
return $db->fetchAll($query);
}
public function getBaseQuery()
{
return $this->getUnfilteredQuery()->where(
's.object_type IN (?)',
array('template')
)->order('CASE WHEN s.check_command_id IS NULL THEN 1 ELSE 0 END')
->order('s.object_name');
}
}

View File

@ -1,7 +0,0 @@
<?php
namespace Icinga\Module\Director\Tables;
class IcingaServiceTemplateTable extends IcingaServiceTable
{
}

View File

@ -1,43 +0,0 @@
<?php
namespace Icinga\Module\Director\Tables;
use Icinga\Module\Director\Web\Table\QuickTable;
class IcingaTimePeriodTable extends QuickTable
{
protected $searchColumns = array(
'timeperiod',
);
public function getColumns()
{
return array(
'id' => 't.id',
'timeperiod' => 't.object_name',
'display_name' => 't.display_name',
);
}
protected function getActionUrl($row)
{
return $this->url('director/timeperiod', array('name' => $row->timeperiod));
}
public function getTitles()
{
$view = $this->view();
return array(
'timeperiod' => $view->translate('Timeperiod'),
'display_name' => $view->translate('Display Name'),
);
}
public function getBaseQuery()
{
return $this->db()->select()->from(
array('t' => 'icinga_timeperiod'),
array()
);
}
}

View File

@ -1,59 +0,0 @@
<?php
namespace Icinga\Module\Director\Tables;
use Icinga\Module\Director\Web\Table\IcingaObjectTable;
class IcingaUserTable extends IcingaObjectTable
{
protected $searchColumns = array(
'user',
'display_name'
);
public function getColumns()
{
return array(
'id' => 'u.id',
'object_type' => 'u.object_type',
'user' => 'u.object_name',
'display_name' => 'u.display_name',
'email' => 'u.email',
'pager' => 'u.pager',
// 'enable_notifications' => 'u.enable_notifications',
// 'period' => ''
'zone' => 'z.object_name',
);
}
protected function getActionUrl($row)
{
return $this->url('director/user', array('name' => $row->user));
}
public function getTitles()
{
$view = $this->view();
return array(
'user' => $view->translate('Username'),
'email' => $view->translate('Email'),
);
}
public function getUnfilteredQuery()
{
return $this->db()->select()->from(
array('u' => 'icinga_user'),
array()
)->joinLeft(
array('z' => 'icinga_zone'),
'u.zone_id = z.id',
array()
);
}
public function getBaseQuery()
{
return $this->getUnfilteredQuery();
}
}

View File

@ -1,13 +0,0 @@
<?php
namespace Icinga\Module\Director\Tables;
use Icinga\Module\Director\Tables\IcingaUserTable;
class IcingaUserTemplateTable extends IcingaUserTable
{
public function getBaseQuery()
{
return $this->getUnfilteredQuery()->where('u.object_type = ?', 'template');
}
}

View File

@ -1,68 +0,0 @@
<?php
namespace Icinga\Module\Director\Tables;
use Icinga\Module\Director\Web\Table\IcingaObjectTable;
class IcingaZoneTable extends IcingaObjectTable
{
protected $searchColumns = array(
'zone',
);
public function getColumns()
{
if ($this->connection()->isPgsql()) {
$endpoints = "ARRAY_TO_STRING(ARRAY_AGG(e.object_name), ', ')";
} else {
$endpoints = "GROUP_CONCAT(e.object_name ORDER BY e.object_name SEPARATOR ', ')";
}
return array(
'id' => 'z.id',
'zone' => 'z.object_name',
'object_type' => 'z.object_type',
'endpoints' => $endpoints,
);
}
protected function getActionUrl($row)
{
return $this->url('director/zone', array('name' => $row->zone));
}
public function getTitles()
{
$view = $this->view();
return array(
'zone' => $view->translate('Zone'),
'endpoints' => $view->translate('Endpoints'),
);
}
public function count()
{
$db = $this->db();
$sub = clone($this->getBaseQuery());
$sub->columns($this->getColumns());
$this->applyFiltersToQuery($sub);
$query = $db->select()->from(
array('sub' => $sub),
'COUNT(*)'
);
return $db->fetchOne($query);
}
public function getBaseQuery()
{
return $this->db()->select()->from(
array('z' => 'icinga_zone'),
array()
)->joinLeft(
array('e' => 'icinga_endpoint'),
'z.id = e.zone_id',
array()
)->group('z.id');
}
}

View File

@ -1,79 +0,0 @@
<?php
namespace Icinga\Module\Director\Restriction;
use Icinga\Module\Director\Objects\IcingaHost;
use Zend_Db_Select as ZfSelect;
class BetaHostgroupRestriction extends ObjectRestriction
{
protected $name = 'director/beta-filter/hostgroups';
public function allowsHost(IcingaHost $host)
{
if (! $this->isRestricted()) {
return true;
}
$query = $this->db->select()->from(
array('h' => 'icinga_host'),
array('id')
)->where('id = ?', $host->id);
$this->applyToHostsQuery($query);
return (int) $this->db->fetchOne($query) === (int) $host->get('id');
}
public function applyToHostsQuery(ZfSelect $query, $hostIdColumn = 'h.id')
{
if (! $this->isRestricted()) {
return;
}
$groups = $this->listRestrictedHostgroups();
if (empty($groups)) {
$query->where('(1 = 0)');
} else {
$sub = $this->db->select()->from(
array('hgh' => 'icinga_hostgroup_host_resolved'),
array('e' => '(1)')
)->join(
array('hg' => 'icinga_hostgroup'),
'hgh.hostgroup_id = hg.id'
)->where('hgh.host_id = ' . $hostIdColumn)
->where('hg.object_name IN (?)', $groups);
$query->where('EXISTS ?', $sub);
}
}
public function applyToHostGroupsQuery(ZfSelect $query)
{
if (! $this->isRestricted()) {
return;
}
$groups = $this->listRestrictedHostgroups();
if (empty($groups)) {
$query->where('(1 = 0)');
} else {
$query->where('object_name IN (?)', $groups);
}
}
protected function listRestrictedHostgroups()
{
if ($restrictions = $this->auth->getRestrictions($this->getName())) {
$groups = array();
foreach ($restrictions as $restriction) {
foreach ($this->gracefullySplitOnComma($restriction) as $group) {
$groups[$group] = $group;
}
}
return array_keys($groups);
} else {
return null;
}
}
}

View File

@ -1,27 +0,0 @@
<?php
namespace Icinga\Module\Director\Web\Table;
abstract class IcingaObjectTable extends QuickTable
{
protected function getRowClasses($row)
{
switch ($row->object_type) {
case 'object':
return 'icinga-object';
case 'template':
return 'icinga-template';
case 'external_object':
return 'icinga-object-external';
case 'apply':
return 'icinga-apply';
}
return null;
}
protected function listTableClasses()
{
return array_merge(array('icinga-objects'), parent::listTableClasses());
}
}

View File

@ -1,111 +0,0 @@
<?php
namespace Icinga\Module\Director\Web\Table;
use Icinga\Module\Director\Db;
use ipl\Html\Icon;
use ipl\Html\Link;
use ipl\Html\Table;
use ipl\Translation\TranslationHelper;
use ipl\Web\Url;
class ServiceTemplatesTable extends Table
{
use TranslationHelper;
protected $defaultAttributes = [
'class' => ['simple', 'common-table', 'table-row-selectable'],
'data-base-target' => '_next',
];
private $db;
public function __construct(Db $connection)
{
$this->db = $connection->getDbAdapter();
$this->header();
$this->fetchRows();
}
public function getColumnsToBeRendered()
{
return ['Template name', 'Actions'];
}
public function renderRow($row)
{
$url = Url::fromPath('director/service/edit', [
'name' => $row->service,
]);
return static::tr([
Table::td(Link::create($row->service, $url)),
Table::td($this->createActionLinks($row))->setSeparator(' ')
]);
}
public function createActionLinks($row)
{
$links = [];
$links[] = Link::create(
Icon::create('sitemap'),
'director/servicetemplate/usage',
['name' => $row->service],
['title' => $this->translate('Show template usage')]
);
$links[] = Link::create(
Icon::create('edit'),
'director/service/edit',
['name' => $row->service],
['title' => $this->translate('Modify this template')]
);
$links[] = Link::create(
Icon::create('doc-text'),
'director/service/render',
['name' => $row->service],
['title' => $this->translate('Template rendering preview')]
);
$links[] = Link::create(
Icon::create('history'),
'director/service/history',
['name' => $row->service],
['title' => $this->translate('Template history')]
);
return $links;
}
protected function fetchRows()
{
$body = $this->body();
foreach ($this->fetch() as $row) {
$body->add($this->renderRow($row));
}
}
public function fetch()
{
return $this->db->fetchAll(
$this->prepareQuery()
);
}
public function prepareQuery()
{
$columns = [
'service' => 's.object_name',
'id' => 's.id',
];
$query = $this->db->select()->from(
['s' => 'icinga_service'],
$columns
)->where(
"object_type = 'template'"
)->order('s.object_name');
return $query;
}
}

View File

@ -1,108 +0,0 @@
<?php
namespace Icinga\Module\Director\Web\Table;
use Icinga\Module\Director\Db;
use ipl\Html\Link;
use ipl\Html\Table;
use ipl\Web\Url;
class ServicesOnHostsTable extends Table
{
protected $defaultAttributes = [
'class' => ['simple', 'common-table', 'table-row-selectable', 'multiselect'],
'data-base-target' => '_next',
];
private $db;
public function __construct(Db $connection)
{
$this->db = $connection->getDbAdapter();
$this->addMultiSelectAttributes();
$this->header();
$this->fetchRows();
}
public function getColumnsToBeRendered()
{
return ['Service Name', 'Host'];
}
protected function addMultiSelectAttributes()
{
$props = $this->getMultiselectProperties();
if (empty($props)) {
return $this;
}
$prefix = 'data-icinga-multiselect';
$multi = [
"$prefix-url" => Url::fromPath($props['url']),
"$prefix-controllers" => Url::fromPath($props['sourceUrl']),
"$prefix-data" => implode(',', $props['keys']),
];
$this->addAttributes($multi);
return $this;
}
protected function getMultiselectProperties()
{
return [
'url' => 'director/services/edit',
'sourceUrl' => 'director/service/edit',
// TODO: evaluate 'keys' => ['name', 'host'],
'keys' => ['id'],
];
}
protected function fetchRows()
{
$body = $this->body();
foreach ($this->fetch() as $row) {
$body->add($this->renderRow($row));
}
}
public function renderRow($row)
{
$url = Url::fromPath('director/service/edit', [
'name' => $row->service,
'host' => $row->host,
'id' => $row->id,
]);
return static::tr([
static::td(Link::create($row->host, $url)),
static::td($row->service)
]);
}
public function fetch()
{
return $this->db->fetchAll(
$this->prepareQuery()
);
}
public function prepareQuery()
{
$columns = [
'host' => 'h.object_name',
'service' => 's.object_name',
'id' => 's.id',
];
$query = $this->db->select()->from(
['s' => 'icinga_service'],
$columns
)->join(
['h' => 'icinga_host'],
"s.host_id = h.id AND h.object_type = 'object'",
[]
);
return $query;
}
}