Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions app/Services/ThemeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ public function upload(UploadedFile $file): bool

$targetPath = $userThemePath . $config['name'];
if (File::exists($targetPath)) {
$existingConfig = admin_setting(self::SETTING_PREFIX . $config['name']);
$oldConfigFile = $targetPath . '/config.json';
if (!File::exists($oldConfigFile)) {
throw new Exception('Existing theme missing config file');
Expand All @@ -159,7 +160,7 @@ public function upload(UploadedFile $file): bool
$this->cleanupThemeFiles($config['name']);
File::deleteDirectory($targetPath);
File::copyDirectory($sourcePath, $targetPath);
$this->initConfig($config['name']);
$this->initConfig($config['name'], is_array($existingConfig) ? $existingConfig : null);
return true;
} else {
throw new Exception('Theme exists and not a newer version');
Expand Down Expand Up @@ -398,7 +399,7 @@ public function refreshCurrentTheme(): bool
/**
* Initialize theme config
*/
private function initConfig(string $theme): void
private function initConfig(string $theme, ?array $existingConfig = null): void
{
$config = $this->readConfigFile($theme);
if (!$config) {
Expand All @@ -408,6 +409,14 @@ private function initConfig(string $theme): void
$defaults = collect($config['configs'] ?? [])
->mapWithKeys(fn($col) => [$col['field_name'] => $col['default_value'] ?? ''])
->toArray();
if ($existingConfig) {
foreach ($defaults as $key => $value) {
if (array_key_exists($key, $existingConfig)) {
$defaults[$key] = $existingConfig[$key];
}
}
}

admin_setting([self::SETTING_PREFIX . $theme => $defaults]);
}
}