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

+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
*/