Merge branch 'bugfix/filter-custom-variables-9692'

fixes #9692
This commit is contained in:
Eric Lippmann 2015-07-24 09:27:05 +02:00
commit 12856da971
2 changed files with 24 additions and 5 deletions

View File

@ -4,7 +4,7 @@
namespace Icinga\Exception; namespace Icinga\Exception;
/** /**
* Exception thrown if a query contains invalid parameters * Exception thrown if a query encountered an error
*/ */
class QueryException extends IcingaException class QueryException extends IcingaException
{ {

View File

@ -12,6 +12,7 @@ use Icinga\Data\Filter\FilterExpression;
use Icinga\Exception\IcingaException; use Icinga\Exception\IcingaException;
use Icinga\Exception\NotImplementedError; use Icinga\Exception\NotImplementedError;
use Icinga\Exception\ProgrammingError; use Icinga\Exception\ProgrammingError;
use Icinga\Exception\QueryException;
use Icinga\Web\Session; use Icinga\Web\Session;
/** /**
@ -855,7 +856,6 @@ abstract class IdoQuery extends DbQuery
protected function customvarNameToTypeName($customvar) protected function customvarNameToTypeName($customvar)
{ {
$customvar = strtolower($customvar); $customvar = strtolower($customvar);
// TODO: Improve this:
if (! preg_match('~^_(host|service)_([a-zA-Z0-9_]+)$~', $customvar, $m)) { if (! preg_match('~^_(host|service)_([a-zA-Z0-9_]+)$~', $customvar, $m)) {
throw new ProgrammingError( throw new ProgrammingError(
'Got invalid custom var: "%s"', 'Got invalid custom var: "%s"',
@ -870,11 +870,20 @@ abstract class IdoQuery extends DbQuery
return array_key_exists($name, $this->joinedVirtualTables); return array_key_exists($name, $this->joinedVirtualTables);
} }
/**
* Get the query column of a already joined custom variable
*
* @param string $customvar
*
* @return string
* @throws QueryException If the custom variable has not been joined
*/
protected function getCustomvarColumnName($customvar) protected function getCustomvarColumnName($customvar)
{ {
if (isset($this->customVars[($customvar = strtolower($customvar))])) { if (! isset($this->customVars[($customvar = strtolower($customvar))])) {
$this->customVars[strtolower($customvar)] . '.varvalue'; throw new QueryException('Custom variable %s has not been joined', $customvar);
} }
return $this->customVars[$customvar] . '.varvalue';
} }
public function aliasToColumnName($alias) public function aliasToColumnName($alias)
@ -882,10 +891,20 @@ abstract class IdoQuery extends DbQuery
return $this->idxAliasColumn[$alias]; return $this->idxAliasColumn[$alias];
} }
/**
* Get the alias of a column expression as defined in the {@link $columnMap} property.
*
* @param string $alias Potential custom alias
*
* @return string
*/
public function customAliasToAlias($alias) public function customAliasToAlias($alias)
{ {
if (isset($this->idxCustomAliases[$alias])) {
return $this->idxCustomAliases[$alias]; return $this->idxCustomAliases[$alias];
} }
return $alias;
}
/** /**
* Create a sub query * Create a sub query