From edc887969e7f00944aaeebfa5bbaac5136543d2a Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Thu, 22 Jun 2017 00:49:03 +0200 Subject: [PATCH] tables: remove obsolete code and files --- application/tables/IcingaApiUserTable.php | 42 ------ application/tables/IcingaCommandTable.php | 49 ------- .../tables/IcingaCommandTemplateTable.php | 13 -- application/tables/IcingaEndpointTable.php | 74 ---------- .../tables/IcingaHostTemplateTable.php | 95 ------------ .../IcingaNotificationTemplateTable.php | 7 - application/tables/IcingaServiceTable.php | 136 ------------------ .../tables/IcingaServiceTemplateTable.php | 7 - application/tables/IcingaTimePeriodTable.php | 43 ------ application/tables/IcingaUserTable.php | 59 -------- .../tables/IcingaUserTemplateTable.php | 13 -- application/tables/IcingaZoneTable.php | 68 --------- .../Restriction/BetaHostgroupRestriction.php | 79 ---------- .../Director/Web/Table/IcingaObjectTable.php | 27 ---- .../Web/Table/ServiceTemplatesTable.php | 111 -------------- .../Web/Table/ServicesOnHostsTable.php | 108 -------------- 16 files changed, 931 deletions(-) delete mode 100644 application/tables/IcingaApiUserTable.php delete mode 100644 application/tables/IcingaCommandTable.php delete mode 100644 application/tables/IcingaCommandTemplateTable.php delete mode 100644 application/tables/IcingaEndpointTable.php delete mode 100644 application/tables/IcingaHostTemplateTable.php delete mode 100644 application/tables/IcingaNotificationTemplateTable.php delete mode 100644 application/tables/IcingaServiceTable.php delete mode 100644 application/tables/IcingaServiceTemplateTable.php delete mode 100644 application/tables/IcingaTimePeriodTable.php delete mode 100644 application/tables/IcingaUserTable.php delete mode 100644 application/tables/IcingaUserTemplateTable.php delete mode 100644 application/tables/IcingaZoneTable.php delete mode 100644 library/Director/Restriction/BetaHostgroupRestriction.php delete mode 100644 library/Director/Web/Table/IcingaObjectTable.php delete mode 100644 library/Director/Web/Table/ServiceTemplatesTable.php delete mode 100644 library/Director/Web/Table/ServicesOnHostsTable.php diff --git a/application/tables/IcingaApiUserTable.php b/application/tables/IcingaApiUserTable.php deleted file mode 100644 index 2f6e4f99..00000000 --- a/application/tables/IcingaApiUserTable.php +++ /dev/null @@ -1,42 +0,0 @@ - '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() - ); - } -} diff --git a/application/tables/IcingaCommandTable.php b/application/tables/IcingaCommandTable.php deleted file mode 100644 index 313ea823..00000000 --- a/application/tables/IcingaCommandTable.php +++ /dev/null @@ -1,49 +0,0 @@ - '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(); - } -} diff --git a/application/tables/IcingaCommandTemplateTable.php b/application/tables/IcingaCommandTemplateTable.php deleted file mode 100644 index b94814f8..00000000 --- a/application/tables/IcingaCommandTemplateTable.php +++ /dev/null @@ -1,13 +0,0 @@ -getUnfilteredQuery()->where('c.object_type = ?', 'template'); - } -} diff --git a/application/tables/IcingaEndpointTable.php b/application/tables/IcingaEndpointTable.php deleted file mode 100644 index 2bd7cc54..00000000 --- a/application/tables/IcingaEndpointTable.php +++ /dev/null @@ -1,74 +0,0 @@ - '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() - ); - } -} diff --git a/application/tables/IcingaHostTemplateTable.php b/application/tables/IcingaHostTemplateTable.php deleted file mode 100644 index 3c3d3bdf..00000000 --- a/application/tables/IcingaHostTemplateTable.php +++ /dev/null @@ -1,95 +0,0 @@ -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'); - } -} diff --git a/application/tables/IcingaNotificationTemplateTable.php b/application/tables/IcingaNotificationTemplateTable.php deleted file mode 100644 index ec32fb0c..00000000 --- a/application/tables/IcingaNotificationTemplateTable.php +++ /dev/null @@ -1,7 +0,0 @@ - '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 = " getRowClassesString($row) . ">\n"; - $htm .= '' . $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: '; - foreach ($extra as $service) { - $href = $v->url('director/service', array('id' => $service->id)); - $htm .= ""; - - 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 .= "'; - $htm .= ''; - $htm .= ''; - } - $htm .= '
" . $service->object_name . '' . $prettyFilter . '
'; - $htm .= $v->qlink( - 'Add more', - 'director/service/add', - array('apply' => $row->service), - array('class' => 'icon-plus') - ); - } - $htm .= ''; - return $htm . " \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'); - } -} diff --git a/application/tables/IcingaServiceTemplateTable.php b/application/tables/IcingaServiceTemplateTable.php deleted file mode 100644 index 2cc38d4d..00000000 --- a/application/tables/IcingaServiceTemplateTable.php +++ /dev/null @@ -1,7 +0,0 @@ - '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() - ); - } -} diff --git a/application/tables/IcingaUserTable.php b/application/tables/IcingaUserTable.php deleted file mode 100644 index 38cdd04f..00000000 --- a/application/tables/IcingaUserTable.php +++ /dev/null @@ -1,59 +0,0 @@ - '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(); - } -} diff --git a/application/tables/IcingaUserTemplateTable.php b/application/tables/IcingaUserTemplateTable.php deleted file mode 100644 index 85c5ed9d..00000000 --- a/application/tables/IcingaUserTemplateTable.php +++ /dev/null @@ -1,13 +0,0 @@ -getUnfilteredQuery()->where('u.object_type = ?', 'template'); - } -} diff --git a/application/tables/IcingaZoneTable.php b/application/tables/IcingaZoneTable.php deleted file mode 100644 index 0a44b122..00000000 --- a/application/tables/IcingaZoneTable.php +++ /dev/null @@ -1,68 +0,0 @@ -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'); - } -} diff --git a/library/Director/Restriction/BetaHostgroupRestriction.php b/library/Director/Restriction/BetaHostgroupRestriction.php deleted file mode 100644 index d1108b88..00000000 --- a/library/Director/Restriction/BetaHostgroupRestriction.php +++ /dev/null @@ -1,79 +0,0 @@ -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; - } - } -} diff --git a/library/Director/Web/Table/IcingaObjectTable.php b/library/Director/Web/Table/IcingaObjectTable.php deleted file mode 100644 index 989d10dc..00000000 --- a/library/Director/Web/Table/IcingaObjectTable.php +++ /dev/null @@ -1,27 +0,0 @@ -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()); - } -} diff --git a/library/Director/Web/Table/ServiceTemplatesTable.php b/library/Director/Web/Table/ServiceTemplatesTable.php deleted file mode 100644 index 5d1a7657..00000000 --- a/library/Director/Web/Table/ServiceTemplatesTable.php +++ /dev/null @@ -1,111 +0,0 @@ - ['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; - } -} diff --git a/library/Director/Web/Table/ServicesOnHostsTable.php b/library/Director/Web/Table/ServicesOnHostsTable.php deleted file mode 100644 index 60f415d8..00000000 --- a/library/Director/Web/Table/ServicesOnHostsTable.php +++ /dev/null @@ -1,108 +0,0 @@ - ['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; - } -}