Zeige vor der Freigabe die enthaltene Struktur und gib Entwürfe nur mit Zustimmung frei.
Deploy Test / test (push) Successful in 26s
Deploy Test / deploy (push) Successful in 27s

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-11-17 13:26:52 +01:00
1 parent 1168c04228
commit d12ba67b45
9 files changed
+934 -88

No files matched your search

@@ -5,6 +5,7 @@
use App\Domain\Catalog\Composition;
use App\Domain\Catalog\CompositionDisplayRelease;
use App\Domain\Catalog\CompositionKind;
use App\Domain\Catalog\CompositionRelease;
use App\Domain\Catalog\CompositionStructureReader;
use App\Domain\Catalog\CompositionVersion;
use App\Domain\Catalog\ContentElement;
@@ -19,6 +20,7 @@
use App\Domain\Catalog\IdentityDimensionValue;
use App\Domain\Catalog\IdentityProfile;
use App\Domain\Catalog\StructureNode;
use App\Filament\Resources\ContentElements\ContentElementResource;
use App\Filament\Support\EditorialCatalog;
use App\Filament\Support\MediumForm;
use App\Http\Controllers\ContentPreviewController;
@@ -93,6 +95,10 @@ abstract class EditComposition extends EditRecord
public bool $releaseArmed = false;
public bool $releaseConsent = false;
public bool $returnAfterRelease = false;
public string $returnUrl = '';
public ?int $templateNumber = null;
@@ -448,12 +454,51 @@ public function armRelease(): void
return;
}
$this->releaseConsent = false;
$this->releaseArmed = true;
}
public function cancelRelease(): void
{
$this->releaseArmed = false;
$this->releaseConsent = false;
$this->returnAfterRelease = false;
}
/**
* @return array<string, mixed>
*/
public function releaseReview(): array
{
/** @var Composition $composition */
$composition = $this->getRecord();
$review = app(CompositionRelease::class)->review($composition, $this->members);
foreach ($review['blocked'] as $index => $item) {
$review['blocked'][$index]['edit_url'] = $this->releaseEditUrl($item['edit'] ?? null);
}
return $review;
}
public function releaseFollowUp(): string
{
$version = $this->currentReadyVersion();
if ($version === null) {
return '';
}
/** @var Composition $composition */
$composition = $this->getRecord();
$library = app(CompositionDisplayRelease::class)->isReleased($version)
? 'In der Mitgliederbibliothek ist Fassung '.$version->number.' sichtbar.'
: 'In der Mitgliederbibliothek ist noch keine Fassung sichtbar. „In Mitgliederbibliothek anzeigen“ wählt die letzte freigegebene Fassung. Das veröffentlicht weder die Website noch ein Angebot.';
$draft = is_array($composition->working_draft) && $composition->working_draft !== []
? ' Es gibt einen gespeicherten Entwurf neben der freigegebenen Fassung.'
: ' Es gibt keinen offenen Entwurf. Änderungen hältst du mit „Entwurf speichern“ fest.';
return $library.$draft;
}
public function discardDraft(): void
@@ -621,6 +666,23 @@ public function selectedAlternatives(): array
public function childrenOf(string $target): string
{
if (preg_match('/^composition-draft:(\d+)$/', $target, $match) === 1) {
$composition = Composition::query()->find($match[1]);
$draft = $composition instanceof Composition && is_array($composition->working_draft) ? $composition->working_draft : [];
$lines = [];
foreach ($draft['members'] ?? [] as $member) {
if (! is_array($member)) {
continue;
}
$row = app(EditorialCatalog::class)->rowForTarget((string) ($member['target'] ?? ''), (int) $this->getRecord()->getKey(), allowSelf: true, allowDraft: true);
$lines[] = trim((string) ($member['role'] ?? '')).': '.($row['title'] ?? 'Bestandteil');
}
return implode(' · ', $lines);
}
if (preg_match('/^composition:(\d+)$/', $target, $match) !== 1) {
return '';
}
@@ -681,7 +743,7 @@ public function addPart(string $target): void
private function includePart(string $target, bool $allowDraft): bool
{
if (preg_match('/^(element|composition):\d+$/', $target) !== 1) {
if (preg_match('/^(element:\d+|composition:\d+|composition-draft:\d+)$/', $target) !== 1) {
$this->feedback = 'Dieser Bestandteil ist nicht verfügbar.';
return false;
@@ -1307,42 +1369,25 @@ private function writePartText(): string|false
}
/**
* @param list<array{role: string, target: ContentElementVersion|CompositionVersion, note: string}> $payload
* @param array{type: string, id: int}|null $edit
*/
private function promoteDraftElements(array $payload): bool
private function releaseEditUrl(?array $edit): ?string
{
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();
if ($edit === null) {
return null;
}
return true;
if ($edit['type'] === 'element') {
$element = ContentElement::query()->find($edit['id']);
return $element instanceof ContentElement
? ContentElementResource::getUrl('view', ['record' => $element])
: null;
}
$composition = Composition::query()->find($edit['id']);
return $composition instanceof Composition ? EditorialCatalog::editUrl($composition) : null;
}
/**
@@ -1428,47 +1473,14 @@ public function publishRevision(): bool
return false;
}
$payload = [];
foreach (array_values($this->members) as $member) {
$role = trim((string) ($member['role'] ?? ''));
$target = (string) ($member['target'] ?? '');
if ($role === '' || preg_match('/^(element|composition):(\d+)$/', $target, $match) !== 1) {
$this->feedback = 'Jeder Bestandteil braucht eine Rolle und eine vorhandene Fassung.';
return false;
}
$model = $match[1] === 'composition'
? CompositionVersion::query()->find($match[2])
: ContentElementVersion::query()->find($match[2]);
if ($model === null) {
$this->feedback = 'Ein Bestandteil ist nicht mehr vorhanden.';
return false;
}
$payload[] = [
'role' => $role,
'target' => $model,
'note' => trim((string) ($member['note'] ?? '')),
];
}
if (! $this->promoteDraftElements($payload)) {
return false;
}
/** @var Composition $record */
$record = $this->getRecord();
$note = trim($this->revisionNote);
try {
app(ContentService::class)->publishComposition(
app(CompositionRelease::class)->publish(
$record,
$payload,
$this->members,
$this->actor(),
$note !== '' ? $note : null,
[
@@ -1476,9 +1488,11 @@ public function publishRevision(): bool
'duration_minutes' => $minutes,
'material_note' => $this->blank($this->materialNote),
],
$this->releaseConsent,
);
} catch (DomainRuleException $exception) {
$this->feedback = $exception->getMessage();
$this->releaseArmed = true;
return false;
}
@@ -1486,9 +1500,17 @@ public function publishRevision(): bool
$this->revisionNote = '';
$this->templateNumber = null;
$this->releaseArmed = false;
$this->releaseConsent = false;
app(EditorialWorkingDraft::class)->clear($record);
$this->loadEditor();
$this->feedback = 'Die neue Fassung ist übernommen. Die bisherige Fassung bleibt erhalten.';
$released = $this->currentReadyVersion();
$number = $released instanceof CompositionVersion ? $released->number : '';
$this->feedback = 'Fassung '.$number.' ist freigegeben. Der Entwurf ist geschlossen und die bisherige Fassung bleibt erhalten. Die Mitgliederbibliothek ändert sich dadurch nicht.';
if ($this->returnAfterRelease) {
$this->returnAfterRelease = false;
$this->finishReturn();
}
return true;
}
@@ -1500,11 +1522,17 @@ public function returnAndInclude(): void
}
if ($this->needsRevision()) {
if (! $this->publishRevision()) {
return;
}
$this->returnAfterRelease = true;
$this->armRelease();
return;
}
$this->finishReturn();
}
private function finishReturn(): void
{
$version = $this->currentReadyVersion();
$url = $this->returnUrl;