Startseite frei gestalten, Neuigkeiten-Block mit Kategorien-Filter (0.26.0)
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 5m21s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 4m55s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 4m40s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 4m42s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 7m25s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 7m57s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 6m16s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 5m34s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m14s
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 5m21s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 4m55s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 4m40s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 4m42s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 7m25s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 7m57s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 6m16s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 5m34s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m14s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
6290e09074
commit
2c96fcce1c
151 changed files with 1515 additions and 317 deletions
|
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
/**
|
||||
* Block „Neuigkeiten“: aus der einzelnen Kategorie („category“) wird der neue Filter
|
||||
* („filter“ = include, „categories“ = [slug]) – in Seiten, Bausteinen und Beiträgen.
|
||||
*/
|
||||
return new class extends Migration
|
||||
{
|
||||
private const COLUMNS = [
|
||||
'pages' => ['content', 'draft', 'scheduled_content'],
|
||||
'content_snippets' => ['content'],
|
||||
'news_posts' => ['content'],
|
||||
];
|
||||
|
||||
public function up(): void
|
||||
{
|
||||
foreach (self::COLUMNS as $table => $columns) {
|
||||
if (! Schema::hasTable($table)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DB::table($table)->orderBy('id')->each(function ($row) use ($table, $columns) {
|
||||
$changes = [];
|
||||
|
||||
foreach ($columns as $column) {
|
||||
$content = json_decode((string) ($row->{$column} ?? ''), true);
|
||||
|
||||
if (is_array($content) && $this->convert($content)) {
|
||||
$changes[$column] = json_encode($content, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
}
|
||||
|
||||
if ($changes) {
|
||||
DB::table($table)->where('id', $row->id)->update($changes);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<mixed> $node
|
||||
*/
|
||||
private function convert(array &$node): bool
|
||||
{
|
||||
$changed = false;
|
||||
|
||||
if (($node['type'] ?? null) === 'news.latest' && is_array($node['data'] ?? null) && array_key_exists('category', $node['data'])) {
|
||||
$slug = (string) $node['data']['category'];
|
||||
unset($node['data']['category']);
|
||||
$node['data'] += $slug !== ''
|
||||
? ['filter' => 'include', 'categories' => [$slug]]
|
||||
: ['filter' => 'all', 'categories' => []];
|
||||
$changed = true;
|
||||
}
|
||||
|
||||
foreach ($node as &$child) {
|
||||
if (is_array($child) && $this->convert($child)) {
|
||||
$changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
return $changed;
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue