From 94f4c1181937388a191d839e0673acd9966e13b2 Mon Sep 17 00:00:00 2001 From: Andrey Borysenko Date: Fri, 23 Dec 2022 15:18:56 +0200 Subject: [PATCH] Added settings texts sync with database --- lib/Migration/AppDataCleanupStep.php | 1 - lib/Service/UtilsService.php | 26 ++++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/Migration/AppDataCleanupStep.php b/lib/Migration/AppDataCleanupStep.php index 4e210c91..ea57c20f 100755 --- a/lib/Migration/AppDataCleanupStep.php +++ b/lib/Migration/AppDataCleanupStep.php @@ -47,7 +47,6 @@ public function getName(): string { public function run(IOutput $output) { $output->startProgress(1); - // $this->cleanupService->dropAppTables(); $this->cleanupService->deleteAppLogs(); $output->advance(1); $output->finishProgress(); diff --git a/lib/Service/UtilsService.php b/lib/Service/UtilsService.php index 73f8ac6d..62f720fe 100755 --- a/lib/Service/UtilsService.php +++ b/lib/Service/UtilsService.php @@ -42,6 +42,7 @@ public function __construct(SettingMapper $settingMapper) { public function checkForSettingsUpdates($app_data) { $settings = $this->settingMapper->findAll(); if (count($settings) > 0) { + $this->updateSettingsTexts($app_data, $settings); $this->checkForNewSettings($app_data, $settings); $this->checkForDeletedSettings($app_data, $settings); } @@ -94,4 +95,29 @@ private function checkForDeletedSettings(array $app_data, array $settings): void } } } + + private function updateSettingsTexts(array $app_data, array $settings) { + $newSettingsKeys = array_map(function ($setting) { + return $setting['name']; + }, $app_data['settings']); + foreach ($settings as $setting) { + if (in_array($setting->getName(), $newSettingsKeys)) { + $newSetting = null; + foreach ($app_data['settings'] as $s) { + if ($s['name'] == $setting->getName()) { + $newSetting = $s; + } + } + if (isset($newSetting)) { + if ($setting->getDescription() !== $newSetting['description']) { + $setting->setDescription($newSetting['description']); + } + if ($setting->getDisplayName() !== $newSetting['displayName']) { + $setting->setDisplayName($newSetting['displayName']); + } + $this->settingMapper->update($setting); + } + } + } + } }