diff --git a/doc/80-Upgrading.md b/doc/80-Upgrading.md index c8844e444..ca9fbd164 100644 --- a/doc/80-Upgrading.md +++ b/doc/80-Upgrading.md @@ -39,6 +39,7 @@ v2.6 to v2.8 requires to follow the instructions for v2.7 too. + `MonitoringBackend::createBackend()`: Use `MonitoringBackend::instance()` instead. + `DbConnection::getConnection()`: Use `Connection::getDbAdapter()` instead. + `DbQuery::renderFilter()`: Use `DbConnection::renderFilter()` instead. ++ `DbQuery::whereToSql()`: Use `DbConnection::renderFilter()` instead. **Classes:** + `Icinga\Util\String`: Use `Icinga\Util\StringHelper` instead. diff --git a/library/Icinga/Data/Db/DbQuery.php b/library/Icinga/Data/Db/DbQuery.php index fea82179b..25acd8905 100644 --- a/library/Icinga/Data/Db/DbQuery.php +++ b/library/Icinga/Data/Db/DbQuery.php @@ -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; @@ -210,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; } @@ -258,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'); } /** @@ -279,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 * diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommentdeletionhistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommentdeletionhistoryQuery.php index e9021f2ec..b602f8a69 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommentdeletionhistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommentdeletionhistoryQuery.php @@ -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; } /** diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommenthistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommenthistoryQuery.php index ddfc4c026..d7a25e054 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommenthistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommenthistoryQuery.php @@ -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; } /** diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimeendhistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimeendhistoryQuery.php index 16857e00a..8df59c7b3 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimeendhistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimeendhistoryQuery.php @@ -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; } /** diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimestarthistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimestarthistoryQuery.php index 5d0517884..ae3df5ffa 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimestarthistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimestarthistoryQuery.php @@ -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; } /** diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostflappingstarthistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostflappingstarthistoryQuery.php index c09e4ac8a..3532b72f5 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostflappingstarthistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostflappingstarthistoryQuery.php @@ -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; } /** diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostnotificationQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostnotificationQuery.php index ff54b3eac..052873f77 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostnotificationQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostnotificationQuery.php @@ -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; } /** diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatehistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatehistoryQuery.php index 565804e3b..7321d1a87 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatehistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatehistoryQuery.php @@ -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; } /** diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommentdeletionhistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommentdeletionhistoryQuery.php index c5ad15553..1f134b2a2 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommentdeletionhistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommentdeletionhistoryQuery.php @@ -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; } /** diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommenthistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommenthistoryQuery.php index afa7772f0..0a3183552 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommenthistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommenthistoryQuery.php @@ -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; } /** diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimeendhistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimeendhistoryQuery.php index 4ee2b6c54..0c7049f3d 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimeendhistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimeendhistoryQuery.php @@ -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; } /** diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimestarthistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimestarthistoryQuery.php index 932d854a0..be096ec9b 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimestarthistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimestarthistoryQuery.php @@ -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; } /** diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServiceflappingstarthistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServiceflappingstarthistoryQuery.php index f6f67f709..842166b25 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServiceflappingstarthistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServiceflappingstarthistoryQuery.php @@ -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; } /** diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicenotificationQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicenotificationQuery.php index 4188ee614..12e512da5 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicenotificationQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicenotificationQuery.php @@ -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; } /** diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatehistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatehistoryQuery.php index 8c0a89763..a1bab89ce 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatehistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatehistoryQuery.php @@ -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; } /**