From 68c4726e517c3d34d33db4b37f3593b284326785 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Thu, 17 Mar 2022 12:05:04 +0100 Subject: [PATCH 1/2] Do not update _lastChanged on auto-detected attributes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- apps/user_ldap/lib/Configuration.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/user_ldap/lib/Configuration.php b/apps/user_ldap/lib/Configuration.php index ab5aa23f98d88..63390a60fd423 100644 --- a/apps/user_ldap/lib/Configuration.php +++ b/apps/user_ldap/lib/Configuration.php @@ -262,6 +262,7 @@ public function readConfiguration() { */ public function saveConfiguration() { $cta = array_flip($this->getConfigTranslationArray()); + $changed = false; foreach ($this->unsavedChanges as $key) { $value = $this->config[$key]; switch ($key) { @@ -291,9 +292,12 @@ public function saveConfiguration() { if (is_null($value)) { $value = ''; } + $changed = true; $this->saveValue($cta[$key], $value); } - $this->saveValue('_lastChange', time()); + if ($changed) { + $this->saveValue('_lastChange', (string)time()); + } $this->unsavedChanges = []; } From fd61479c46882064de6101a7d73a39410b5fb319 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Tue, 22 Mar 2022 14:53:37 +0100 Subject: [PATCH 2/2] Avoid updating _lastChange when nothing is changed in the configuration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Had to set at least one var when creating an empty configuration in order to save the default values. Signed-off-by: Côme Chilliet --- apps/user_ldap/lib/Command/CreateEmptyConfig.php | 1 + apps/user_ldap/lib/Configuration.php | 5 ++--- apps/user_ldap/lib/Controller/ConfigAPIController.php | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/apps/user_ldap/lib/Command/CreateEmptyConfig.php b/apps/user_ldap/lib/Command/CreateEmptyConfig.php index 8b1736e3a535f..f7f04e28e607c 100644 --- a/apps/user_ldap/lib/Command/CreateEmptyConfig.php +++ b/apps/user_ldap/lib/Command/CreateEmptyConfig.php @@ -59,6 +59,7 @@ protected function configure() { protected function execute(InputInterface $input, OutputInterface $output): int { $configPrefix = $this->helper->getNextServerConfigurationPrefix(); $configHolder = new Configuration($configPrefix); + $configHolder->ldapConfigurationActive = false; $configHolder->saveConfiguration(); $prose = ''; diff --git a/apps/user_ldap/lib/Configuration.php b/apps/user_ldap/lib/Configuration.php index 63390a60fd423..c895874a7a036 100644 --- a/apps/user_ldap/lib/Configuration.php +++ b/apps/user_ldap/lib/Configuration.php @@ -50,10 +50,9 @@ class Configuration { protected $configPrefix = null; protected $configRead = false; /** - * @var string[] pre-filled with one reference key so that at least one entry is written on save request and - * the config ID is registered + * @var string[] */ - protected $unsavedChanges = ['ldapConfigurationActive' => 'ldapConfigurationActive']; + protected $unsavedChanges = []; //settings protected $config = [ diff --git a/apps/user_ldap/lib/Controller/ConfigAPIController.php b/apps/user_ldap/lib/Controller/ConfigAPIController.php index cf09c6acd0625..bbf9e822f49f3 100644 --- a/apps/user_ldap/lib/Controller/ConfigAPIController.php +++ b/apps/user_ldap/lib/Controller/ConfigAPIController.php @@ -117,6 +117,7 @@ public function create() { try { $configPrefix = $this->ldapHelper->getNextServerConfigurationPrefix(); $configHolder = new Configuration($configPrefix); + $configHolder->ldapConfigurationActive = false; $configHolder->saveConfiguration(); } catch (\Exception $e) { $this->logger->logException($e);