Entferne alten JSON-basierten Datenquellen-Synonym-Handler

Die Verwaltung der Datenquellen-Synonyme wurde überarbeitet, um ein flexibleres und strukturiertes Konzept zu ermöglichen. Der bestehende JSON-basierte Ansatz wurde durch eine neue Service-basierte Architektur ersetzt, die eine bessere Handhabung und Erweiterbarkeit erlaubt.
This commit is contained in:
Marcel Diegelmann 2025-11-05 12:27:40 +01:00
parent d80ec94227
commit a8b3dce899
30 changed files with 802 additions and 277 deletions

View file

@ -4,7 +4,7 @@ declare(strict_types=1);
namespace App\Settings\BehaviorSettings;
use App\Form\Type\DataSourceJsonType;
use App\Form\Type\DataSourceSynonymsCollectionType;
use App\Settings\SettingsIcon;
use Jbtronics\SettingsBundle\ParameterTypes\ArrayType;
use Jbtronics\SettingsBundle\ParameterTypes\StringType;
@ -20,11 +20,12 @@ class DataSourceSynonymsSettings
{
use SettingsTrait;
#[SettingsParameter(ArrayType::class,
#[SettingsParameter(
ArrayType::class,
label: new TM("settings.system.data_source_synonyms.configuration"),
description: new TM("settings.system.data_source_synonyms.configuration.help", ['%format%' => '{"en":"", "de":""}']),
options: ['type' => StringType::class],
formType: DataSourceJsonType::class,
description: new TM("settings.system.data_source_synonyms.configuration.help"),
options: ['type' => ArrayType::class, 'options' => ['type' => StringType::class]],
formType: DataSourceSynonymsCollectionType::class,
formOptions: [
'required' => false,
'data_sources' => [
@ -35,39 +36,55 @@ class DataSourceSynonymsSettings
'supplier' => new TM("settings.behavior.data_source_synonyms.supplier"),
'project' => new TM("settings.behavior.data_source_synonyms.project"),
],
'default_values' => [
'category' => '{"en":"Categories", "de":"Kategorien"}',
'storagelocation' => '{"en":"Storage locations", "de":"Lagerorte"}',
'footprint' => '{"en":"Footprints", "de":"Footprints"}',
'manufacturer' => '{"en":"Manufacturers", "de":"Hersteller"}',
'supplier' => '{"en":"Suppliers", "de":"Lieferanten"}',
'project' => '{"en":"Projects", "de":"Projekte"}',
],
],
)]
#[Assert\Type('array')]
#[Assert\All([new Assert\Type('array')])]
public array $dataSourceSynonyms = [
'category' => '{"en":"Categories", "de":"Kategorien"}',
'storagelocation' => '{"en":"Storage locations", "de":"Lagerorte"}',
'footprint' => '{"en":"Footprints", "de":"Footprints"}',
'manufacturer' => '{"en":"Manufacturers", "de":"Hersteller"}',
'supplier' => '{"en":"Suppliers", "de":"Lieferanten"}',
'project' => '{"en":"Projects", "de":"Projekte"}',
// flat list of rows, e.g.:
// ['dataSource' => 'category', 'locale' => 'en', 'translation_singular' => 'Category', 'translation_plural' => 'Categories'],
];
/**
* Get the synonyms data as a structured array.
* Normalize to map form:
* [dataSource => [locale => ['singular' => string, 'plural' => string]]]
* No preference/merging is applied; both values are returned as provided (missing ones as empty strings).
*
* @return array<string, array<string, string>> The data source synonyms parsed from JSON to array.
* @return array<string, array<string, array{singular: string, plural: string}>>
*/
public function getSynonymsAsArray(): array
{
$result = [];
foreach ($this->dataSourceSynonyms as $key => $jsonString) {
$result[$key] = json_decode($jsonString, true, 512, JSON_THROW_ON_ERROR) ?? [];
foreach ($this->dataSourceSynonyms as $row) {
if (!is_array($row)) {
continue;
}
$ds = $row['dataSource'] ?? null;
$loc = $row['locale'] ?? null;
if (!is_string($ds) || $ds === '' || !is_string($loc) || $loc === '') {
continue;
}
// Read both fields independently; do not prefer one over the other.
$singular = isset($row['translation_singular']) && is_string($row['translation_singular'])
? $row['translation_singular'] : '';
$plural = isset($row['translation_plural']) && is_string($row['translation_plural'])
? $row['translation_plural'] : '';
// For legacy data (optional): if only "text" exists and both fields are empty, keep it as given in both slots or leave empty?
// Requirement says: no preference, just return values. We therefore do NOT map legacy automatically.
// If you want to expose legacy "text" as well, handle it outside or migrate data beforehand.
$result[$ds] ??= [];
$result[$ds][$loc] = [
'singular' => $singular,
'plural' => $plural,
];
}
return $result;
}
}

View file

@ -1,37 +0,0 @@
<?php
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2024 Jan Böhmer (https://github.com/jbtronics)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace App\Settings\SystemSettings;
enum PreferredLocales: string
{
case EN = 'en';
case DE = 'de';
case IT = 'it';
case FR = 'fr';
case RU = 'ru';
case JA = 'ja';
case CS = 'cs';
case DA = 'da';
case ZH = 'zh';
case PL = 'pl';
}