mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-22 21:34:28 +02:00
IdoQueryExtensionHook: "just a new hook"
This commit is contained in:
parent
6394cec933
commit
b7352105d2
@ -5,6 +5,7 @@ namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
|||||||
|
|
||||||
use Zend_Db_Expr;
|
use Zend_Db_Expr;
|
||||||
use Icinga\Application\Icinga;
|
use Icinga\Application\Icinga;
|
||||||
|
use Icinga\Application\Hook;
|
||||||
use Icinga\Application\Logger;
|
use Icinga\Application\Logger;
|
||||||
use Icinga\Data\Db\DbQuery;
|
use Icinga\Data\Db\DbQuery;
|
||||||
use Icinga\Data\Filter\Filter;
|
use Icinga\Data\Filter\Filter;
|
||||||
@ -119,6 +120,15 @@ abstract class IdoQuery extends DbQuery
|
|||||||
*/
|
*/
|
||||||
protected $joinedVirtualTables = array();
|
protected $joinedVirtualTables = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A map of virtual table names and corresponding hook instances
|
||||||
|
*
|
||||||
|
* Joins for those tables will be delegated to them
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $hookedVirtualTables = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List of column aliases used for sorting the result
|
* List of column aliases used for sorting the result
|
||||||
*
|
*
|
||||||
@ -593,6 +603,18 @@ abstract class IdoQuery extends DbQuery
|
|||||||
return isset($this->caseInsensitiveColumns[$table][$alias]);
|
return isset($this->caseInsensitiveColumns[$table][$alias]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return our column map
|
||||||
|
*
|
||||||
|
* Might be useful for hooks
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getColumnMap()
|
||||||
|
{
|
||||||
|
return $this->columnMap;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply oracle specific query initialization
|
* Apply oracle specific query initialization
|
||||||
*/
|
*/
|
||||||
@ -651,6 +673,23 @@ abstract class IdoQuery extends DbQuery
|
|||||||
{
|
{
|
||||||
parent::init();
|
parent::init();
|
||||||
$this->prefix = $this->ds->getTablePrefix();
|
$this->prefix = $this->ds->getTablePrefix();
|
||||||
|
|
||||||
|
foreach (Hook::all('monitoring/idoQueryExtension') as $hook) {
|
||||||
|
$extensions = $hook->extendColumnMap($this);
|
||||||
|
if (! is_array($extensions)) continue;
|
||||||
|
|
||||||
|
foreach ($extensions as $vTable => $cols) {
|
||||||
|
if (! array_key_exists($vTable, $this->columnMap)) {
|
||||||
|
$this->hookedVirtualTables[$vTable] = $hook;
|
||||||
|
$this->columMap[$vTable] = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($cols as $k => $v) {
|
||||||
|
$this->columnMap[$vTable][$k] = $v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$dbType = $this->ds->getDbType();
|
$dbType = $this->ds->getDbType();
|
||||||
if ($dbType === 'oracle') {
|
if ($dbType === 'oracle') {
|
||||||
$this->initializeForOracle();
|
$this->initializeForOracle();
|
||||||
@ -787,7 +826,24 @@ abstract class IdoQuery extends DbQuery
|
|||||||
if ($this->hasJoinedVirtualTable($name)) {
|
if ($this->hasJoinedVirtualTable($name)) {
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
return $this->joinVirtualTable($name);
|
|
||||||
|
if ($this->virtualTableIsHooked($name)) {
|
||||||
|
return $this->joinHookedVirtualTable($name);
|
||||||
|
} else {
|
||||||
|
return $this->joinVirtualTable($name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether a given virtual table name has been provided by a hook
|
||||||
|
*
|
||||||
|
* @param string $name Virtual table name
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
protected function virtualTableIsHooked($name)
|
||||||
|
{
|
||||||
|
return array_key_exists($name, $this->hookedVirtualTables);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function conflictsWithVirtualTable($name)
|
protected function conflictsWithVirtualTable($name)
|
||||||
|
@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
||||||
|
|
||||||
|
namespace Icinga\Module\Monitoring\Hook;
|
||||||
|
|
||||||
|
use Icinga\Module\Monitoring\Backend\Ido\Query\IdoQuery;
|
||||||
|
|
||||||
|
abstract class IdoQueryExtensionHook
|
||||||
|
{
|
||||||
|
abstract public function extendColumnMap(IdoQuery $query);
|
||||||
|
|
||||||
|
public function joinVirtualTable(IdoQuery $query, $virtualTable)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user