Phase 4: Seiten mit Pagebuilder, Redaktion und Freigaben
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m56s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m56s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 2m2s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 2m9s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 2m40s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 2m35s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 2m29s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 2m38s
CI / Build-Artefakte aktuell (pull_request) Successful in 55s
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m56s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m56s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 2m2s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 2m9s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 2m40s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 2m35s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 2m29s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 2m38s
CI / Build-Artefakte aktuell (pull_request) Successful in 55s
- Seiten-Plugin: Seitenbaum mit Adressen, Seitennavigation, Brotkrumen und optional Hauptnavigation; Sichtbarkeit vererbt sich auf Unterseiten - Pagebuilder (Block-Registry im Kern, Plugins tragen Blöcke bei): Abschnitt, Spalten, Tabs, Akkordeon, Box, Überschrift, Text (TipTap), Zitat, Schaltflächen, Symbolliste, Tabelle, Trennlinie, Abstand, Bild, Galerie, Video (erst nach Klick), Titelbild, Ansprechpartner, Downloads, Unterseiten, Neuigkeiten, Termine; Sichtbarkeit je Block; Bereinigung beim Speichern - Editor im Portal: Ziehen und Ablegen, Autospeichern als Entwurf, Rückgängig, Gerätevorschau, Versionen, Zeitsteuerung, Bearbeitungssperre, Freigabe anfordern - Rechte „inkl. Unterseiten“ werden im Rechte-Cache aufgelöst - Neuigkeiten: Schreiben im Portal, Freigabe-Workflow mit Benachrichtigungen - Bereich „Redaktion“, Benachrichtigungen im Portal - storage/.migrations-fingerprint nicht mehr ausliefern Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
6269d3302c
commit
f3987e8386
328 changed files with 10618 additions and 389 deletions
239
plugins-core/pages/src/Models/Page.php
Normal file
239
plugins-core/pages/src/Models/Page.php
Normal file
|
|
@ -0,0 +1,239 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Pages\Models;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Pagebuilder\Content;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Inhaus\Plugins\Pages\PageTree;
|
||||
|
||||
/**
|
||||
* Eine Inhaltsseite im Seitenbaum. Inhalt, Entwurf und geplanter Stand sind
|
||||
* bereinigtes Block-JSON (siehe App\Pagebuilder\Content).
|
||||
*/
|
||||
#[Fillable(['parent_id', 'title', 'slug', 'sort', 'in_navigation', 'created_by'])]
|
||||
class Page extends Model
|
||||
{
|
||||
/** So lange hält eine Bearbeitungssperre ohne Lebenszeichen des Editors. */
|
||||
public const LOCK_SECONDS = 120;
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::saving(function (Page $page) {
|
||||
$page->slug = Str::slug($page->slug ?: $page->title, language: 'de') ?: 'seite';
|
||||
|
||||
if ($page->isDirty(['slug', 'parent_id']) || $page->path === null) {
|
||||
$page->path = static::uniquePath($page);
|
||||
}
|
||||
});
|
||||
|
||||
// Unterseiten ziehen mit, wenn sich die Adresse ändert.
|
||||
static::saved(function (Page $page) {
|
||||
if (! $page->wasRecentlyCreated && $page->wasChanged('path')) {
|
||||
$old = $page->getOriginal('path');
|
||||
|
||||
DB::table('pages')->where('path', 'like', str_replace(['%', '_'], ['\%', '\_'], $old).'/%')->update([
|
||||
'path' => DB::raw('CONCAT('.DB::getPdo()->quote($page->path).', SUBSTRING(path, '.(mb_strlen($old) + 1).'))'),
|
||||
]);
|
||||
}
|
||||
|
||||
if ($page->wasRecentlyCreated || $page->wasChanged(['title', 'path', 'parent_id', 'sort', 'in_navigation', 'published_at'])) {
|
||||
PageTree::flush($page->wasRecentlyCreated || $page->wasChanged('parent_id'));
|
||||
}
|
||||
});
|
||||
|
||||
static::deleted(fn () => PageTree::flush(true));
|
||||
}
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'content' => 'array',
|
||||
'draft' => 'array',
|
||||
'scheduled_content' => 'array',
|
||||
'in_navigation' => 'boolean',
|
||||
'published_at' => 'datetime',
|
||||
'draft_updated_at' => 'datetime',
|
||||
'scheduled_at' => 'datetime',
|
||||
'locked_until' => 'datetime',
|
||||
'locked_by' => 'integer',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{0: string, 1: int}
|
||||
*/
|
||||
public function permissionResource(): array
|
||||
{
|
||||
return ['page', $this->id];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<Page, $this>
|
||||
*/
|
||||
public function parent(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Page::class, 'parent_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HasMany<Page, $this>
|
||||
*/
|
||||
public function children(): HasMany
|
||||
{
|
||||
return $this->hasMany(Page::class, 'parent_id')->orderBy('sort')->orderBy('title');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HasMany<PageRevision, $this>
|
||||
*/
|
||||
public function revisions(): HasMany
|
||||
{
|
||||
return $this->hasMany(PageRevision::class)->latest('id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HasMany<PageFile, $this>
|
||||
*/
|
||||
public function files(): HasMany
|
||||
{
|
||||
return $this->hasMany(PageFile::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<User, $this>
|
||||
*/
|
||||
public function lockedBy(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'locked_by');
|
||||
}
|
||||
|
||||
public function isPublished(): bool
|
||||
{
|
||||
return $this->content !== null;
|
||||
}
|
||||
|
||||
public function hasDraft(): bool
|
||||
{
|
||||
return $this->draft !== null;
|
||||
}
|
||||
|
||||
public function url(): string
|
||||
{
|
||||
return '/seiten/'.$this->path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stand, mit dem der Editor startet: Entwurf, sonst veröffentlichter Inhalt.
|
||||
*
|
||||
* @return array{title: string, content: array<string, mixed>}
|
||||
*/
|
||||
public function workingCopy(): array
|
||||
{
|
||||
return [
|
||||
'title' => $this->draft_title ?? $this->title,
|
||||
'content' => $this->draft ?? $this->content ?? Content::empty(),
|
||||
];
|
||||
}
|
||||
|
||||
public function isLockedFor(User $user): bool
|
||||
{
|
||||
return $this->locked_by !== null && $this->locked_by !== $user->id && $this->locked_until?->isFuture();
|
||||
}
|
||||
|
||||
public function lockFor(User $user): void
|
||||
{
|
||||
$this->forceFill(['locked_by' => $user->id, 'locked_until' => now()->addSeconds(self::LOCK_SECONDS)])->saveQuietly();
|
||||
}
|
||||
|
||||
public function unlockFor(User $user): void
|
||||
{
|
||||
if ($this->locked_by === $user->id) {
|
||||
$this->forceFill(['locked_by' => null, 'locked_until' => null])->saveQuietly();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stand veröffentlichen und als Version ablegen.
|
||||
*
|
||||
* @param array<string, mixed> $content bereinigt
|
||||
*/
|
||||
public function publish(string $title, array $content, ?User $user, string $action = 'published'): void
|
||||
{
|
||||
DB::transaction(function () use ($title, $content, $user, $action) {
|
||||
$this->forceFill([
|
||||
'title' => $title,
|
||||
'content' => $content,
|
||||
'published_at' => now(),
|
||||
'published_by' => $user?->id,
|
||||
'draft' => null,
|
||||
'draft_title' => null,
|
||||
'draft_updated_at' => null,
|
||||
'draft_updated_by' => null,
|
||||
])->save();
|
||||
|
||||
$this->revisions()->create(['title' => $title, 'content' => $content, 'action' => $action, 'user_id' => $user?->id, 'created_at' => now()]);
|
||||
|
||||
// Nur die letzten 50 Versionen behalten.
|
||||
$keep = $this->revisions()->limit(50)->pluck('id');
|
||||
$this->revisions()->whereNotIn('id', $keep)->delete();
|
||||
});
|
||||
}
|
||||
|
||||
public function schedule(string $title, array $content, Carbon $at, User $user): void
|
||||
{
|
||||
$this->forceFill([
|
||||
'scheduled_at' => $at,
|
||||
'scheduled_title' => $title,
|
||||
'scheduled_content' => $content,
|
||||
'scheduled_by' => $user->id,
|
||||
'draft' => null,
|
||||
'draft_title' => null,
|
||||
'draft_updated_at' => null,
|
||||
'draft_updated_by' => null,
|
||||
])->save();
|
||||
}
|
||||
|
||||
public function cancelSchedule(): void
|
||||
{
|
||||
$this->forceFill(['scheduled_at' => null, 'scheduled_title' => null, 'scheduled_content' => null, 'scheduled_by' => null])->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fälligen geplanten Stand veröffentlichen (Hintergrundaufgabe und beim Aufruf).
|
||||
*/
|
||||
public function publishIfDue(): bool
|
||||
{
|
||||
if (! $this->scheduled_at || $this->scheduled_at->isFuture()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$by = $this->scheduled_by ? User::query()->find($this->scheduled_by) : null;
|
||||
$title = $this->scheduled_title ?? $this->title;
|
||||
$content = $this->scheduled_content ?? Content::empty();
|
||||
$this->cancelSchedule();
|
||||
$this->publish($title, $content, $by, 'scheduled');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function uniquePath(Page $page): string
|
||||
{
|
||||
$prefix = $page->parent_id ? static::query()->whereKey($page->parent_id)->value('path').'/' : '';
|
||||
$slug = $page->slug;
|
||||
|
||||
for ($i = 2; static::query()->where('path', $prefix.$slug)->when($page->exists, fn ($q) => $q->whereKeyNot($page->id))->exists(); $i++) {
|
||||
$slug = $page->slug.'-'.$i;
|
||||
}
|
||||
|
||||
$page->slug = $slug;
|
||||
|
||||
return $prefix.$slug;
|
||||
}
|
||||
}
|
||||
50
plugins-core/pages/src/Models/PageFile.php
Normal file
50
plugins-core/pages/src/Models/PageFile.php
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Pages\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
/**
|
||||
* Datei zum Herunterladen (Block „Downloads“). Liegt außerhalb von public/ und
|
||||
* wird nur an Personen ausgeliefert, die die Seite sehen dürfen.
|
||||
*/
|
||||
#[Fillable(['page_id', 'name', 'path', 'mime', 'size', 'uploaded_by'])]
|
||||
class PageFile extends Model
|
||||
{
|
||||
public const DISK = 'local';
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::deleted(fn (PageFile $file) => Storage::disk(self::DISK)->delete($file->path));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<Page, $this>
|
||||
*/
|
||||
public function page(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Page::class);
|
||||
}
|
||||
|
||||
public function url(): string
|
||||
{
|
||||
return route('pages.file', ['file' => $this->id, 'name' => $this->name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{id: int, name: string, size: int, extension: string, url: string}
|
||||
*/
|
||||
public function toBlockArray(): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'size' => (int) $this->size,
|
||||
'extension' => strtoupper(pathinfo($this->name, PATHINFO_EXTENSION)),
|
||||
'url' => $this->url(),
|
||||
];
|
||||
}
|
||||
}
|
||||
41
plugins-core/pages/src/Models/PageRevision.php
Normal file
41
plugins-core/pages/src/Models/PageRevision.php
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Pages\Models;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
#[Fillable(['page_id', 'title', 'content', 'action', 'user_id', 'created_at'])]
|
||||
class PageRevision extends Model
|
||||
{
|
||||
public const UPDATED_AT = null;
|
||||
|
||||
public const ACTIONS = [
|
||||
'published' => 'Veröffentlicht',
|
||||
'scheduled' => 'Zeitgesteuert veröffentlicht',
|
||||
'restored' => 'Wiederhergestellt',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['content' => 'array'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<User, $this>
|
||||
*/
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<Page, $this>
|
||||
*/
|
||||
public function page(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Page::class);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue