10-04-2026
This commit is contained in:
parent
4d6b4930b2
commit
4bb89aad8c
836 changed files with 52961 additions and 5950 deletions
118
database/seeders/CmsContentSeeder.php
Normal file
118
database/seeders/CmsContentSeeder.php
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use FluxCms\Core\Models\CmsContent;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\Lang;
|
||||
|
||||
class CmsContentSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Sections to skip (not migrated, handled elsewhere or irrelevant).
|
||||
*
|
||||
* netzwerk_cabinet_partner / netzwerk_immobilien_hint: siehe NetzwerkPageCmsSeeder
|
||||
* (nur einfügen wenn leer, damit manuelle CMS-Anpassungen nicht überschrieben werden).
|
||||
*
|
||||
* @var array<string>
|
||||
*/
|
||||
protected array $skipSections = [
|
||||
'netzwerk_cabinet_partner',
|
||||
'netzwerk_immobilien_hint',
|
||||
];
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
/** @var array<string, array{0: string, 1: string}> $sectionMap */
|
||||
$sectionMap = config('cms_section_map.sections', []);
|
||||
/** @var array<string, string> $langKeys */
|
||||
$langKeys = config('cms_section_map.lang_keys', []);
|
||||
|
||||
/** @var array<string, mixed> $configTheme */
|
||||
$configTheme = config('content.themes.b2in', []);
|
||||
/** @var array<string, mixed> $langDe */
|
||||
$langDe = Lang::get('b2in.themes.b2in', [], 'de');
|
||||
/** @var array<string, mixed> $langEn */
|
||||
$langEn = Lang::get('b2in.themes.b2in', [], 'en');
|
||||
|
||||
if (! is_array($langDe) || empty($langDe)) {
|
||||
$this->command?->warn('No b2in theme found in resources/lang/de/b2in.php (key: b2in.themes.b2in) – skipping.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (! is_array($langEn)) {
|
||||
$langEn = [];
|
||||
}
|
||||
|
||||
/** @var array<string, mixed> $themeDe */
|
||||
$themeDe = array_merge($configTheme, $langDe);
|
||||
/** @var array<string, mixed> $themeEn */
|
||||
$themeEn = array_merge($configTheme, $langEn);
|
||||
|
||||
$created = 0;
|
||||
$updated = 0;
|
||||
|
||||
foreach ($sectionMap as $sectionKey => $groupKeyPair) {
|
||||
if (in_array($sectionKey, $this->skipSections, true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$langSectionKey = $langKeys[$sectionKey] ?? $sectionKey;
|
||||
|
||||
if (! array_key_exists($langSectionKey, $themeDe)) {
|
||||
$this->command?->warn("Unmapped or missing theme data for section: {$sectionKey} (lang key: {$langSectionKey}) – skipping.");
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$sectionDataDe = $themeDe[$langSectionKey];
|
||||
$sectionDataEn = $themeEn[$langSectionKey] ?? $sectionDataDe;
|
||||
|
||||
[$group, $key] = $groupKeyPair;
|
||||
$type = $this->detectType($sectionDataDe);
|
||||
|
||||
$content = CmsContent::query()
|
||||
->where('group', $group)
|
||||
->where('key', $key)
|
||||
->first();
|
||||
|
||||
$value = [
|
||||
'de' => $sectionDataDe,
|
||||
'en' => $sectionDataEn,
|
||||
];
|
||||
|
||||
if ($content) {
|
||||
$content->update([
|
||||
'type' => $type,
|
||||
'value' => $value,
|
||||
]);
|
||||
$updated++;
|
||||
} else {
|
||||
CmsContent::query()->create([
|
||||
'group' => $group,
|
||||
'key' => $key,
|
||||
'type' => $type,
|
||||
'value' => $value,
|
||||
'order' => 0,
|
||||
]);
|
||||
$created++;
|
||||
}
|
||||
}
|
||||
|
||||
$this->command?->info("CmsContent: {$created} created, {$updated} updated.");
|
||||
}
|
||||
|
||||
private function detectType(mixed $data): string
|
||||
{
|
||||
if (is_array($data)) {
|
||||
return 'json';
|
||||
}
|
||||
|
||||
if (is_string($data) && preg_match('/<[^>]+>/', $data)) {
|
||||
return 'html';
|
||||
}
|
||||
|
||||
return 'text';
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue