overwriteExisting = true; * $seeder->run(); */ public bool $overwriteExisting = false; /** * Nur diese Section-Keys verarbeiten (leer = alle). * * Erlaubt einen gezielten Lauf für einzelne Sektionen, ohne den Rest anzufassen. * * @var array */ public array $onlySections = []; public function run(): void { /** @var array $sectionMap */ $sectionMap = config('cms_section_map.sections', []); /** @var array $langDe */ $langDe = Lang::get('b2in.themes.b2in', [], 'de'); /** @var array $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 = []; } $created = 0; $updated = 0; $skipped = 0; foreach ($sectionMap as $sectionKey => $groupKeyPair) { if ($this->onlySections !== [] && ! in_array($sectionKey, $this->onlySections, true)) { continue; } if (! array_key_exists($sectionKey, $langDe)) { $this->command?->warn("Unmapped or missing theme data for section: {$sectionKey} – skipping."); continue; } $sectionDataDe = $langDe[$sectionKey]; $sectionDataEn = $langEn[$sectionKey] ?? $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) { if (! $this->overwriteExisting) { $skipped++; continue; } $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, {$skipped} kept (existing CMS content)."); if ($skipped > 0 && ! $this->overwriteExisting) { $this->command?->comment('Bestehende CMS-Inhalte wurden nicht angetastet. Zum Überschreiben $overwriteExisting = true setzen.'); } if ($created > 0 || $updated > 0) { app(CmsContentService::class)->clearCache(); } } private function detectType(mixed $data): string { if (is_array($data)) { return 'json'; } if (is_string($data) && preg_match('/<[^>]+>/', $data)) { return 'html'; } return 'text'; } }