diff --git a/contao/drivers/DC_Config.php b/contao/drivers/DC_Config.php index 151fa7b..1a281ef 100644 --- a/contao/drivers/DC_Config.php +++ b/contao/drivers/DC_Config.php @@ -101,15 +101,9 @@ public function __construct(string $strTable) } // Prefill on empty (only database) - if ($this->useDatabase) + if ($this->useDatabase && !!$GLOBALS['TL_DCA'][$this->strTable]['config']['fillOnEmpty'] && empty($this->getValuesFromDatabase())) { - $objDatabase = $this->Database->prepare("SELECT $this->column FROM $this->table WHERE id=?") - ->execute($this->intId); - - if (!!$GLOBALS['TL_DCA'][$this->strTable]['config']['fillOnEmpty'] && !$objDatabase->{$this->column}) - { - $this->prefillConfig(); - } + $this->prefillConfig(); } // Call onload_callback (e.g. to check permissions) @@ -142,10 +136,7 @@ private function prefillConfig(): void $arrDefaults[ $key ] = $field['default'] ?? ''; } - $deserialize = serialize($arrDefaults); - - $this->Database->prepare("UPDATE " . $this->table . " SET " . $this->column . "=? WHERE id=?") - ->execute($deserialize, $this->intId); + $this->updateConfig($arrDefaults); } /** @@ -702,10 +693,7 @@ protected function save($varValue): void $arrValues[$this->strField] = $varValue; - $deserialize = serialize($arrValues); - - $this->Database->prepare("UPDATE " . $this->table . " SET " . $this->column . "=? WHERE id=?") - ->execute($deserialize, $this->intId); + $this->updateConfig($arrValues); } else { @@ -742,6 +730,15 @@ protected function save($varValue): void } } + /** + * Updates the configuration in the database + */ + private function updateConfig(array $arrConfig): void + { + $this->Database->prepare("UPDATE " . $this->table . " SET " . $this->column . "=? WHERE id=?") + ->execute(serialize($arrConfig), $this->intId); + } + /** * Return the values of fields from database */