Merge pull request #4758 from Icinga/remove-depricated-classes-and-methods
Remove deprecated classes and methods
This commit is contained in:
commit
3203cd8fea
|
@ -12,12 +12,12 @@ class Zend_View_Helper_CreateTicketLinks extends Zend_View_Helper_Abstract
|
|||
* @param string $text
|
||||
*
|
||||
* @return string
|
||||
* @see \Icinga\Web\Hook\TicketHook::createLinks()
|
||||
* @see \Icinga\Application\Hook\TicketHook::createLinks()
|
||||
*/
|
||||
public function createTicketLinks($text)
|
||||
{
|
||||
$tickets = $this->view->tickets;
|
||||
/** @var \Icinga\Web\Hook\TicketHook $tickets */
|
||||
/** @var \Icinga\Application\Hook\TicketHook $tickets */
|
||||
return isset($tickets) ? $tickets->createLinks($text) : $text;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -159,9 +159,6 @@ this, put the macro `$user.local_name$` in the restriction where you want it to
|
|||
This can come in handy if you have e.g. an attribute on hosts or services defining which user is responsible for it:
|
||||
`_host_deputy=$user.local_name$|_service_deputy=$user.local_name$`
|
||||
|
||||
> Please note that since version 2.9 the use of `user.local_name` instead of `user:local_name` is supported and
|
||||
> recommended. `user:local_name` is deprecated and will be removed in version 2.11.
|
||||
|
||||
### Filter Expressions
|
||||
|
||||
Filters operate on columns. A complete list of all available filter columns on hosts and services can be found in
|
||||
|
|
|
@ -16,6 +16,50 @@ v2.6 to v2.8 requires to follow the instructions for v2.7 too.
|
|||
In package installations this file can be found in `/usr/share/doc/icingaweb2/schema/*-upgrades/`
|
||||
(Debian/Ubuntu: `/usr/share/icingaweb2/etc/schema/*-upgrades/`).
|
||||
|
||||
**Breaking changes**
|
||||
|
||||
* The `user:local_name` macro in restrictions has been removed. Use `user.local_name` now.
|
||||
|
||||
**Framework changes affecting third-party code**
|
||||
|
||||
* All the following deprecated php classes and methods are removed:
|
||||
|
||||
**Methods:**
|
||||
+ `Url::setBaseUrl()`: Please create a new url from scratch instead.
|
||||
+ `Url::getBaseUrl()`: Use either `Url::getBasePath()` or `Url::getAbsoluteUrl()` now.
|
||||
+ `ApplicationBootstrap::setupZendAutoloader()`: Since it does nothing. All uses removed.
|
||||
+ `ApplicationBootstrap::listLocales()`: Use `\ipl\I18n\GettextTranslator::listLocales()` instead.
|
||||
+ `Module::registerHook()`: Use `provideHook()` instead.
|
||||
+ `Web::getMenu()`: Instantiate the menu class `new Menu()` directly instead.
|
||||
+ `AesCrypt::encryptToBase64()`: Use `AesCrypt::encrypt()` instead as it also returns a base64 encoded string.
|
||||
+ `AesCrypt::decryptFromBase64()`: Use `AesCrypt::decrypt()` instead as it also returns a base64 decoded string.
|
||||
+ `InlinePie::disableNoScript()`: Empty method.
|
||||
+ `SimpleQuery::paginate()`: Use `Icinga\Web\Controller::setupPaginationControl()` and/or `Icinga\Web\Widget\Paginator` instead.
|
||||
+ `LdapConnection::connect()`: The connection is established lazily now.
|
||||
+ `MonitoredObject::matches()`: Use `$filter->matches($object)` instead.
|
||||
+ `MonitoredObject::fromParams()`: Deleted without substitution.
|
||||
+ `DataView::fromRequest()`: Use `$backend->select()->from($viewName)` instead.
|
||||
+ `DataView::sort()`: Use `DataView::order()` instead.
|
||||
+ `MonitoringBackend::createBackend()`: Use `MonitoringBackend::instance()` instead.
|
||||
+ `DbConnection::getConnection()`: Use `Connection::getDbAdapter()` instead.
|
||||
+ `DbQuery::renderFilter()`: Use `DbConnection::renderFilter()` instead.
|
||||
+ `DbQuery::whereToSql()`: Use `DbConnection::renderFilter()` instead.
|
||||
+ `DataView::applyUrlFilter()`: Not in use.
|
||||
|
||||
**Classes:**
|
||||
+ `Icinga\Util\String`: Use `Icinga\Util\StringHelper` instead.
|
||||
+ `Icinga\Util\Translator`: Use `\ipl\I18n\StaticTranslator::$instance` or `\ipl\I18n\Translation` instead.
|
||||
+ `Icinga\Module\Migrate\Clicommands\DashboardCommand`: Deleted without substitution.
|
||||
+ `Icinga\Web\Hook\TicketHook`: Use `Icinga\Application\Hook\TicketHook` instead.
|
||||
+ `Icinga\Web\Hook\GrapherHook`: Use `Icinga\Application\Hook\GrapherHook` instead.
|
||||
+ `Icinga\Module\Monitoring\Environment`: Not in use.
|
||||
+ `Icinga\Module\Monitoring\Backend`: Use `Icinga\Module\Monitoring\Backend\MonitoringBackend` instead.
|
||||
|
||||
* All the following deprecated js classes and methods are removed:
|
||||
|
||||
**Methods:**
|
||||
+ `loader::addUrlFlag()`: Use `Icinga.Utils.addUrlFlag()` instead.
|
||||
|
||||
## Upgrading to Icinga Web 2 2.10.x
|
||||
|
||||
**General**
|
||||
|
|
|
@ -434,17 +434,6 @@ abstract class ApplicationBootstrap
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the Zend Autoloader - compat only - does nothing
|
||||
*
|
||||
* @deprecated
|
||||
* @return $this
|
||||
*/
|
||||
public function setupZendAutoloader()
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup module manager
|
||||
*
|
||||
|
@ -766,19 +755,4 @@ abstract class ApplicationBootstrap
|
|||
$localedir = $this->getLocaleDir();
|
||||
return $localedir !== false && file_exists($localedir) && is_dir($localedir);
|
||||
}
|
||||
|
||||
/**
|
||||
* List all available locales
|
||||
*
|
||||
* @return array Locale list
|
||||
*
|
||||
* @deprecated Use {@see \ipl\I18n\GettextTranslator::listLocales()} instead
|
||||
*/
|
||||
public function listLocales()
|
||||
{
|
||||
/** @var GettextTranslator $translator */
|
||||
$translator = StaticTranslator::$instance;
|
||||
|
||||
return $translator->listLocales();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,7 +65,6 @@ class EmbeddedWeb extends ApplicationBootstrap
|
|||
protected function bootstrap()
|
||||
{
|
||||
return $this
|
||||
->setupZendAutoloader()
|
||||
->setupErrorHandling()
|
||||
->loadLibraries()
|
||||
->loadConfig()
|
||||
|
|
|
@ -1388,22 +1388,6 @@ class Module
|
|||
return $this->includeScript($this->configScript);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a hook
|
||||
*
|
||||
* @param string $name Name of the hook
|
||||
* @param string $class Class of the hook w/ namespace
|
||||
* @param string $key
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @deprecated Deprecated since 2.1.1. Use {@link provideHook()} instead
|
||||
*/
|
||||
protected function registerHook($name, $class, $key = null)
|
||||
{
|
||||
return $this->provideHook($name, $class, $key);
|
||||
}
|
||||
|
||||
protected function slashesToNamespace($class)
|
||||
{
|
||||
$list = explode('/', $class);
|
||||
|
|
|
@ -20,7 +20,6 @@ use Icinga\User;
|
|||
use Icinga\Util\DirectoryIterator;
|
||||
use Icinga\Util\TimezoneDetect;
|
||||
use Icinga\Web\Controller\Dispatcher;
|
||||
use Icinga\Web\Menu;
|
||||
use Icinga\Web\Navigation\Navigation;
|
||||
use Icinga\Web\Notification;
|
||||
use Icinga\Web\Session;
|
||||
|
@ -82,7 +81,6 @@ class Web extends EmbeddedWeb
|
|||
protected function bootstrap()
|
||||
{
|
||||
return $this
|
||||
->setupZendAutoloader()
|
||||
->setupLogging()
|
||||
->setupErrorHandling()
|
||||
->loadLibraries()
|
||||
|
@ -284,18 +282,6 @@ class Web extends EmbeddedWeb
|
|||
return $navigation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the app's menu
|
||||
*
|
||||
* @deprecated Instantiate the returned class directly instead of using this method.
|
||||
*
|
||||
* @return Menu
|
||||
*/
|
||||
public function getMenu()
|
||||
{
|
||||
return new Menu();
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch public interface
|
||||
*/
|
||||
|
|
|
@ -204,11 +204,8 @@ class AdmissionLoader
|
|||
|
||||
$roleRestrictions = $role->getRestrictions();
|
||||
foreach ($roleRestrictions as $name => & $restriction) {
|
||||
// TODO(el): user.local_name is supported since version 2.9.
|
||||
// and therefore user:local_name is deprecated.
|
||||
// The latter will be removed in version 2.11.
|
||||
$restriction = str_replace(
|
||||
['$user.local_name$', '$user:local_name$'],
|
||||
'$user.local_name$',
|
||||
$user->getLocalUsername(),
|
||||
$restriction
|
||||
);
|
||||
|
|
|
@ -244,22 +244,6 @@ class AesCrypt
|
|||
return $decrypt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode from Base64 and decrypt the given string
|
||||
*
|
||||
* @param string $data
|
||||
*
|
||||
* @return string The base64 decoded and decrypted string
|
||||
*
|
||||
* @deprecated Use decrypt() instead as it also returns a base64 decoded string
|
||||
*
|
||||
* @throws RuntimeException If decryption fails
|
||||
*/
|
||||
public function decryptFromBase64($data)
|
||||
{
|
||||
return $this->decrypt(base64_decode($data));
|
||||
}
|
||||
|
||||
/**
|
||||
* Encrypt the given string
|
||||
*
|
||||
|
@ -284,22 +268,6 @@ class AesCrypt
|
|||
return $encrypt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encrypt the given string and encode to Base64
|
||||
*
|
||||
* @param string $data
|
||||
*
|
||||
* @return string encrypted and base64 encoded string
|
||||
*
|
||||
* @deprecated Use encrypt() instead as it also returns a base64 encoded string
|
||||
*
|
||||
* @throws RuntimeException If encryption fails
|
||||
*/
|
||||
public function encryptToBase64($data)
|
||||
{
|
||||
return base64_encode($this->encrypt($data));
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrypt the given string with non Authenticated encryption (AE) cipher method
|
||||
*
|
||||
|
|
|
@ -268,14 +268,6 @@ class DbConnection implements Selectable, Extensible, Updatable, Reducible, Insp
|
|||
return new static(ResourceFactory::getResourceConfig($name));
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use Connection::getDbAdapter() instead
|
||||
*/
|
||||
public function getConnection()
|
||||
{
|
||||
return $this->dbAdapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the table prefix
|
||||
*
|
||||
|
|
|
@ -7,13 +7,10 @@ use DateInterval;
|
|||
use DateTime;
|
||||
use DateTimeZone;
|
||||
use Exception;
|
||||
use Icinga\Data\Filter\Filter;
|
||||
use Zend_Db_Expr;
|
||||
use Zend_Db_Select;
|
||||
use Icinga\Application\Logger;
|
||||
use Icinga\Data\Filter\FilterAnd;
|
||||
use Icinga\Data\Filter\FilterChain;
|
||||
use Icinga\Data\Filter\FilterNot;
|
||||
use Icinga\Data\Filter\FilterOr;
|
||||
use Icinga\Data\SimpleQuery;
|
||||
use Icinga\Exception\ProgrammingError;
|
||||
use Icinga\Exception\QueryException;
|
||||
|
@ -116,6 +113,23 @@ class DbQuery extends SimpleQuery
|
|||
return parent::where($condition, $value);
|
||||
}
|
||||
|
||||
public function addFilter(Filter $filter)
|
||||
{
|
||||
$this->expressionsToTimestamp($filter);
|
||||
return parent::addFilter($filter);
|
||||
}
|
||||
|
||||
private function expressionsToTimestamp(Filter $filter)
|
||||
{
|
||||
if ($filter->isChain()) {
|
||||
foreach ($filter->filters() as $child) {
|
||||
$this->expressionsToTimestamp($child);
|
||||
}
|
||||
} elseif ($this->isTimestamp($filter->getColumn())) {
|
||||
$filter->setExpression($this->valueToTimestamp($filter->getExpression()));
|
||||
}
|
||||
}
|
||||
|
||||
protected function dbSelect()
|
||||
{
|
||||
return clone $this->select;
|
||||
|
@ -179,55 +193,12 @@ class DbQuery extends SimpleQuery
|
|||
|
||||
protected function applyFilterSql($select)
|
||||
{
|
||||
$where = $this->renderFilter($this->filter);
|
||||
$where = $this->getDatasource()->renderFilter($this->filter);
|
||||
if ($where !== '') {
|
||||
$select->where($where);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use DbConnection::renderFilter() instead!
|
||||
*/
|
||||
protected function renderFilter($filter, $level = 0)
|
||||
{
|
||||
$str = '';
|
||||
if ($filter instanceof FilterChain) {
|
||||
if ($filter instanceof FilterAnd) {
|
||||
$op = ' AND ';
|
||||
} elseif ($filter instanceof FilterOr) {
|
||||
$op = ' OR ';
|
||||
} elseif ($filter instanceof FilterNot) {
|
||||
$op = ' AND ';
|
||||
$str .= ' NOT ';
|
||||
} else {
|
||||
throw new QueryException(
|
||||
'Cannot render filter: %s',
|
||||
$filter
|
||||
);
|
||||
}
|
||||
$parts = array();
|
||||
if (! $filter->isEmpty()) {
|
||||
foreach ($filter->filters() as $f) {
|
||||
$filterPart = $this->renderFilter($f, $level + 1);
|
||||
if ($filterPart !== '') {
|
||||
$parts[] = $filterPart;
|
||||
}
|
||||
}
|
||||
if (! empty($parts)) {
|
||||
if ($level > 0) {
|
||||
$str .= ' (' . implode($op, $parts) . ') ';
|
||||
} else {
|
||||
$str .= implode($op, $parts);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$str .= $this->whereToSql($filter->getColumn(), $filter->getSign(), $filter->getExpression());
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
protected function escapeForSql($value)
|
||||
{
|
||||
// bindParam? bindValue?
|
||||
|
@ -253,20 +224,16 @@ class DbQuery extends SimpleQuery
|
|||
|
||||
protected function valueToTimestamp($value)
|
||||
{
|
||||
// We consider integers as valid timestamps. Does not work for URL params
|
||||
if (! is_string($value) || ctype_digit($value)) {
|
||||
return $value;
|
||||
if (ctype_digit($value)) {
|
||||
$value = (int) $value;
|
||||
} elseif (is_string($value)) {
|
||||
$value = strtotime($value);
|
||||
}
|
||||
$value = strtotime($value);
|
||||
if (! $value) {
|
||||
/*
|
||||
NOTE: It's too late to throw exceptions, we might finish in __toString
|
||||
throw new QueryException(sprintf(
|
||||
'"%s" is not a valid time expression',
|
||||
$value
|
||||
));
|
||||
*/
|
||||
|
||||
if (is_int($value)) {
|
||||
$value = $this->timestampForSql($value);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
|
@ -301,7 +268,7 @@ class DbQuery extends SimpleQuery
|
|||
}
|
||||
}
|
||||
|
||||
return $this->escapeForSql($dateTime->format('Y-m-d H:i:s'));
|
||||
return $dateTime->format('Y-m-d H:i:s');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -322,63 +289,6 @@ class DbQuery extends SimpleQuery
|
|||
return false;
|
||||
}
|
||||
|
||||
public function whereToSql($col, $sign, $expression)
|
||||
{
|
||||
if ($this->isTimestamp($col)) {
|
||||
$expression = $this->valueToTimestamp($expression);
|
||||
}
|
||||
|
||||
if (is_array($expression)) {
|
||||
$comp = [];
|
||||
$pattern = [];
|
||||
foreach ($expression as $value) {
|
||||
if (strpos($value, '*') === false) {
|
||||
$comp[] = $value;
|
||||
} else {
|
||||
$pattern[] = $this->whereToSql($col, $sign, $value);
|
||||
}
|
||||
}
|
||||
$sql = $pattern;
|
||||
if ($sign === '=') {
|
||||
if (! empty($comp)) {
|
||||
$sql[] = $col . ' IN (' . $this->escapeForSql($comp) . ')';
|
||||
}
|
||||
$operator = 'OR';
|
||||
} elseif ($sign === '!=') {
|
||||
if (! empty($comp)) {
|
||||
$sql[] = sprintf('(%1$s NOT IN (%2$s) OR %1$s IS NULL)', $col, $this->escapeForSql($comp));
|
||||
}
|
||||
$operator = 'AND';
|
||||
} else {
|
||||
throw new QueryException(
|
||||
'Unable to render array expressions with operators other than equal or not equal'
|
||||
);
|
||||
}
|
||||
|
||||
return '(' . implode(" $operator ", $sql) . ')';
|
||||
} elseif ($sign === '=' && $expression !== null && strpos($expression, '*') !== false) {
|
||||
if ($expression === '*') {
|
||||
return $col . ' IS NOT NULL';
|
||||
}
|
||||
|
||||
return $col . ' LIKE ' . $this->escapeForSql($this->escapeWildcards($expression));
|
||||
} elseif ($sign === '!=' && $expression !== null && strpos($expression, '*') !== false) {
|
||||
if ($expression === '*') {
|
||||
return $col . ' IS NULL';
|
||||
}
|
||||
|
||||
return sprintf(
|
||||
'(%1$s NOT LIKE %2$s OR %1$s IS NULL)',
|
||||
$col,
|
||||
$this->escapeForSql($this->escapeWildcards($expression))
|
||||
);
|
||||
} elseif ($sign === '!=') {
|
||||
return sprintf('(%1$s %2$s %3$s OR %1$s IS NULL)', $col, $sign, $this->escapeForSql($expression));
|
||||
} else {
|
||||
return sprintf('%s %s %s', $col, $sign, $this->escapeForSql($expression));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the count query
|
||||
*
|
||||
|
|
|
@ -5,13 +5,10 @@ namespace Icinga\Data;
|
|||
|
||||
use Iterator;
|
||||
use IteratorAggregate;
|
||||
use Zend_Paginator;
|
||||
use Icinga\Application\Icinga;
|
||||
use Icinga\Application\Benchmark;
|
||||
use Icinga\Data\Filter\Filter;
|
||||
use Icinga\Exception\IcingaException;
|
||||
use Icinga\Exception\ProgrammingError;
|
||||
use Icinga\Web\Paginator\Adapter\QueryAdapter;
|
||||
|
||||
class SimpleQuery implements QueryInterface, Queryable, Iterator
|
||||
{
|
||||
|
@ -517,43 +514,6 @@ class SimpleQuery implements QueryInterface, Queryable, Iterator
|
|||
return $this->limitOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Paginate data
|
||||
*
|
||||
* Auto-detects pagination parameters from request when unset
|
||||
*
|
||||
* @param int $itemsPerPage Number of items per page
|
||||
* @param int $pageNumber Current page number
|
||||
*
|
||||
* @return Zend_Paginator
|
||||
*
|
||||
* @deprecated Use Icinga\Web\Controller::setupPaginationControl() and/or Icinga\Web\Widget\Paginator instead
|
||||
*/
|
||||
public function paginate($itemsPerPage = null, $pageNumber = null)
|
||||
{
|
||||
trigger_error(
|
||||
'SimpleQuery::paginate() is deprecated. Use Icinga\Web\Controller::setupPaginationControl()'
|
||||
. ' and/or Icinga\Web\Widget\Paginator instead',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
|
||||
if ($itemsPerPage === null || $pageNumber === null) {
|
||||
// Detect parameters from request
|
||||
$request = Icinga::app()->getRequest();
|
||||
if ($itemsPerPage === null) {
|
||||
$itemsPerPage = $request->getParam('limit', 25);
|
||||
}
|
||||
if ($pageNumber === null) {
|
||||
$pageNumber = $request->getParam('page', 0);
|
||||
}
|
||||
}
|
||||
$this->limit($itemsPerPage, $pageNumber * $itemsPerPage);
|
||||
$paginator = new Zend_Paginator(new QueryAdapter($this));
|
||||
$paginator->setItemCountPerPage($itemsPerPage);
|
||||
$paginator->setCurrentPageNumber($pageNumber);
|
||||
return $paginator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve an array containing all rows of the result set
|
||||
*
|
||||
|
|
|
@ -321,18 +321,6 @@ class LdapConnection implements Selectable, Inspectable
|
|||
return $this->encrypted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Establish a connection
|
||||
*
|
||||
* @throws LdapException In case the connection could not be established
|
||||
*
|
||||
* @deprecated The connection is established lazily now
|
||||
*/
|
||||
public function connect()
|
||||
{
|
||||
$this->getConnection();
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a LDAP bind on the current connection
|
||||
*
|
||||
|
|
|
@ -305,7 +305,7 @@ namespace Icinga\Test {
|
|||
);
|
||||
}
|
||||
|
||||
$resource->getConnection()->exec($sqlData);
|
||||
$resource->getDbAdapter()->exec($sqlData);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -324,7 +324,7 @@ namespace Icinga\Test {
|
|||
return;
|
||||
}
|
||||
|
||||
$adapter = $resource->getConnection();
|
||||
$adapter = $resource->getDbAdapter();
|
||||
|
||||
try {
|
||||
$adapter->getConnection();
|
||||
|
|
|
@ -1,159 +0,0 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2013 Icinga Development Team | GPLv2+ */
|
||||
|
||||
namespace Icinga\Util;
|
||||
|
||||
/**
|
||||
* Common string functions
|
||||
*
|
||||
* @deprecated(el): For backwards compatibility only. Use StringHelper instead.
|
||||
*/
|
||||
class String
|
||||
{
|
||||
/**
|
||||
* Split string into an array and trim spaces
|
||||
*
|
||||
* @param string $value
|
||||
* @param string $delimiter
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function trimSplit($value, $delimiter = ',')
|
||||
{
|
||||
return array_map('trim', explode($delimiter, $value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Uppercase the first character of each word in a string
|
||||
*
|
||||
* Converts 'first_name' to 'FirstName' for example.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $separator Word separator
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function cname($name, $separator = '_')
|
||||
{
|
||||
return str_replace(' ', '', ucwords(str_replace($separator, ' ', strtolower($name))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add ellipsis when a string is longer than max length
|
||||
*
|
||||
* @param string $string
|
||||
* @param int $maxLength
|
||||
* @param string $ellipsis
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function ellipsis($string, $maxLength, $ellipsis = '...')
|
||||
{
|
||||
if (strlen($string) > $maxLength) {
|
||||
return substr($string, 0, $maxLength - strlen($ellipsis)) . $ellipsis;
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add ellipsis in the center of a string when a string is longer than max length
|
||||
*
|
||||
* @param string $string
|
||||
* @param int $maxLength
|
||||
* @param string $ellipsis
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function ellipsisCenter($string, $maxLength, $ellipsis = '...')
|
||||
{
|
||||
$start = ceil($maxLength / 2.0);
|
||||
$end = floor($maxLength / 2.0);
|
||||
if (strlen($string) > $maxLength) {
|
||||
return substr($string, 0, $start - strlen($ellipsis)) . $ellipsis . substr($string, - $end);
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find and return all similar strings in $possibilites matching $string with the given minimum $similarity
|
||||
*
|
||||
* @param string $string
|
||||
* @param array $possibilities
|
||||
* @param float $similarity
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function findSimilar($string, array $possibilities, $similarity = 0.33)
|
||||
{
|
||||
if (empty($string)) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$matches = array();
|
||||
foreach ($possibilities as $possibility) {
|
||||
$distance = levenshtein($string, $possibility);
|
||||
if ($distance / strlen($string) <= $similarity) {
|
||||
$matches[] = $possibility;
|
||||
}
|
||||
}
|
||||
|
||||
return $matches;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether the given string ends with the given suffix
|
||||
*
|
||||
* @param string $string The string to test
|
||||
* @param string $suffix The suffix the string must end with
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function endsWith($string, $suffix)
|
||||
{
|
||||
$stringSuffix = substr($string, -strlen($suffix));
|
||||
return $stringSuffix !== false ? $stringSuffix === $suffix : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an array of strings that constitutes the cartesian product of all passed sets, with all
|
||||
* string combinations concatenated using the passed join-operator.
|
||||
*
|
||||
* <pre>
|
||||
* cartesianProduct(
|
||||
* array(array('foo', 'bar'), array('mumble', 'grumble', null)),
|
||||
* '_'
|
||||
* );
|
||||
* => array('foo_mumble', 'foo_grumble', 'bar_mumble', 'bar_grumble', 'foo', 'bar')
|
||||
* </pre>
|
||||
*
|
||||
* @param array $sets An array of arrays containing all sets for which the cartesian
|
||||
* product should be calculated.
|
||||
* @param string $glue The glue used to join the strings, defaults to ''.
|
||||
*
|
||||
* @returns array The cartesian product in one array of strings.
|
||||
*/
|
||||
public static function cartesianProduct(array $sets, $glue = '')
|
||||
{
|
||||
$product = null;
|
||||
foreach ($sets as $set) {
|
||||
if (! isset($product)) {
|
||||
$product = $set;
|
||||
} else {
|
||||
$newProduct = array();
|
||||
foreach ($product as $strA) {
|
||||
foreach ($set as $strB) {
|
||||
if ($strB === null) {
|
||||
$newProduct []= $strA;
|
||||
} else {
|
||||
$newProduct []= $strA . $glue . $strB;
|
||||
}
|
||||
}
|
||||
}
|
||||
$product = $newProduct;
|
||||
}
|
||||
}
|
||||
return $product;
|
||||
}
|
||||
}
|
|
@ -1,184 +0,0 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2014 Icinga Development Team | GPLv2+ */
|
||||
|
||||
namespace Icinga\Util;
|
||||
|
||||
use ipl\I18n\GettextTranslator;
|
||||
use ipl\I18n\Locale;
|
||||
use ipl\I18n\StaticTranslator;
|
||||
|
||||
/**
|
||||
* Helper class to ease internationalization when using gettext
|
||||
*
|
||||
* @deprecated Use {@see \ipl\I18n\StaticTranslator::$instance} or {@see \ipl\I18n\Translation} instead
|
||||
*/
|
||||
class Translator
|
||||
{
|
||||
/**
|
||||
* The default gettext domain used as fallback
|
||||
*/
|
||||
const DEFAULT_DOMAIN = 'icinga';
|
||||
|
||||
/**
|
||||
* The locale code that is used in the project
|
||||
*/
|
||||
const DEFAULT_LOCALE = 'en_US';
|
||||
|
||||
/**
|
||||
* Translate a string
|
||||
*
|
||||
* Falls back to the default domain in case the string cannot be translated using the given domain
|
||||
*
|
||||
* @param string $text The string to translate
|
||||
* @param string $domain The primary domain to use
|
||||
* @param string|null $context Optional parameter for context based translation
|
||||
*
|
||||
* @return string The translated string
|
||||
*/
|
||||
public static function translate($text, $domain, $context = null)
|
||||
{
|
||||
return StaticTranslator::$instance->translateInDomain($domain, $text, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate a plural string
|
||||
*
|
||||
* Falls back to the default domain in case the string cannot be translated using the given domain
|
||||
*
|
||||
* @param string $textSingular The string in singular form to translate
|
||||
* @param string $textPlural The string in plural form to translate
|
||||
* @param integer $number The amount to determine from whether to return singular or plural
|
||||
* @param string $domain The primary domain to use
|
||||
* @param string|null $context Optional parameter for context based translation
|
||||
*
|
||||
* @return string The translated string
|
||||
*/
|
||||
public static function translatePlural($textSingular, $textPlural, $number, $domain, $context = null)
|
||||
{
|
||||
return StaticTranslator::$instance->translatePluralInDomain(
|
||||
$domain,
|
||||
$textSingular,
|
||||
$textPlural,
|
||||
$number,
|
||||
$context
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Emulated pgettext()
|
||||
*
|
||||
* @link http://php.net/manual/de/book.gettext.php#89975
|
||||
*
|
||||
* @param $text
|
||||
* @param $domain
|
||||
* @param $context
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function pgettext($text, $domain, $context)
|
||||
{
|
||||
return StaticTranslator::$instance->translateInDomain($domain, $text, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Emulated pngettext()
|
||||
*
|
||||
* @link http://php.net/manual/de/book.gettext.php#89975
|
||||
*
|
||||
* @param $textSingular
|
||||
* @param $textPlural
|
||||
* @param $number
|
||||
* @param $domain
|
||||
* @param $context
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function pngettext($textSingular, $textPlural, $number, $domain, $context)
|
||||
{
|
||||
return StaticTranslator::$instance->translatePluralInDomain(
|
||||
$domain,
|
||||
$textSingular,
|
||||
$textPlural,
|
||||
$number,
|
||||
$context
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a new gettext domain
|
||||
*
|
||||
* @param string $name The name of the domain to register
|
||||
* @param string $directory The directory where message catalogs can be found
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function registerDomain($name, $directory)
|
||||
{
|
||||
/** @var GettextTranslator $translator */
|
||||
$translator = StaticTranslator::$instance;
|
||||
|
||||
$translator->addTranslationDirectory($directory, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the locale to use
|
||||
*
|
||||
* @param string $localeName The name of the locale to use
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function setupLocale($localeName)
|
||||
{
|
||||
/** @var GettextTranslator $translator */
|
||||
$translator = StaticTranslator::$instance;
|
||||
|
||||
$translator->setLocale($localeName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Split and return the language code and country code of the given locale or the current locale
|
||||
*
|
||||
* @param string $locale The locale code to split, or null to split the current locale
|
||||
*
|
||||
* @return object An object with a 'language' and 'country' attribute
|
||||
*/
|
||||
public static function splitLocaleCode($locale = null)
|
||||
{
|
||||
/** @var GettextTranslator $translator */
|
||||
$translator = StaticTranslator::$instance;
|
||||
|
||||
if ($locale === null) {
|
||||
$locale = $translator->getLocale();
|
||||
}
|
||||
|
||||
return (new Locale())->parseLocale($locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of all locale codes currently available in the known domains
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getAvailableLocaleCodes()
|
||||
{
|
||||
/** @var GettextTranslator $translator */
|
||||
$translator = StaticTranslator::$instance;
|
||||
|
||||
return $translator->listLocales();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the preferred locale based on the given HTTP header and the available translations
|
||||
*
|
||||
* @param string $header The HTTP "Accept-Language" header
|
||||
*
|
||||
* @return string The browser's preferred locale code
|
||||
*/
|
||||
public static function getPreferredLocaleCode($header)
|
||||
{
|
||||
/** @var GettextTranslator $translator */
|
||||
$translator = StaticTranslator::$instance;
|
||||
|
||||
return (new Locale())->getPreferred($header, $translator->listLocales());
|
||||
}
|
||||
}
|
|
@ -8,7 +8,8 @@ use Icinga\Application\Hook as NewHookImplementation;
|
|||
/**
|
||||
* Icinga Web Hook registry
|
||||
*
|
||||
* Deprecated, please use Icinga\Application\Hook instead
|
||||
* @deprecated It is highly recommended to use {@see Icinga\Application\Hook} instead. Though since this message
|
||||
* (or rather the previous message) hasn't been visible for ages... This won't be removed anyway....
|
||||
*/
|
||||
class Hook extends NewHookImplementation
|
||||
{
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2013 Icinga Development Team | GPLv2+ */
|
||||
|
||||
namespace Icinga\Web\Hook;
|
||||
|
||||
use Icinga\Application\Hook\GrapherHook as BaseHook;
|
||||
|
||||
/**
|
||||
* Deprecated, compat only.
|
||||
*
|
||||
* Please implement hooks in Icinga\Application\Hook
|
||||
*/
|
||||
abstract class GrapherHook extends BaseHook
|
||||
{
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2014 Icinga Development Team | GPLv2+ */
|
||||
|
||||
namespace Icinga\Web\Hook;
|
||||
|
||||
use Icinga\Application\Hook\TicketHook as BaseHook;
|
||||
|
||||
/**
|
||||
* Deprecated, compat only.
|
||||
*
|
||||
* Please implement hooks in Icinga\Application\Hook
|
||||
*/
|
||||
abstract class TicketHook extends BaseHook
|
||||
{
|
||||
}
|
|
@ -367,75 +367,6 @@ class Url
|
|||
return $this->scheme;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the baseUrl for this url
|
||||
*
|
||||
* @deprecated Please create a new url from scratch instead
|
||||
*
|
||||
* @param string $baseUrl The url path to use as the url base
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setBaseUrl($baseUrl)
|
||||
{
|
||||
$urlParts = parse_url($baseUrl);
|
||||
if (isset($urlParts["host"])) {
|
||||
$this->setHost($urlParts["host"]);
|
||||
}
|
||||
if (isset($urlParts["port"])) {
|
||||
$this->setPort($urlParts["port"]);
|
||||
}
|
||||
if (isset($urlParts['scheme'])) {
|
||||
$this->setScheme($urlParts['scheme']);
|
||||
}
|
||||
if (isset($urlParts['user'])) {
|
||||
$this->setUsername($urlParts['user']);
|
||||
}
|
||||
if (isset($urlParts['pass'])) {
|
||||
$this->setPassword($urlParts['pass']);
|
||||
}
|
||||
if (isset($urlParts['path'])) {
|
||||
$this->setBasePath($urlParts['path']);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the baseUrl for this url
|
||||
*
|
||||
* @deprecated
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getBaseUrl()
|
||||
{
|
||||
if (! $this->isExternal()) {
|
||||
return $this->getBasePath();
|
||||
}
|
||||
|
||||
$urlString = '';
|
||||
if ($this->getScheme()) {
|
||||
$urlString .= $this->getScheme() . '://';
|
||||
}
|
||||
if ($this->getPassword()) {
|
||||
$urlString .= $this->getUsername() . ':' . $this->getPassword() . '@';
|
||||
} elseif ($this->getUsername()) {
|
||||
$urlString .= $this->getUsername() . '@';
|
||||
}
|
||||
if ($this->getHost()) {
|
||||
$urlString .= $this->getHost();
|
||||
}
|
||||
if ($this->getPort()) {
|
||||
$urlString .= ':' . $this->getPort();
|
||||
}
|
||||
if ($this->getBasePath()) {
|
||||
$urlString .= $this->getBasePath();
|
||||
}
|
||||
|
||||
return $urlString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the relative path of this url, without query parameters
|
||||
*
|
||||
|
|
|
@ -134,15 +134,6 @@ class InlinePie extends AbstractWidget
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Do not display the NoScript fallback html
|
||||
*
|
||||
* @deprecated noop
|
||||
*/
|
||||
public function disableNoScript()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the class to define the
|
||||
*
|
||||
|
|
|
@ -1,127 +0,0 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2019 Icinga GmbH | GPLv2+ */
|
||||
|
||||
namespace Icinga\Module\Migrate\Clicommands;
|
||||
|
||||
use Exception;
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Application\Icinga;
|
||||
use Icinga\Application\Modules\DashboardContainer;
|
||||
use Icinga\Cli\Command;
|
||||
use Icinga\Application\Logger;
|
||||
use ipl\I18n\GettextTranslator;
|
||||
use ipl\I18n\StaticTranslator;
|
||||
use ReflectionClass;
|
||||
|
||||
class DashboardCommand extends Command
|
||||
{
|
||||
/**
|
||||
* Rename translated dashboard sections
|
||||
*
|
||||
* Migrates all locally found dashboard configurations so that the effects of
|
||||
* https://github.com/Icinga/icingaweb2/issues/3542 are reversed.
|
||||
*
|
||||
* USAGE
|
||||
*
|
||||
* icingacli migrate dashboard sections
|
||||
*/
|
||||
public function sectionsAction()
|
||||
{
|
||||
$moduleReflection = new ReflectionClass('Icinga\Application\Modules\Module');
|
||||
// There's no direct way to invoke this method
|
||||
$launchConfigScriptMethod = $moduleReflection->getMethod('launchConfigScript');
|
||||
$launchConfigScriptMethod->setAccessible(true);
|
||||
// Calling getDashboard() results in Url::fromPath() getting called as well == the CLI's death
|
||||
$paneItemsProperty = $moduleReflection->getProperty('paneItems');
|
||||
$paneItemsProperty->setAccessible(true);
|
||||
|
||||
/** @var GettextTranslator $translator */
|
||||
$translator = StaticTranslator::$instance;
|
||||
|
||||
$locales = $translator->listLocales();
|
||||
$modules = Icinga::app()->getModuleManager()->getLoadedModules();
|
||||
foreach ($this->listDashboardConfigs() as $path) {
|
||||
Logger::info('Migrating dashboard config: %s', $path);
|
||||
|
||||
$config = Config::fromIni($path);
|
||||
foreach ($modules as $module) {
|
||||
if (! $module->hasLocales()) {
|
||||
// Modules without any translations are not affected
|
||||
continue;
|
||||
}
|
||||
|
||||
$launchConfigScriptMethod->invoke($module);
|
||||
|
||||
foreach ($locales as $locale) {
|
||||
if ($locale === 'en_US') {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
$translator->setLocale($locale);
|
||||
} catch (Exception $e) {
|
||||
Logger::debug('Ignoring locale "%s". Reason: %s', $locale, $e->getMessage());
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($paneItemsProperty->getValue($module) as $paneName => $container) {
|
||||
/** @var DashboardContainer $container */
|
||||
foreach ($config->toArray() as $section => $options) {
|
||||
if (strpos($section, '.') !== false) {
|
||||
list($paneTitle, $dashletTitle) = explode('.', $section, 2);
|
||||
} else {
|
||||
$paneTitle = $section;
|
||||
$dashletTitle = null;
|
||||
}
|
||||
|
||||
if (mt($module->getName(), $paneName) !== $paneTitle) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$dashletName = null;
|
||||
if ($dashletTitle !== null) {
|
||||
foreach ($container->getDashlets() as $name => $url) {
|
||||
if (mt($module->getName(), $name) === $dashletTitle) {
|
||||
$dashletName = $name;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($dashletName === null) {
|
||||
$dashletName = $dashletTitle;
|
||||
}
|
||||
}
|
||||
|
||||
$newSection = $paneName . ($dashletName ? '.' . $dashletName : '');
|
||||
$config->removeSection($section);
|
||||
$config->setSection($newSection, $options);
|
||||
|
||||
Logger::info('Migrated section "%s" to "%s"', $section, $newSection);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$config->saveIni();
|
||||
}
|
||||
}
|
||||
|
||||
protected function listDashboardConfigs()
|
||||
{
|
||||
$dashboardConfigPath = Config::resolvePath('dashboards');
|
||||
|
||||
try {
|
||||
$dashboardConfigDir = opendir($dashboardConfigPath);
|
||||
} catch (Exception $e) {
|
||||
Logger::error('Cannot access dashboard configuration: %s', $e);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
while ($entry = readdir($dashboardConfigDir)) {
|
||||
$userDashboardPath = join(DIRECTORY_SEPARATOR, [$dashboardConfigPath, $entry, 'dashboard.ini']);
|
||||
if (is_file($userDashboardPath)) {
|
||||
yield $userDashboardPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
namespace Icinga\Module\Monitoring\Clicommands;
|
||||
|
||||
use Icinga\Module\Monitoring\Backend;
|
||||
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
|
||||
use Icinga\Module\Monitoring\Cli\CliUtils;
|
||||
use Icinga\Date\DateFormatter;
|
||||
use Icinga\Cli\Command;
|
||||
|
@ -25,8 +25,7 @@ class ListCommand extends Command
|
|||
|
||||
public function init()
|
||||
{
|
||||
$this->app->setupZendAutoloader();
|
||||
$this->backend = Backend::createBackend($this->params->shift('backend'));
|
||||
$this->backend = MonitoringBackend::instance($this->params->shift('backend'));
|
||||
$this->dumpSql = $this->params->shift('showsql');
|
||||
}
|
||||
|
||||
|
|
|
@ -8,10 +8,10 @@ use Icinga\Data\ResourceFactory;
|
|||
use Icinga\Exception\ConfigurationError;
|
||||
use Icinga\Exception\NotFoundError;
|
||||
use Icinga\Forms\ConfirmRemovalForm;
|
||||
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
|
||||
use Icinga\Module\Monitoring\Forms\Config\TransportReorderForm;
|
||||
use Icinga\Web\Controller;
|
||||
use Icinga\Web\Notification;
|
||||
use Icinga\Module\Monitoring\Backend;
|
||||
use Icinga\Module\Monitoring\Forms\Config\BackendConfigForm;
|
||||
use Icinga\Module\Monitoring\Forms\Config\SecurityConfigForm;
|
||||
use Icinga\Module\Monitoring\Forms\Config\TransportConfigForm;
|
||||
|
@ -215,7 +215,7 @@ class ConfigController extends Controller
|
|||
$form->setTitle(sprintf($this->translate('Edit Command Transport %s'), $transportName));
|
||||
$form->setIniConfig($this->Config('commandtransports'));
|
||||
$form->setInstanceNames(
|
||||
Backend::createBackend()->select()->from('instance', array('instance_name'))->fetchColumn()
|
||||
MonitoringBackend::instance()->select()->from('instance', array('instance_name'))->fetchColumn()
|
||||
);
|
||||
$form->setOnSuccess(function (TransportConfigForm $form) use ($transportName) {
|
||||
try {
|
||||
|
@ -259,7 +259,7 @@ class ConfigController extends Controller
|
|||
$form->setTitle($this->translate('Create New Command Transport'));
|
||||
$form->setIniConfig($this->Config('commandtransports'));
|
||||
$form->setInstanceNames(
|
||||
Backend::createBackend()->select()->from('instance', array('instance_name'))->fetchColumn()
|
||||
MonitoringBackend::instance()->select()->from('instance', array('instance_name'))->fetchColumn()
|
||||
);
|
||||
$form->setOnSuccess(function (TransportConfigForm $form) {
|
||||
try {
|
||||
|
|
|
@ -3,12 +3,12 @@
|
|||
|
||||
namespace Icinga\Module\Monitoring\Controllers;
|
||||
|
||||
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
|
||||
use Icinga\Security\SecurityException;
|
||||
use Icinga\Util\GlobFilter;
|
||||
use Icinga\Web\Form;
|
||||
use Zend_Form;
|
||||
use Icinga\Data\Filter\Filter;
|
||||
use Icinga\Module\Monitoring\Backend;
|
||||
use Icinga\Module\Monitoring\Controller;
|
||||
use Icinga\Module\Monitoring\DataView\DataView;
|
||||
use Icinga\Module\Monitoring\Forms\Command\Object\DeleteCommentCommandForm;
|
||||
|
@ -34,7 +34,7 @@ class ListController extends Controller
|
|||
/**
|
||||
* Overwrite the backend to use (used for testing)
|
||||
*
|
||||
* @param Backend $backend The Backend that should be used for querying
|
||||
* @param MonitoringBackend $backend The Backend that should be used for querying
|
||||
*/
|
||||
public function setBackend($backend)
|
||||
{
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
namespace Icinga\Module\Monitoring\Controllers;
|
||||
|
||||
use Icinga\Data\Filter\FilterEqual;
|
||||
use Icinga\Module\Monitoring\Backend;
|
||||
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
|
||||
use Icinga\Module\Monitoring\Controller;
|
||||
use Icinga\Security\SecurityException;
|
||||
use Icinga\Web\Url;
|
||||
|
@ -17,7 +17,7 @@ use Icinga\Web\Url;
|
|||
class ShowController extends Controller
|
||||
{
|
||||
/**
|
||||
* @var Backend
|
||||
* @var MonitoringBackend
|
||||
*/
|
||||
protected $backend;
|
||||
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2013 Icinga Development Team | GPLv2+ */
|
||||
|
||||
// TODO: obsolete, remove once MonitoringBackend is in use everywhere
|
||||
|
||||
namespace Icinga\Module\Monitoring;
|
||||
|
||||
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
|
||||
|
||||
class Backend extends MonitoringBackend
|
||||
{
|
||||
}
|
|
@ -8,16 +8,13 @@ namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
|||
*/
|
||||
class HostcommentdeletionhistoryQuery extends HostcommenthistoryQuery
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function whereToSql($col, $sign, $expression)
|
||||
public function isTimestamp($field)
|
||||
{
|
||||
if ($col === 'UNIX_TIMESTAMP(hch.deletion_time)') {
|
||||
return 'hch.deletion_time ' . $sign . ' ' . $this->timestampForSql($this->valueToTimestamp($expression));
|
||||
} else {
|
||||
return parent::whereToSql($col, $sign, $expression);
|
||||
if (! parent::isTimestamp($field)) {
|
||||
return $field === 'hch.deletion_time';
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -40,7 +40,7 @@ class HostcommenthistoryQuery extends IdoQuery
|
|||
'object_type' => '(\'host\')',
|
||||
'output' => "('[' || hch.author_name || '] ' || hch.comment_data)",
|
||||
'state' => '(-1)',
|
||||
'timestamp' => 'UNIX_TIMESTAMP(hch.comment_time)',
|
||||
'timestamp' => 'hch.comment_time',
|
||||
'type' => "(CASE hch.entry_type WHEN 1 THEN 'comment' WHEN 2 THEN 'dt_comment' WHEN 3 THEN 'flapping' WHEN 4 THEN 'ack' END)"
|
||||
),
|
||||
'hostgroups' => array(
|
||||
|
@ -68,16 +68,13 @@ class HostcommenthistoryQuery extends IdoQuery
|
|||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function whereToSql($col, $sign, $expression)
|
||||
public function isTimestamp($field)
|
||||
{
|
||||
if ($col === 'UNIX_TIMESTAMP(hch.comment_time)') {
|
||||
return 'hch.comment_time ' . $sign . ' ' . $this->timestampForSql($this->valueToTimestamp($expression));
|
||||
} else {
|
||||
return parent::whereToSql($col, $sign, $expression);
|
||||
if (! parent::isTimestamp($field)) {
|
||||
return $field === 'hch.comment_time';
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -8,18 +8,13 @@ namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
|||
*/
|
||||
class HostdowntimeendhistoryQuery extends HostdowntimestarthistoryQuery
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function whereToSql($col, $sign, $expression)
|
||||
public function isTimestamp($field)
|
||||
{
|
||||
if ($col === 'UNIX_TIMESTAMP(hdh.actual_end_time)') {
|
||||
return 'hdh.actual_end_time ' . $sign . ' ' . $this->timestampForSql(
|
||||
$this->valueToTimestamp($expression)
|
||||
);
|
||||
} else {
|
||||
return parent::whereToSql($col, $sign, $expression);
|
||||
if (! parent::isTimestamp($field)) {
|
||||
return $field === 'hdh.actual_end_time';
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -40,7 +40,7 @@ class HostdowntimestarthistoryQuery extends IdoQuery
|
|||
'object_type' => '(\'host\')',
|
||||
'output' => "('[' || hdh.author_name || '] ' || hdh.comment_data)",
|
||||
'state' => '(-1)',
|
||||
'timestamp' => 'UNIX_TIMESTAMP(hdh.actual_start_time)',
|
||||
'timestamp' => 'hdh.actual_start_time',
|
||||
'type' => "('dt_start')"
|
||||
),
|
||||
'hostgroups' => array(
|
||||
|
@ -68,18 +68,13 @@ class HostdowntimestarthistoryQuery extends IdoQuery
|
|||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function whereToSql($col, $sign, $expression)
|
||||
public function isTimestamp($field)
|
||||
{
|
||||
if ($col === 'UNIX_TIMESTAMP(hdh.actual_start_time)') {
|
||||
return 'hdh.actual_start_time ' . $sign . ' ' . $this->timestampForSql(
|
||||
$this->valueToTimestamp($expression)
|
||||
);
|
||||
} else {
|
||||
return parent::whereToSql($col, $sign, $expression);
|
||||
if (! parent::isTimestamp($field)) {
|
||||
return $field === 'hdh.actual_start_time';
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -40,7 +40,7 @@ class HostflappingstarthistoryQuery extends IdoQuery
|
|||
'object_type' => '(\'host\')',
|
||||
'output' => '(hfh.percent_state_change || \'\')',
|
||||
'state' => '(-1)',
|
||||
'timestamp' => 'UNIX_TIMESTAMP(hfh.event_time)',
|
||||
'timestamp' => 'hfh.event_time',
|
||||
'type' => '(\'flapping\')'
|
||||
),
|
||||
'hostgroups' => array(
|
||||
|
@ -68,16 +68,13 @@ class HostflappingstarthistoryQuery extends IdoQuery
|
|||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function whereToSql($col, $sign, $expression)
|
||||
public function isTimestamp($field)
|
||||
{
|
||||
if ($col === 'UNIX_TIMESTAMP(hfh.event_time)') {
|
||||
return 'hfh.event_time ' . $sign . ' ' . $this->timestampForSql($this->valueToTimestamp($expression));
|
||||
} else {
|
||||
return parent::whereToSql($col, $sign, $expression);
|
||||
if (! parent::isTimestamp($field)) {
|
||||
return $field === 'hfh.event_time';
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
|
||||
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||
|
||||
use Icinga\Data\Filter\Filter;
|
||||
use Icinga\Data\Filter\FilterExpression;
|
||||
|
||||
/**
|
||||
* Query for host notifications
|
||||
*/
|
||||
|
@ -37,7 +40,7 @@ class HostnotificationQuery extends IdoQuery
|
|||
'history' => array(
|
||||
'output' => null,
|
||||
'state' => 'hn.state',
|
||||
'timestamp' => 'UNIX_TIMESTAMP(hn.start_time)',
|
||||
'timestamp' => 'hn.start_time',
|
||||
'type' => '
|
||||
CASE hn.notification_reason
|
||||
WHEN 1 THEN \'notification_ack\'
|
||||
|
@ -60,7 +63,7 @@ class HostnotificationQuery extends IdoQuery
|
|||
'notification_output' => 'hn.output',
|
||||
'notification_reason' => 'hn.notification_reason',
|
||||
'notification_state' => 'hn.state',
|
||||
'notification_timestamp' => 'UNIX_TIMESTAMP(hn.start_time)',
|
||||
'notification_timestamp' => 'hn.start_time',
|
||||
'object_type' => '(\'host\')'
|
||||
),
|
||||
'servicegroups' => array(
|
||||
|
@ -76,18 +79,24 @@ class HostnotificationQuery extends IdoQuery
|
|||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function whereToSql($col, $sign, $expression)
|
||||
protected function requireFilterColumns(Filter $filter)
|
||||
{
|
||||
if ($col === 'UNIX_TIMESTAMP(hn.start_time)') {
|
||||
return 'hn.start_time ' . $sign . ' ' . $this->timestampForSql($this->valueToTimestamp($expression));
|
||||
} elseif ($col === $this->columnMap['history']['output']) {
|
||||
return parent::whereToSql('hn.output', $sign, $expression);
|
||||
} else {
|
||||
return parent::whereToSql($col, $sign, $expression);
|
||||
if ($filter instanceof FilterExpression && $filter->getColumn() === 'output') {
|
||||
$this->requireColumn($filter->getColumn());
|
||||
$filter->setColumn('hn.output');
|
||||
return null;
|
||||
}
|
||||
|
||||
return parent::requireFilterColumns($filter);
|
||||
}
|
||||
|
||||
public function isTimestamp($field)
|
||||
{
|
||||
if (! parent::isTimestamp($field)) {
|
||||
return $field === 'hn.start_time';
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -73,26 +73,18 @@ class HoststatehistoryQuery extends IdoQuery
|
|||
'object_type' => '(\'host\')',
|
||||
'output' => '(CASE WHEN hh.state_type = 1 THEN hh.output ELSE \'[ \' || hh.current_check_attempt || \'/\' || hh.max_check_attempts || \' ] \' || hh.output END)',
|
||||
'state' => 'hh.state',
|
||||
'timestamp' => 'UNIX_TIMESTAMP(hh.state_time)',
|
||||
'timestamp' => 'hh.state_time',
|
||||
'type' => "(CASE WHEN hh.state_type = 1 THEN 'hard_state' ELSE 'soft_state' END)"
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function whereToSql($col, $sign, $expression)
|
||||
public function isTimestamp($field)
|
||||
{
|
||||
if ($col === 'UNIX_TIMESTAMP(hh.state_time)') {
|
||||
return 'hh.state_time ' . $sign . ' ' . $this->timestampForSql($this->valueToTimestamp($expression));
|
||||
} elseif ($col === $this->columnMap['statehistory']['type']
|
||||
&& ! is_array($expression)
|
||||
&& array_key_exists($expression, $this->types)
|
||||
) {
|
||||
return 'hh.state_type ' . $sign . ' ' . $this->types[$expression];
|
||||
} else {
|
||||
return parent::whereToSql($col, $sign, $expression);
|
||||
if (! parent::isTimestamp($field)) {
|
||||
return $field === 'hh.state_time';
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -8,16 +8,13 @@ namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
|||
*/
|
||||
class ServicecommentdeletionhistoryQuery extends ServicecommenthistoryQuery
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function whereToSql($col, $sign, $expression)
|
||||
public function isTimestamp($field)
|
||||
{
|
||||
if ($col === 'UNIX_TIMESTAMP(sch.deletion_time)') {
|
||||
return 'sch.deletion_time ' . $sign . ' ' . $this->timestampForSql($this->valueToTimestamp($expression));
|
||||
} else {
|
||||
return parent::whereToSql($col, $sign, $expression);
|
||||
if (! parent::isTimestamp($field)) {
|
||||
return $field === 'sch.deletion_time';
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -44,7 +44,7 @@ class ServicecommenthistoryQuery extends IdoQuery
|
|||
'service_host' => 'so.name1 COLLATE latin1_general_ci',
|
||||
'service_host_name' => 'so.name1',
|
||||
'state' => '(-1)',
|
||||
'timestamp' => 'UNIX_TIMESTAMP(sch.comment_time)',
|
||||
'timestamp' => 'sch.comment_time',
|
||||
'type' => "(CASE sch.entry_type WHEN 1 THEN 'comment' WHEN 2 THEN 'dt_comment' WHEN 3 THEN 'flapping' WHEN 4 THEN 'ack' END)"
|
||||
),
|
||||
'hostgroups' => array(
|
||||
|
@ -69,16 +69,13 @@ class ServicecommenthistoryQuery extends IdoQuery
|
|||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function whereToSql($col, $sign, $expression)
|
||||
public function isTimestamp($field)
|
||||
{
|
||||
if ($col === 'UNIX_TIMESTAMP(sch.comment_time)') {
|
||||
return 'sch.comment_time ' . $sign . ' ' . $this->timestampForSql($this->valueToTimestamp($expression));
|
||||
} else {
|
||||
return parent::whereToSql($col, $sign, $expression);
|
||||
if (! parent::isTimestamp($field)) {
|
||||
return $field === 'sch.comment_time';
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -8,18 +8,13 @@ namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
|||
*/
|
||||
class ServicedowntimeendhistoryQuery extends ServicedowntimestarthistoryQuery
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function whereToSql($col, $sign, $expression)
|
||||
public function isTimestamp($field)
|
||||
{
|
||||
if ($col === 'UNIX_TIMESTAMP(sdh.actual_end_time)') {
|
||||
return 'sdh.actual_end_time ' . $sign . ' ' . $this->timestampForSql(
|
||||
$this->valueToTimestamp($expression)
|
||||
);
|
||||
} else {
|
||||
return parent::whereToSql($col, $sign, $expression);
|
||||
if (! parent::isTimestamp($field)) {
|
||||
return $field === 'sdh.actual_end_time';
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -44,7 +44,7 @@ class ServicedowntimestarthistoryQuery extends IdoQuery
|
|||
'service_host' => 'so.name1 COLLATE latin1_general_ci',
|
||||
'service_host_name' => 'so.name1',
|
||||
'state' => '(-1)',
|
||||
'timestamp' => 'UNIX_TIMESTAMP(sdh.actual_start_time)',
|
||||
'timestamp' => 'sdh.actual_start_time',
|
||||
'type' => "('dt_start')"
|
||||
),
|
||||
'hostgroups' => array(
|
||||
|
@ -69,18 +69,13 @@ class ServicedowntimestarthistoryQuery extends IdoQuery
|
|||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function whereToSql($col, $sign, $expression)
|
||||
public function isTimestamp($field)
|
||||
{
|
||||
if ($col === 'UNIX_TIMESTAMP(sdh.actual_start_time)') {
|
||||
return 'sdh.actual_start_time ' . $sign . ' ' . $this->timestampForSql(
|
||||
$this->valueToTimestamp($expression)
|
||||
);
|
||||
} else {
|
||||
return parent::whereToSql($col, $sign, $expression);
|
||||
if (! parent::isTimestamp($field)) {
|
||||
return $field === 'sdh.actual_start_time';
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -43,7 +43,7 @@ class ServiceflappingstarthistoryQuery extends IdoQuery
|
|||
'service_description' => 'so.name2',
|
||||
'service_host_name' => 'so.name1',
|
||||
'state' => '(-1)',
|
||||
'timestamp' => 'UNIX_TIMESTAMP(sfh.event_time)',
|
||||
'timestamp' => 'sfh.event_time',
|
||||
'type' => "('flapping')"
|
||||
),
|
||||
'hostgroups' => array(
|
||||
|
@ -68,18 +68,13 @@ class ServiceflappingstarthistoryQuery extends IdoQuery
|
|||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function whereToSql($col, $sign, $expression)
|
||||
public function isTimestamp($field)
|
||||
{
|
||||
if ($col === 'UNIX_TIMESTAMP(sfh.event_time)') {
|
||||
return 'sfh.event_time ' . $sign . ' ' . $this->timestampForSql(
|
||||
$this->valueToTimestamp($expression)
|
||||
);
|
||||
} else {
|
||||
return parent::whereToSql($col, $sign, $expression);
|
||||
if (! parent::isTimestamp($field)) {
|
||||
return $field === 'sfh.event_time';
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
|
||||
namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
||||
|
||||
use Icinga\Data\Filter\Filter;
|
||||
use Icinga\Data\Filter\FilterExpression;
|
||||
|
||||
/**
|
||||
* Query for service notifications
|
||||
*/
|
||||
|
@ -28,7 +31,7 @@ class ServicenotificationQuery extends IdoQuery
|
|||
'history' => array(
|
||||
'output' => null,
|
||||
'state' => 'sn.state',
|
||||
'timestamp' => 'UNIX_TIMESTAMP(sn.start_time)',
|
||||
'timestamp' => 'sn.start_time',
|
||||
'type' => '
|
||||
CASE sn.notification_reason
|
||||
WHEN 1 THEN \'notification_ack\'
|
||||
|
@ -60,7 +63,7 @@ class ServicenotificationQuery extends IdoQuery
|
|||
'notification_output' => 'sn.output',
|
||||
'notification_reason' => 'sn.notification_reason',
|
||||
'notification_state' => 'sn.state',
|
||||
'notification_timestamp' => 'UNIX_TIMESTAMP(sn.start_time)',
|
||||
'notification_timestamp' => 'sn.start_time',
|
||||
'object_type' => '(\'service\')',
|
||||
'service' => 'so.name2 COLLATE latin1_general_ci',
|
||||
'service_description' => 'so.name2',
|
||||
|
@ -76,18 +79,24 @@ class ServicenotificationQuery extends IdoQuery
|
|||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function whereToSql($col, $sign, $expression)
|
||||
protected function requireFilterColumns(Filter $filter)
|
||||
{
|
||||
if ($col === 'UNIX_TIMESTAMP(sn.start_time)') {
|
||||
return 'sn.start_time ' . $sign . ' ' . $this->timestampForSql($this->valueToTimestamp($expression));
|
||||
} elseif ($col === $this->columnMap['history']['output']) {
|
||||
return parent::whereToSql('sn.output', $sign, $expression);
|
||||
} else {
|
||||
return parent::whereToSql($col, $sign, $expression);
|
||||
if ($filter instanceof FilterExpression && $filter->getColumn() === 'output') {
|
||||
$this->requireColumn($filter->getColumn());
|
||||
$filter->setColumn('sn.output');
|
||||
return null;
|
||||
}
|
||||
|
||||
return parent::requireFilterColumns($filter);
|
||||
}
|
||||
|
||||
public function isTimestamp($field)
|
||||
{
|
||||
if (! parent::isTimestamp($field)) {
|
||||
return $field === 'sn.start_time';
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -74,26 +74,18 @@ class ServicestatehistoryQuery extends IdoQuery
|
|||
'service_host' => 'so.name1 COLLATE latin1_general_ci',
|
||||
'service_host_name' => 'so.name1',
|
||||
'state' => 'sh.state',
|
||||
'timestamp' => 'UNIX_TIMESTAMP(sh.state_time)',
|
||||
'timestamp' => 'sh.state_time',
|
||||
'type' => "(CASE WHEN sh.state_type = 1 THEN 'hard_state' ELSE 'soft_state' END)"
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function whereToSql($col, $sign, $expression)
|
||||
public function isTimestamp($field)
|
||||
{
|
||||
if ($col === 'UNIX_TIMESTAMP(sh.state_time)') {
|
||||
return 'sh.state_time ' . $sign . ' ' . $this->timestampForSql($this->valueToTimestamp($expression));
|
||||
} elseif ($col === $this->columnMap['statehistory']['type']
|
||||
&& ! is_array($expression)
|
||||
&& array_key_exists($expression, $this->types)
|
||||
) {
|
||||
return 'sh.state_type ' . $sign . ' ' . $this->types[$expression];
|
||||
} else {
|
||||
return parent::whereToSql($col, $sign, $expression);
|
||||
if (! parent::isTimestamp($field)) {
|
||||
return $field === 'sh.state_time';
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -197,23 +197,6 @@ class MonitoringBackend implements Selectable, Queryable, ConnectionInterface
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a backend
|
||||
*
|
||||
* @deprecated
|
||||
*
|
||||
* @param string $backendName Name of the backend or null for creating the default backend which is the first INI
|
||||
* configuration entry not being disabled
|
||||
*
|
||||
* @return Backend
|
||||
* @throws ConfigurationError When no backend has been configured or all backends are disabled or the
|
||||
* configuration for the requested backend does either not exist or it's disabled
|
||||
*/
|
||||
public static function createBackend($name = null)
|
||||
{
|
||||
return self::instance($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get this backend's internal resource
|
||||
*
|
||||
|
|
|
@ -9,6 +9,7 @@ use Icinga\Exception\QueryException;
|
|||
use Icinga\Data\Filter\Filter;
|
||||
use Icinga\Data\Filterable;
|
||||
use Icinga\File\Csv;
|
||||
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
|
||||
use Icinga\Module\Monitoring\Data\CustomvarProtectionIterator;
|
||||
use Icinga\Util\Json;
|
||||
use Icinga\Web\Controller as IcingaWebController;
|
||||
|
@ -22,13 +23,13 @@ class Controller extends IcingaWebController
|
|||
/**
|
||||
* The backend used for this controller
|
||||
*
|
||||
* @var Backend
|
||||
* @var MonitoringBackend
|
||||
*/
|
||||
protected $backend;
|
||||
|
||||
protected function moduleInit()
|
||||
{
|
||||
$this->backend = Backend::createBackend($this->_getParam('backend'));
|
||||
$this->backend = MonitoringBackend::instance($this->_getParam('backend'));
|
||||
$this->view->url = Url::fromRequest();
|
||||
}
|
||||
|
||||
|
|
|
@ -123,23 +123,6 @@ abstract class DataView implements QueryInterface, SortRules, FilterColumns, Ite
|
|||
*/
|
||||
abstract public function getColumns();
|
||||
|
||||
/**
|
||||
* Create view from request
|
||||
*
|
||||
* @param Request $request
|
||||
* @param array $columns
|
||||
*
|
||||
* @return static
|
||||
* @deprecated Use $backend->select()->from($viewName) instead
|
||||
*/
|
||||
public static function fromRequest($request, array $columns = null)
|
||||
{
|
||||
$view = new static(MonitoringBackend::instance($request->getParam('backend')), $columns);
|
||||
$view->applyUrlFilter($request);
|
||||
|
||||
return $view;
|
||||
}
|
||||
|
||||
protected function getHookedColumns()
|
||||
{
|
||||
$columns = array();
|
||||
|
@ -152,26 +135,6 @@ abstract class DataView implements QueryInterface, SortRules, FilterColumns, Ite
|
|||
return $columns;
|
||||
}
|
||||
|
||||
// TODO: This is not the right place for this, move it away
|
||||
protected function applyUrlFilter($request = null)
|
||||
{
|
||||
$url = Url::fromRequest();
|
||||
|
||||
$limit = $url->shift('limit');
|
||||
$sort = $url->shift('sort');
|
||||
$dir = $url->shift('dir');
|
||||
$page = $url->shift('page');
|
||||
$format = $url->shift('format');
|
||||
$view = $url->shift('showCompact');
|
||||
$view = $url->shift('backend');
|
||||
foreach ($url->getParams() as $k => $v) {
|
||||
$this->where($k, $v);
|
||||
}
|
||||
if ($sort) {
|
||||
$this->order($sort, $dir);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create view from params
|
||||
*
|
||||
|
@ -200,7 +163,7 @@ abstract class DataView implements QueryInterface, SortRules, FilterColumns, Ite
|
|||
}
|
||||
}
|
||||
|
||||
$view->sort($params['sort'], $order);
|
||||
$view->order($params['sort'], $order);
|
||||
}
|
||||
return $view;
|
||||
}
|
||||
|
@ -324,18 +287,14 @@ abstract class DataView implements QueryInterface, SortRules, FilterColumns, Ite
|
|||
}
|
||||
|
||||
/**
|
||||
* Sort the rows, according to the specified sort column and order
|
||||
* Sort result set either by the given column (and direction) or the sort defaults
|
||||
*
|
||||
* @param string $column Sort column
|
||||
* @param string $order Sort order, one of the SORT_ constants
|
||||
* @param string $column
|
||||
* @param string $direction
|
||||
*
|
||||
* @return $this
|
||||
* @throws QueryException If the sort column is not allowed
|
||||
* @see DataView::SORT_ASC
|
||||
* @see DataView::SORT_DESC
|
||||
* @deprecated Use DataView::order() instead
|
||||
* @return $this
|
||||
*/
|
||||
public function sort($column = null, $order = null)
|
||||
public function order($column = null, $direction = null)
|
||||
{
|
||||
$sortRules = $this->getSortRules();
|
||||
if ($column === null) {
|
||||
|
@ -356,16 +315,16 @@ abstract class DataView implements QueryInterface, SortRules, FilterColumns, Ite
|
|||
} else {
|
||||
$sortColumns = array(
|
||||
'columns' => array($column),
|
||||
'order' => $order
|
||||
'order' => $direction
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
$order = $order === null ? (isset($sortColumns['order']) ? $sortColumns['order'] : static::SORT_ASC) : $order;
|
||||
$order = (strtoupper($order) === static::SORT_ASC) ? 'ASC' : 'DESC';
|
||||
$direction = $direction === null ? ($sortColumns['order'] ?? static::SORT_ASC) : $direction;
|
||||
$direction = (strtoupper($direction) === static::SORT_ASC) ? 'ASC' : 'DESC';
|
||||
|
||||
foreach ($sortColumns['columns'] as $column) {
|
||||
list($column, $direction) = $this->query->splitOrder($column);
|
||||
list($column, $order) = $this->query->splitOrder($column);
|
||||
if (! $this->isValidFilterTarget($column)) {
|
||||
throw new QueryException(
|
||||
mt('monitoring', 'The sort column "%s" is not allowed in "%s".'),
|
||||
|
@ -373,7 +332,7 @@ abstract class DataView implements QueryInterface, SortRules, FilterColumns, Ite
|
|||
get_class($this)
|
||||
);
|
||||
}
|
||||
$this->query->order($column, $direction !== null ? $direction : $order);
|
||||
$this->query->order($column, $order !== null ? $order : $direction);
|
||||
}
|
||||
$this->isSorted = true;
|
||||
return $this;
|
||||
|
@ -389,19 +348,6 @@ abstract class DataView implements QueryInterface, SortRules, FilterColumns, Ite
|
|||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort result set either by the given column (and direction) or the sort defaults
|
||||
*
|
||||
* @param string $column
|
||||
* @param string $direction
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function order($column = null, $direction = null)
|
||||
{
|
||||
return $this->sort($column, $direction);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether an order is set
|
||||
*
|
||||
|
|
|
@ -1,57 +0,0 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2013 Icinga Development Team | GPLv2+ */
|
||||
|
||||
namespace Icinga\Module\Monitoring;
|
||||
|
||||
class Environment
|
||||
{
|
||||
protected static $envs = array(
|
||||
'default' => array(
|
||||
'backend' => null,
|
||||
'grapher' => null,
|
||||
'configBackend' => null,
|
||||
'commandPipe' => null,
|
||||
)
|
||||
);
|
||||
|
||||
public static function defaultName()
|
||||
{
|
||||
// TODO: Check session
|
||||
reset(self::$envs);
|
||||
return key(self::$envs);
|
||||
}
|
||||
|
||||
protected static function config($env, $what)
|
||||
{
|
||||
return self::$config[self::getName($env)][$what];
|
||||
}
|
||||
|
||||
protected static function getName($env)
|
||||
{
|
||||
return $env === null ? self::defaultName() : $env;
|
||||
}
|
||||
|
||||
public static function backend($env = null)
|
||||
{
|
||||
return Backend::getInstance(self::config($env, 'backend'));
|
||||
}
|
||||
|
||||
public static function grapher($env = null)
|
||||
{
|
||||
return Hook::createInstance('grapher', null, self::config($env, 'grapher'));
|
||||
}
|
||||
|
||||
public static function configBackend($env = null)
|
||||
{
|
||||
return Hook::createInstance(
|
||||
'configBackend',
|
||||
null,
|
||||
self::config($env, 'configBackend')
|
||||
);
|
||||
}
|
||||
|
||||
public static function commandPipe($env = null)
|
||||
{
|
||||
return CommandPipe::getInstance(self::config($env, 'commandPipe'));
|
||||
}
|
||||
}
|
|
@ -234,30 +234,6 @@ abstract class MonitoredObject implements Filterable
|
|||
// Left out on purpose. Interface is deprecated.
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether this object matches the given filter
|
||||
*
|
||||
* @param Filter $filter
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws ProgrammingError In case the object cannot be found
|
||||
*
|
||||
* @deprecated Use $filter->matches($object) instead
|
||||
*/
|
||||
public function matches(Filter $filter)
|
||||
{
|
||||
if ($this->properties === null && $this->fetch() === false) {
|
||||
throw new ProgrammingError(
|
||||
'Unable to apply filter. Object %s of type %s not found.',
|
||||
$this->getName(),
|
||||
$this->getType()
|
||||
);
|
||||
}
|
||||
|
||||
return $filter->matches($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Require the object's type to be one of the given types
|
||||
*
|
||||
|
@ -951,17 +927,4 @@ abstract class MonitoredObject implements Filterable
|
|||
|
||||
throw new InvalidPropertyException('Can\'t access property \'%s\'. Property does not exist.', $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
public static function fromParams(UrlParams $params)
|
||||
{
|
||||
if ($params->has('service') && $params->has('host')) {
|
||||
return new Service(MonitoringBackend::instance(), $params->get('host'), $params->get('service'));
|
||||
} elseif ($params->has('host')) {
|
||||
return new Host(MonitoringBackend::instance(), $params->get('host'));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ namespace Icinga\Module\Monitoring\ProvidedHook;
|
|||
|
||||
use Icinga\Application\Hook\HealthHook;
|
||||
use Icinga\Date\DateFormatter;
|
||||
use Icinga\Module\Monitoring\Backend;
|
||||
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
|
||||
use ipl\Web\Url;
|
||||
|
||||
class Health extends HealthHook
|
||||
|
@ -25,7 +25,7 @@ class Health extends HealthHook
|
|||
|
||||
public function checkHealth()
|
||||
{
|
||||
$backendName = Backend::instance()->getName();
|
||||
$backendName = MonitoringBackend::instance()->getName();
|
||||
$programStatus = $this->getProgramStatus();
|
||||
if ($programStatus === false) {
|
||||
$this->setState(self::STATE_UNKNOWN);
|
||||
|
@ -55,7 +55,7 @@ class Health extends HealthHook
|
|||
protected function getProgramStatus()
|
||||
{
|
||||
if ($this->programStatus === null) {
|
||||
$this->programStatus = Backend::instance()->select()
|
||||
$this->programStatus = MonitoringBackend::instance()->select()
|
||||
->from('programstatus', [
|
||||
'program_version',
|
||||
'status_update_time',
|
||||
|
|
|
@ -9,7 +9,7 @@ require_once realpath(dirname(__FILE__) . '/../../../../../test/php/bootstrap.ph
|
|||
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Data\ConfigObject;
|
||||
use Icinga\Module\Monitoring\Backend;
|
||||
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
use Mockery;
|
||||
|
||||
|
@ -53,7 +53,7 @@ class Bug7043Test extends BaseTestCase
|
|||
)
|
||||
)));
|
||||
|
||||
$defaultBackend = Backend::createBackend();
|
||||
$defaultBackend = MonitoringBackend::instance();
|
||||
|
||||
$this->assertEquals('backendName', $defaultBackend->getName(), 'Default backend has name set');
|
||||
}
|
||||
|
|
|
@ -443,21 +443,6 @@
|
|||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Add the specified flag to the given URL
|
||||
*
|
||||
* @param {string} url
|
||||
* @param {string} flag
|
||||
*
|
||||
* @returns {string}
|
||||
*
|
||||
* @deprecated since version 2.8.0. Use {@link Icinga.Utils.addUrlFlag()} instead
|
||||
*/
|
||||
addUrlFlag: function(url, flag)
|
||||
{
|
||||
return this.icinga.utils.addUrlFlag(url, flag);
|
||||
},
|
||||
|
||||
/**
|
||||
* Process the X-Icinga-Redirect HTTP Response Header
|
||||
*
|
||||
|
|
|
@ -25,7 +25,7 @@ class BaseTestCaseTest extends BaseTestCase
|
|||
public function testWhetherMySqlProviderAnnotationSetsUpZendDbAdapter($resource)
|
||||
{
|
||||
$this->setupDbProvider($resource);
|
||||
$this->assertInstanceOf('Zend_Db_Adapter_Pdo_Mysql', $resource->getConnection());
|
||||
$this->assertInstanceOf('Zend_Db_Adapter_Pdo_Mysql', $resource->getDbAdapter());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -43,7 +43,7 @@ class BaseTestCaseTest extends BaseTestCase
|
|||
public function testWhetherCreatingTablesWithMySqlAdapterWorks($resource)
|
||||
{
|
||||
$this->setupDbProvider($resource);
|
||||
$adapter = $resource->getConnection();
|
||||
$adapter = $resource->getDbAdapter();
|
||||
$adapter->exec('CREATE TABLE test(uid INT NOT NULL PRIMARY KEY);');
|
||||
|
||||
$tables = $adapter->listTables();
|
||||
|
@ -58,7 +58,7 @@ class BaseTestCaseTest extends BaseTestCase
|
|||
{
|
||||
$this->setupDbProvider($resource);
|
||||
|
||||
$tables = $resource->getConnection()->listTables();
|
||||
$tables = $resource->getDbAdapter()->listTables();
|
||||
$this->assertCount(0, $tables);
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,7 @@ class BaseTestCaseTest extends BaseTestCase
|
|||
public function testWhetherPgSqlProviderAnnotationSetsUpZendDbAdapter($resource)
|
||||
{
|
||||
$this->setupDbProvider($resource);
|
||||
$this->assertInstanceOf('Zend_Db_Adapter_Pdo_Pgsql', $resource->getConnection());
|
||||
$this->assertInstanceOf('Zend_Db_Adapter_Pdo_Pgsql', $resource->getDbAdapter());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -86,7 +86,7 @@ class BaseTestCaseTest extends BaseTestCase
|
|||
public function testWhetherCreatingTablesWithPgSqlAdapterWorks($resource)
|
||||
{
|
||||
$this->setupDbProvider($resource);
|
||||
$adapter = $resource->getConnection();
|
||||
$adapter = $resource->getDbAdapter();
|
||||
$adapter->exec('CREATE TABLE test(uid INT NOT NULL PRIMARY KEY);');
|
||||
|
||||
$tables = $adapter->listTables();
|
||||
|
@ -101,7 +101,7 @@ class BaseTestCaseTest extends BaseTestCase
|
|||
{
|
||||
$this->setupDbProvider($resource);
|
||||
|
||||
$tables = $resource->getConnection()->listTables();
|
||||
$tables = $resource->getDbAdapter()->listTables();
|
||||
$this->assertCount(0, $tables);
|
||||
}
|
||||
|
||||
|
@ -111,7 +111,7 @@ class BaseTestCaseTest extends BaseTestCase
|
|||
public function testWhetherOciProviderAnnotationSetsUpZendDbAdapter($resource)
|
||||
{
|
||||
$this->setupDbProvider($resource);
|
||||
$this->assertInstanceOf('Zend_Db_Adapter_Pdo_Oci', $resource->getConnection());
|
||||
$this->assertInstanceOf('Zend_Db_Adapter_Pdo_Oci', $resource->getDbAdapter());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -129,7 +129,7 @@ class BaseTestCaseTest extends BaseTestCase
|
|||
public function testWhetherCreatingTablesWithOciAdapterWorks($resource)
|
||||
{
|
||||
$this->setupDbProvider($resource);
|
||||
$adapter = $resource->getConnection();
|
||||
$adapter = $resource->getDbAdapter();
|
||||
$adapter->exec('CREATE TABLE test(uid INT NOT NULL PRIMARY KEY);');
|
||||
|
||||
$tables = $adapter->listTables();
|
||||
|
@ -144,7 +144,7 @@ class BaseTestCaseTest extends BaseTestCase
|
|||
{
|
||||
$this->setupDbProvider($resource);
|
||||
|
||||
$tables = $resource->getConnection()->listTables();
|
||||
$tables = $resource->getDbAdapter()->listTables();
|
||||
$this->assertCount(0, $tables);
|
||||
}
|
||||
|
||||
|
@ -176,7 +176,7 @@ class BaseTestCaseTest extends BaseTestCase
|
|||
|
||||
$this->loadSql($resource, $tempFile);
|
||||
|
||||
$count = (int) $resource->getConnection()->fetchOne('SELECT COUNT(*) as cntX from dummyData;');
|
||||
$count = (int) $resource->getDbAdapter()->fetchOne('SELECT COUNT(*) as cntX from dummyData;');
|
||||
$this->assertSame(20, $count);
|
||||
|
||||
$this->assertTrue(unlink($tempFile));
|
||||
|
|
Loading…
Reference in New Issue