mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-31 01:34:12 +02:00
CustomVariableCache: optionally use digest()...
...for PostgreSQL in case pgcrypto is installed. Also add related hint to the installation documentation
This commit is contained in:
parent
6f12663756
commit
1bc4a397a8
@ -35,8 +35,12 @@ command.
|
||||
|
||||
psql -q -c "CREATE DATABASE director WITH ENCODING 'UTF8';"
|
||||
psql director -q -c "CREATE USER director WITH PASSWORD 'some-password';
|
||||
GRANT ALL PRIVILEGES ON DATABASE director TO director;"
|
||||
GRANT ALL PRIVILEGES ON DATABASE director TO director;
|
||||
CREATE EXTENSION pgcrypto;"
|
||||
|
||||
Hint: pgcrypto helps to boost performance, but is currently optional. In case you
|
||||
do not have it available on your platform and/or do not know how to solve this
|
||||
just leave away the 'CREATE EXTENSION' part.
|
||||
|
||||
Web-based Configuration
|
||||
-----------------------
|
||||
|
@ -632,6 +632,17 @@ class Db extends DbConnection
|
||||
return $this->getDbType() === 'pgsql';
|
||||
}
|
||||
|
||||
public function hasPgExtension($name)
|
||||
{
|
||||
$db = $this->db();
|
||||
$query = $db->select()->from(
|
||||
array('e' => 'pg_extension'),
|
||||
array('cnt' => 'COUNT(*)')
|
||||
)->where('extname = ?', $name);
|
||||
|
||||
return (int) $db->fetchOne($query) === 1;
|
||||
}
|
||||
|
||||
public function dbHexFunc($column)
|
||||
{
|
||||
if ($this->isPgsql()) {
|
||||
|
@ -27,7 +27,11 @@ class CustomVariableCache
|
||||
'checksum' => '(NULL)',
|
||||
);
|
||||
|
||||
if (! $connection->isPgsql()) {
|
||||
if ($connection->isPgsql()) {
|
||||
if ($connection->hasPgExtension('pgcrypto')) {
|
||||
$columns['checksum'] = "DIGEST(v.varvalue || ';' || v.format, 'sha1')";
|
||||
}
|
||||
} else {
|
||||
$columns['checksum'] = "UNHEX(SHA1(v.varvalue || ';' || v.format))";
|
||||
}
|
||||
|
||||
@ -41,6 +45,10 @@ class CustomVariableCache
|
||||
$id = $row->id;
|
||||
unset($row->id);
|
||||
|
||||
if (is_resource($row->checksum)) {
|
||||
$row->checksum = stream_get_contents($row->checksum);
|
||||
}
|
||||
|
||||
if (array_key_exists($id, $this->rowsById)) {
|
||||
$this->rowsById[$id][] = $row;
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user