81 lines
2.6 KiB
PHP
81 lines
2.6 KiB
PHP
<?php
|
||
|
||
namespace Database\Seeders;
|
||
|
||
use FluxCms\Core\Models\CmsContent;
|
||
use FluxCms\Core\Services\CmsContentService;
|
||
use Illuminate\Database\Seeder;
|
||
|
||
/**
|
||
* Projekttext auf der Startseite (Briefing Marcel 24.09.2026, Punkt 7; Nachtrag 19).
|
||
*
|
||
* In der Karte „Ausstattung für Ihr Projekt“ (home/audience_switch) wird „Mit deutscher
|
||
* Vertragssicherheit …“ durch „Mit einem zentralen deutschen Vertragspartner …“ ersetzt.
|
||
* Der Seeder tauscht nur genau diesen Satz, egal wo er im Sektions-JSON steht; alles andere
|
||
* bleibt. Steht der Satz nicht mehr drin, passiert nichts. Mehrfaches Ausführen ist unbedenklich.
|
||
*
|
||
* php artisan db:seed --class=AudienceSwitchProjectTextSeeder
|
||
*/
|
||
class AudienceSwitchProjectTextSeeder extends Seeder
|
||
{
|
||
/** @var array<string, string> alter Satz → neuer Satz */
|
||
public const REPLACEMENTS = [
|
||
'Mit deutscher Vertragssicherheit und einem eingespielten Herstellernetzwerk.' => 'Mit einem zentralen deutschen Vertragspartner und einem eingespielten Herstellernetzwerk.',
|
||
'With German contractual reliability and an established manufacturer network.' => 'With a single German contract partner and an established manufacturer network.',
|
||
];
|
||
|
||
public function run(): void
|
||
{
|
||
$row = CmsContent::query()->where('group', 'home')->where('key', 'audience_switch')->first();
|
||
|
||
if (! $row) {
|
||
$this->command?->info('Projekttext: Sektion home/audience_switch nicht im CMS – die Lang-Datei gilt.');
|
||
|
||
return;
|
||
}
|
||
|
||
$value = $row->getTranslations('value');
|
||
$count = 0;
|
||
$value = $this->replaceDeep($value, $count);
|
||
|
||
if ($count === 0) {
|
||
$this->command?->info('Projekttext: bereits aktuell, nichts geändert.');
|
||
|
||
return;
|
||
}
|
||
|
||
$row->value = $value;
|
||
$row->save();
|
||
app(CmsContentService::class)->clearCache('home');
|
||
|
||
$this->command?->info("Projekttext ersetzt ({$count} Stelle(n)).");
|
||
}
|
||
|
||
/**
|
||
* @param array<mixed> $data
|
||
* @return array<mixed>
|
||
*/
|
||
private function replaceDeep(array $data, int &$count): array
|
||
{
|
||
foreach ($data as $key => $item) {
|
||
if (is_array($item)) {
|
||
$data[$key] = $this->replaceDeep($item, $count);
|
||
|
||
continue;
|
||
}
|
||
|
||
if (! is_string($item)) {
|
||
continue;
|
||
}
|
||
|
||
$replaced = strtr($item, self::REPLACEMENTS);
|
||
|
||
if ($replaced !== $item) {
|
||
$data[$key] = $replaced;
|
||
$count++;
|
||
}
|
||
}
|
||
|
||
return $data;
|
||
}
|
||
}
|