Halte ungenutzte Medien bearbeitbar und lege Dateien direkt im Modul an.
Deploy Test / test (push) Successful in 26s
Deploy Test / deploy (push) Successful in 30s

Eine Fassung wird erst unveränderlich, wenn sie freigegeben und verwendet wird. Das Auge am Listeneintrag öffnet die Vorschau.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-11-17 10:34:42 +01:00
1 parent 1fb48783bf
commit c73207f2c3
11 files changed
+547 -25

No files matched your search

@@ -38,6 +38,18 @@ protected static function booted(): void
return;
}
if (
$original === ContentVersionStatus::Bereit->value
&& StatusValue::of($version->status) === ContentVersionStatus::Bereit->value
&& ! app(ContentService::class)->isCommitted($version)
) {
$contentFields = ['body', 'metadata', 'content_hash', 'change_note', 'updated_at'];
if (array_diff(array_keys($version->getDirty()), $contentFields) === []) {
return;
}
}
$allowed = ['status', 'updated_at'];
if (
+86
View File
@@ -78,6 +78,92 @@ public function publishElementVersion(
return $version;
}
public function draftElementVersion(
ContentElement $element,
?string $body = null,
array $metadata = [],
): ContentElementVersion {
if (($body === null || $body === '') && $metadata === []) {
throw new DomainRuleException('Eine Inhaltsfassung braucht einen Inhalt.');
}
$number = ((int) $element->versions()->max('number')) + 1;
$version = $element->versions()->create([
'number' => $number,
'status' => ContentVersionStatus::Entwurf,
'content_hash' => hash('sha256', json_encode([
'body' => $body,
'metadata' => $metadata,
], JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE)),
'body' => $body,
'metadata' => $metadata === [] ? null : $metadata,
'change_note' => null,
]);
$incoming = $metadata['incoming'] ?? null;
if (is_string($incoming) && $incoming !== '') {
StoreContentFile::dispatch($version->id, $incoming);
$version->refresh();
}
return $version;
}
public function isCommitted(ContentElementVersion $version): bool
{
if ($version->status !== ContentVersionStatus::Bereit) {
return false;
}
$usedByComposition = CompositionMember::query()
->where('content_element_version_id', $version->id)
->whereHas('compositionVersion', function ($query): void {
$query->where('status', ContentVersionStatus::Bereit);
})
->exists();
if ($usedByComposition) {
return true;
}
return ReleaseContent::query()
->where('content_element_version_id', $version->id)
->exists();
}
public function reviseElementContent(ContentElementVersion $version, string $body): ContentElementVersion
{
$body = trim($body);
if ($body === '') {
throw new DomainRuleException('Der Text braucht einen Inhalt.');
}
$version->loadMissing('element');
if ($version->status === ContentVersionStatus::Gesperrt) {
throw new DomainRuleException('Eine deaktivierte Fassung lässt sich nicht ändern.');
}
if (trim((string) $version->body) === $body) {
return $version;
}
if ($this->isCommitted($version)) {
return $this->publishElementVersion($version->element, $body);
}
$metadata = $version->metadata ?? [];
$version->body = $body;
$version->content_hash = hash('sha256', json_encode([
'body' => $body,
'metadata' => $metadata,
], JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
$version->save();
return $version->refresh();
}
/**
* @param list<array{role: string, target: ContentElementVersion|CompositionVersion}> $members
*/
@@ -20,6 +20,7 @@
use App\Domain\Catalog\IdentityProfile;
use App\Domain\Catalog\StructureNode;
use App\Filament\Support\EditorialCatalog;
use App\Filament\Support\IncomingFile;
use App\Http\Controllers\ContentPreviewController;
use App\Jobs\DeriveCompositionFrame;
use App\Jobs\DeriveThumbnail;
@@ -88,6 +89,8 @@ abstract class EditComposition extends EditRecord
public bool $textOpen = false;
public bool $fileOpen = false;
public bool $releaseArmed = false;
public string $returnUrl = '';
@@ -100,6 +103,14 @@ abstract class EditComposition extends EditRecord
public string $newTextBody = '';
public string $newFileTitle = '';
public mixed $incomingFile = null;
public string $partTitle = '';
public string $partBody = '';
public string $newModuleName = '';
public mixed $previewUpload = null;
@@ -301,6 +312,7 @@ public function openPicker(): void
$this->pickerOpen = true;
$this->textOpen = false;
$this->fileOpen = false;
$this->pickerSelected = '';
}
@@ -396,6 +408,7 @@ public function openText(): void
$this->pickerOpen = false;
$this->moduleOpen = false;
$this->partOpen = false;
$this->fileOpen = false;
$this->textOpen = true;
}
@@ -406,6 +419,22 @@ public function cancelText(): void
$this->newTextBody = '';
}
public function openFile(): void
{
$this->pickerOpen = false;
$this->moduleOpen = false;
$this->partOpen = false;
$this->textOpen = false;
$this->fileOpen = true;
}
public function cancelFile(): void
{
$this->fileOpen = false;
$this->newFileTitle = '';
$this->incomingFile = null;
}
public function saveDraft(): void
{
$this->commitRoleDraft();
@@ -668,11 +697,16 @@ public function selectPart(int $index): void
}
public function addPart(string $target): void
{
$this->includePart($target, false);
}
private function includePart(string $target, bool $allowDraft): bool
{
if (preg_match('/^(element|composition):\d+$/', $target) !== 1) {
$this->feedback = 'Dieser Bestandteil ist nicht verfügbar.';
return;
return false;
}
foreach ($this->members as $index => $member) {
@@ -681,16 +715,16 @@ public function addPart(string $target): void
$this->panel = 'bestandteil';
$this->feedback = 'Diese Fassung ist schon enthalten.';
return;
return false;
}
}
$row = app(EditorialCatalog::class)->rowForTarget($target, (int) $this->getRecord()->getKey());
$row = app(EditorialCatalog::class)->rowForTarget($target, (int) $this->getRecord()->getKey(), allowDraft: $allowDraft);
if ($row === null) {
$this->feedback = 'Diese Fassung ist nicht bereit oder gehört zu diesem Eintrag.';
return;
return false;
}
$row['role'] = app(EditorialCatalog::class)->defaultRole((string) $row['kind']);
@@ -705,10 +739,12 @@ public function addPart(string $target): void
$this->pickerSelected = '';
if (! $this->persistDraft()) {
return;
return false;
}
$this->feedback = $row['title'].' ist in den Aufbau übernommen. Die Datei wird nicht kopiert. Der Entwurf ist gespeichert. Es entsteht keine neue Fassung.';
return true;
}
public function removePart(int $index): void
@@ -796,7 +832,7 @@ public function addText(): void
try {
$service = app(ContentService::class);
$element = $service->createElement('text', 'text', $title);
$version = $service->publishElementVersion($element, $body);
$version = $service->draftElementVersion($element, $body);
} catch (DomainRuleException $exception) {
$this->feedback = $exception->getMessage();
@@ -806,8 +842,62 @@ public function addText(): void
$this->newTextTitle = '';
$this->newTextBody = '';
$this->textOpen = false;
$this->addPart('element:'.$version->id);
$this->feedback = $title.' ist angelegt und in den Aufbau übernommen. Derselbe Text kann später woanders wiederverwendet werden. Der Entwurf ist gespeichert. Es entsteht keine neue Fassung dieses Eintrags.';
if (! $this->includePart('element:'.$version->id, true)) {
return;
}
$this->feedback = $title.' ist angelegt und in den Aufbau übernommen. Der Text bleibt bearbeitbar, solange diese Fassung nicht freigegeben und verwendet wird. Es entsteht keine neue Fassung dieses Eintrags.';
}
public function addFile(): void
{
$title = trim($this->newFileTitle);
$stored = IncomingFile::store($this->incomingFile);
if ($title === '' || $stored === null) {
$this->feedback = 'Das Medium braucht einen Titel und eine Datei.';
return;
}
$extension = strtolower(pathinfo($stored, PATHINFO_EXTENSION));
$shape = match ($extension) {
'mp4', 'webm', 'mov', 'm4v' => ['film', 'film'],
'mp3', 'm4a', 'wav', 'ogg' => ['audio', 'audio'],
'png', 'jpg', 'jpeg', 'webp', 'gif' => ['bild', 'bild'],
'pdf' => ['dokument', 'document'],
default => null,
};
if ($shape === null) {
$this->feedback = 'Diese Dateiart lässt sich hier nicht anlegen.';
return;
}
try {
$service = app(ContentService::class);
$element = $service->createElement($shape[0], $shape[1], $title);
$version = $service->draftElementVersion($element, null, [
'incoming' => $stored,
'hold' => true,
]);
} catch (DomainRuleException $exception) {
$this->feedback = $exception->getMessage();
return;
}
$this->newFileTitle = '';
$this->incomingFile = null;
$this->fileOpen = false;
if (! $this->includePart('element:'.$version->id, true)) {
return;
}
$this->feedback = $title.' ist angelegt und in den Aufbau übernommen. Die Datei liegt bei den Medien. Eine neue Fassung entsteht erst, wenn diese Fassung freigegeben und verwendet wird.';
}
public function startModule(): void
@@ -856,6 +946,7 @@ public function openModule(): void
$this->pickerOpen = false;
$this->partOpen = false;
$this->textOpen = false;
$this->fileOpen = false;
$this->moduleTab = 'beschreibung';
$this->frameFilmChoices = $this->frameFilms();
$films = $this->frameFilmChoices;
@@ -914,10 +1005,14 @@ public function saveModule(): void
public function openPart(int $index): void
{
$this->selectPart($index);
$member = $this->selectedMember();
$this->partTitle = (string) ($member['title'] ?? '');
$this->partBody = (string) ($member['body'] ?? '');
$this->partSnapshot = $this->members;
$this->moduleOpen = false;
$this->pickerOpen = false;
$this->textOpen = false;
$this->fileOpen = false;
$this->partOpen = true;
}
@@ -941,6 +1036,11 @@ public function savePart(): void
}
$this->commitRoleDraft();
$textNote = $this->writePartText();
if ($textNote === false) {
return;
}
if (! $this->persistDraft()) {
return;
@@ -948,7 +1048,9 @@ public function savePart(): void
$this->partOpen = false;
$this->partSnapshot = [];
$this->feedback = 'Die Angaben zum Bestandteil sind im Entwurf. Es entsteht keine neue Fassung.';
$this->feedback = $textNote !== ''
? $textNote
: 'Die Angaben zum Bestandteil sind im Entwurf. Es entsteht keine neue Fassung.';
}
/**
@@ -1098,6 +1200,118 @@ public function adoptPicture(int $elementId): void
$this->feedback = $this->previewFeedback($record, $before);
}
private function writePartText(): string|false
{
$index = $this->selected;
$member = $this->selectedMember();
if ($index === null || $member === null || ($member['output'] ?? '') !== 'text') {
return '';
}
$title = trim($this->partTitle);
$body = trim($this->partBody);
if ($title === '' || $body === '') {
$this->feedback = 'Der Text braucht einen Titel und einen Inhalt.';
return false;
}
if (preg_match('/^element:(\d+)$/', (string) ($member['target'] ?? ''), $match) !== 1) {
return '';
}
$version = ContentElementVersion::query()->with('element')->find($match[1]);
if (! $version instanceof ContentElementVersion || $version->element === null) {
$this->feedback = 'Dieser Text ist nicht mehr vorhanden.';
return false;
}
$changed = $title !== (string) ($member['title'] ?? '') || $body !== trim((string) $version->body);
if (! $changed) {
return '';
}
try {
$service = app(ContentService::class);
$service->describe($version->element, $title, $version->element->description);
$updated = $service->reviseElementContent($version, $body);
} catch (DomainRuleException $exception) {
$this->feedback = $exception->getMessage();
return false;
}
if ($updated->id === $version->id) {
$this->members[$index]['title'] = $title;
$this->members[$index]['body'] = $body;
return 'Der Text ist in derselben Fassung geändert. Eine neue Fassung entsteht, sobald diese Fassung freigegeben und verwendet wird.';
}
$row = app(EditorialCatalog::class)->rowForTarget(
'element:'.$updated->id,
(int) $this->getRecord()->getKey(),
allowSelf: true,
allowDraft: true,
);
if ($row === null) {
$this->feedback = 'Die neue Fassung ließ sich nicht in den Aufbau übernehmen.';
return false;
}
$row['role'] = (string) ($this->members[$index]['role'] ?? $row['kind']);
$row['note'] = (string) ($this->members[$index]['note'] ?? '');
$this->members[$index] = $row;
return 'Die Änderung liegt in einer neuen Fassung. Die bisherige Fassung bleibt in den freigegebenen Aufbauten.';
}
/**
* @param list<array{role: string, target: ContentElementVersion|CompositionVersion, note: string}> $payload
*/
private function promoteDraftElements(array $payload): bool
{
foreach ($payload as $member) {
$target = $member['target'];
if (! $target instanceof ContentElementVersion || $target->status !== ContentVersionStatus::Entwurf) {
continue;
}
$meta = is_array($target->metadata) ? $target->metadata : [];
if (isset($meta['incoming']) && ! isset($meta['file'])) {
$this->feedback = 'Eine Datei wird noch übernommen. Gib den Aufbau frei, sobald die Datei bereitsteht.';
return false;
}
if (isset($meta['error'])) {
$this->feedback = (string) $meta['error'];
return false;
}
unset($meta['held']);
$target->metadata = $meta === [] ? null : $meta;
$target->content_hash = hash('sha256', json_encode([
'body' => $target->body,
'metadata' => $meta,
], JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
$target->status = ContentVersionStatus::Bereit;
$target->save();
}
return true;
}
/**
* @return array{url: ?string, note: ?string, own: bool}
*/
@@ -1210,6 +1424,10 @@ public function publishRevision(): bool
];
}
if (! $this->promoteDraftElements($payload)) {
return false;
}
/** @var Composition $record */
$record = $this->getRecord();
$note = trim($this->revisionNote);
@@ -1343,7 +1561,7 @@ protected function applyDraft(array $draft): void
}
$requested++;
$row = $catalog->rowForTarget((string) ($member['target'] ?? ''), (int) $this->getRecord()->getKey(), allowSelf: true);
$row = $catalog->rowForTarget((string) ($member['target'] ?? ''), (int) $this->getRecord()->getKey(), allowSelf: true, allowDraft: true);
if ($row === null) {
continue;
@@ -3,6 +3,7 @@
namespace App\Filament\Resources\ContentElements;
use App\Domain\Catalog\ContentElement;
use App\Domain\Catalog\ContentVersionStatus;
use App\Domain\Identity\StaffRole;
use App\Filament\Resources\ContentElements\Pages\EditContentElement;
use App\Filament\Resources\ContentElements\Pages\ListContentElements;
@@ -85,8 +86,11 @@ public static function table(Table $table): Table
}
$file = is_array($version->metadata) ? ($version->metadata['file'] ?? null) : null;
$label = $version->status === ContentVersionStatus::Entwurf
? 'Entwurf'
: 'Fassung '.$version->number;
return 'Fassung '.$version->number.(is_string($file) && $file !== '' ? ' · mit Datei' : ' · ohne Datei');
return $label.(is_string($file) && $file !== '' ? ' · mit Datei' : ' · ohne Datei');
}),
]);
}
@@ -39,6 +39,8 @@ class ViewContentElement extends ViewRecord
public string $frameSecond = '';
public string $bodyDraft = '';
public string $thumbnailAlt = '';
public string $pictureFeedback = '';
@@ -56,6 +58,7 @@ public function mount(int|string $record): void
}
$this->thumbnailAlt = (string) ($this->getRecord()->thumbnail_alt ?? '');
$this->syncBodyDraft();
}
public function getSubheading(): string|Htmlable|null
@@ -74,6 +77,25 @@ public function showVersion(int $version): void
{
abort_unless($this->ownedVersion($version) instanceof ContentElementVersion, 404);
$this->fassung = $version;
$this->syncBodyDraft();
}
public function saveShownText(): void
{
$shown = $this->shownVersion();
if (! ContentElementResource::editor() || ! $shown instanceof ContentElementVersion || $shown->element?->output_class !== 'text') {
return;
}
$created = app(ContentService::class)->isCommitted($shown);
$this->report(function () use ($shown): void {
app(ContentService::class)->reviseElementContent($shown, $this->bodyDraft);
}, $created
? 'Die neue Fassung ist angelegt. Die bisherige bleibt erhalten.'
: 'Der Text ist in derselben Fassung gespeichert.');
$this->getRecord()->unsetRelation('versions');
$this->syncBodyDraft();
}
public function adoptFrame(): void
@@ -282,6 +304,7 @@ private function viewerData(): array
?? $versions->first(fn (ContentElementVersion $version): bool => $version->status === ContentVersionStatus::Bereit)
?? $versions->first();
$preview = app(ContentPreviewController::class);
$committed = $shown instanceof ContentElementVersion && app(ContentService::class)->isCommitted($shown);
return [
'element' => $element,
@@ -292,11 +315,21 @@ private function viewerData(): array
'pillars' => $element->pillars->pluck('name')->all(),
'usage' => app(CatalogReading::class)->elementUsage($element),
'canRevise' => ContentElementResource::editor(),
'canEditBody' => ContentElementResource::editor()
&& $shown instanceof ContentElementVersion
&& $element->output_class === 'text'
&& $shown->status !== ContentVersionStatus::Gesperrt,
'bodyCommitted' => $committed,
'pictureUrl' => ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path),
'pictureCaption' => $this->pictureCaption($element),
];
}
private function syncBodyDraft(): void
{
$this->bodyDraft = (string) ($this->shownVersion()?->body ?? '');
}
private function shownVersion(): ?ContentElementVersion
{
/** @var ContentElement $element */
+14 -6
View File
@@ -40,7 +40,7 @@ public function rows(CompositionVersion $version, int $exceptCompositionId): arr
$target = $member->content_element_version_id
? 'element:'.$member->content_element_version_id
: 'composition:'.$member->nested_composition_version_id;
$row = $this->rowForTarget($target, $exceptCompositionId, allowSelf: true);
$row = $this->rowForTarget($target, $exceptCompositionId, allowSelf: true, allowDraft: true);
if ($row === null) {
continue;
@@ -57,7 +57,7 @@ public function rows(CompositionVersion $version, int $exceptCompositionId): arr
/**
* @return array<string, string|null>|null
*/
public function rowForTarget(string $target, int $exceptCompositionId, bool $allowSelf = false): ?array
public function rowForTarget(string $target, int $exceptCompositionId, bool $allowSelf = false, bool $allowDraft = false): ?array
{
if (preg_match('/^(element|composition):(\d+)$/', $target, $match) !== 1) {
return null;
@@ -67,8 +67,13 @@ public function rowForTarget(string $target, int $exceptCompositionId, bool $all
$version = ContentElementVersion::query()
->with('element.editorialContentKind')
->find($match[2]);
$acceptable = [ContentVersionStatus::Bereit];
if (! $version instanceof ContentElementVersion || $version->status !== ContentVersionStatus::Bereit) {
if ($allowDraft) {
$acceptable[] = ContentVersionStatus::Entwurf;
}
if (! $version instanceof ContentElementVersion || ! in_array($version->status, $acceptable, true)) {
return null;
}
@@ -80,13 +85,16 @@ public function rowForTarget(string $target, int $exceptCompositionId, bool $all
'target' => 'element:'.$version->id,
'title' => $title,
'kind' => $kind,
'output' => (string) $element->output_class,
'body' => (string) ($version->body ?? ''),
'summary' => (string) ($element->summary ?: $element->description ?: ''),
'medium_description' => (string) ($element->description ?? ''),
'usage_note' => (string) ($element->usage_note ?? ''),
'license_note' => (string) ($element->license_note ?? ''),
'tone' => $this->tone((string) $element->output_class, $kind),
'image' => $this->cardUrl('element', $element->id, $element->thumbnail_path),
'version_label' => 'Fassung '.$version->number,
'version_label' => $version->status === ContentVersionStatus::Entwurf ? 'Entwurf' : 'Fassung '.$version->number,
'committed' => app(ContentService::class)->isCommitted($version),
'identity' => 'medium:'.$element->id,
'open_url' => route('content.preview', $version),
'open_label' => 'Medium ansehen',
@@ -119,8 +127,8 @@ public function rowForTarget(string $target, int $exceptCompositionId, bool $all
'image' => $this->cardUrl('komposition', $composition->id, $composition->thumbnail_path),
'version_label' => 'Fassung '.$version->number,
'identity' => 'zusammenstellung:'.$composition->id,
'open_url' => null,
'open_label' => null,
'open_url' => route('editorial.preview', ['composition' => $composition, 'version' => $version]),
'open_label' => 'Aufbau ansehen',
'edit_url' => self::editUrl($composition),
];
}
+12 -2
View File
@@ -63,14 +63,24 @@ public function handle(): void
}
$metadata = $version->metadata ?? [];
unset($metadata['incoming']);
$hold = ($metadata['hold'] ?? false) === true;
unset($metadata['incoming'], $metadata['hold']);
$metadata['file'] = $target;
if ($hold) {
$metadata['held'] = true;
}
$version->metadata = $metadata;
$version->content_hash = hash('sha256', json_encode([
'body' => $version->body,
'metadata' => $metadata,
], JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
$version->status = ContentVersionStatus::Bereit;
if (! $hold) {
$version->status = ContentVersionStatus::Bereit;
}
$version->save();
DeriveThumbnail::dispatch('element', $version->content_element_id);
DeriveFilmRenditions::dispatch($version->id);