mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-29 16:54:06 +02:00
Db: add methods to store and fetch settings
This commit is contained in:
parent
b551651f7e
commit
ea327ed4ec
@ -15,11 +15,68 @@ class Db extends DbConnection
|
|||||||
|
|
||||||
protected static $commandCache;
|
protected static $commandCache;
|
||||||
|
|
||||||
|
protected $settings;
|
||||||
|
|
||||||
protected function db()
|
protected function db()
|
||||||
{
|
{
|
||||||
return $this->getDbAdapter();
|
return $this->getDbAdapter();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getSetting($name, $default = null)
|
||||||
|
{
|
||||||
|
if ($this->settings === null) {
|
||||||
|
$this->fetchSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (array_key_exists($name, $this->settings)) {
|
||||||
|
return $this->settings[$name];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $default;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function storeSetting($name, $value)
|
||||||
|
{
|
||||||
|
$db = $this->db();
|
||||||
|
$db->beginTransaction();
|
||||||
|
$updated = $db->update(
|
||||||
|
'director_setting',
|
||||||
|
array('setting_value' => $value),
|
||||||
|
$db->quoteInto('setting_name = ?', $name)
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($updated === 0) {
|
||||||
|
$db->insert(
|
||||||
|
'director_setting',
|
||||||
|
array(
|
||||||
|
'setting_name' => $name,
|
||||||
|
'setting_value' => $value,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$db->commit();
|
||||||
|
if ($this->settings !== null) {
|
||||||
|
$this->settings[$name] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function fetchSettings($force = true)
|
||||||
|
{
|
||||||
|
if ($force || $this->settings === null) {
|
||||||
|
$db = $this->db();
|
||||||
|
$query = $db->select()->from(
|
||||||
|
array('s' => 'director_setting'),
|
||||||
|
array('setting_name', 'setting_value')
|
||||||
|
);
|
||||||
|
$this->settings = (array) $db->fetchPairs($query);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->settings;
|
||||||
|
}
|
||||||
|
|
||||||
public function getActivitylogNeighbors($id, $type = null, $name = null)
|
public function getActivitylogNeighbors($id, $type = null, $name = null)
|
||||||
{
|
{
|
||||||
$db = $this->db();
|
$db = $this->db();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user