mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2026-05-28 04:35:53 -04:00
DbObjectWithSettings: no return value for __unset
This commit is contained in:
parent
1999de2707
commit
41aa86188f
1 changed files with 14 additions and 11 deletions
|
|
@ -2,13 +2,18 @@
|
|||
|
||||
namespace Icinga\Module\Director\Data\Db;
|
||||
|
||||
use Icinga\Module\Director\Db;
|
||||
|
||||
abstract class DbObjectWithSettings extends DbObject
|
||||
{
|
||||
/** @var Db $connection */
|
||||
protected $connection;
|
||||
|
||||
protected $settingsTable = 'your_table_name';
|
||||
|
||||
protected $settingsRemoteId = 'column_pointing_to_main_table_id';
|
||||
|
||||
protected $settings = array();
|
||||
protected $settings = [];
|
||||
|
||||
public function set($key, $value)
|
||||
{
|
||||
|
|
@ -54,15 +59,13 @@ abstract class DbObjectWithSettings extends DbObject
|
|||
public function __unset($key)
|
||||
{
|
||||
if ($this->hasProperty($key)) {
|
||||
return parent::__unset($key);
|
||||
parent::__unset($key);
|
||||
}
|
||||
|
||||
if (array_key_exists($key, $this->settings)) {
|
||||
unset($this->settings[$key]);
|
||||
$this->hasBeenModified = true;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function onStore()
|
||||
|
|
@ -70,9 +73,9 @@ abstract class DbObjectWithSettings extends DbObject
|
|||
$old = $this->fetchSettingsFromDb();
|
||||
$oldKeys = array_keys($old);
|
||||
$newKeys = array_keys($this->settings);
|
||||
$add = array();
|
||||
$mod = array();
|
||||
$del = array();
|
||||
$add = [];
|
||||
$mod = [];
|
||||
$del = [];
|
||||
$id = $this->get('id');
|
||||
|
||||
foreach ($this->settings as $key => $val) {
|
||||
|
|
@ -94,7 +97,7 @@ abstract class DbObjectWithSettings extends DbObject
|
|||
foreach ($mod as $key => $val) {
|
||||
$db->update(
|
||||
$this->settingsTable,
|
||||
array('setting_value' => $val),
|
||||
['setting_value' => $val],
|
||||
$db->quoteInto($where, $key)
|
||||
);
|
||||
}
|
||||
|
|
@ -102,11 +105,11 @@ abstract class DbObjectWithSettings extends DbObject
|
|||
foreach ($add as $key => $val) {
|
||||
$db->insert(
|
||||
$this->settingsTable,
|
||||
array(
|
||||
[
|
||||
$this->settingsRemoteId => $id,
|
||||
'setting_name' => $key,
|
||||
'setting_value' => $val
|
||||
)
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -121,7 +124,7 @@ abstract class DbObjectWithSettings extends DbObject
|
|||
$db = $this->getDb();
|
||||
return $db->fetchPairs(
|
||||
$db->select()
|
||||
->from($this->settingsTable, array('setting_name', 'setting_value'))
|
||||
->from($this->settingsTable, ['setting_name', 'setting_value'])
|
||||
->where($this->settingsRemoteId . ' = ?', $this->get('id'))
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue