Zeige vor der Freigabe die enthaltene Struktur und gib Entwürfe nur mit Zustimmung frei.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
1168c04228
commit
d12ba67b45
9 files changed
+934
-88
No files matched your search
@@ -0,0 +1,467 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Catalog;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class CompositionRelease
|
||||
{
|
||||
/** @var array<int, CompositionVersion> */
|
||||
private array $publishedDrafts = [];
|
||||
|
||||
/**
|
||||
* @param list<array<string, mixed>> $members
|
||||
* @return array{
|
||||
* host_label: string,
|
||||
* title: string,
|
||||
* next_label: string,
|
||||
* ready: list<array{title: string, detail: string, depth: int}>,
|
||||
* pending: list<array{title: string, detail: string, depth: int}>,
|
||||
* blocked: list<array{title: string, detail: string, depth: int, edit: array{type: string, id: int}|null}>,
|
||||
* needs_consent: bool,
|
||||
* nested_draft: bool
|
||||
* }
|
||||
*/
|
||||
public function review(Composition $host, array $members): array
|
||||
{
|
||||
$ready = [];
|
||||
$pending = [];
|
||||
$blocked = [];
|
||||
$nestedDraft = false;
|
||||
$this->inspectMembers($members, 0, [$host->id], false, $ready, $pending, $blocked, $nestedDraft);
|
||||
|
||||
return [
|
||||
'host_label' => $this->label($host),
|
||||
'title' => $this->title($host),
|
||||
'next_label' => 'Fassung '.(((int) $host->versions()->max('number')) + 1),
|
||||
'ready' => $ready,
|
||||
'pending' => $pending,
|
||||
'blocked' => $blocked,
|
||||
'needs_consent' => $pending !== [],
|
||||
'nested_draft' => $nestedDraft,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<array<string, mixed>> $members
|
||||
* @param array{learning_goal?: mixed, duration_minutes?: mixed, material_note?: mixed} $didactic
|
||||
*/
|
||||
public function publish(
|
||||
Composition $host,
|
||||
array $members,
|
||||
?User $actor,
|
||||
?string $note,
|
||||
array $didactic,
|
||||
bool $consent,
|
||||
): CompositionVersion {
|
||||
$review = $this->review($host, $members);
|
||||
|
||||
if ($review['blocked'] !== []) {
|
||||
throw new DomainRuleException($review['blocked'][0]['detail']);
|
||||
}
|
||||
|
||||
if ($review['needs_consent'] && ! $consent) {
|
||||
throw new DomainRuleException('Noch nicht freigegebene Bestandteile werden nur mit ausdrücklicher Zustimmung freigegeben.');
|
||||
}
|
||||
|
||||
$this->publishedDrafts = [];
|
||||
|
||||
return DB::transaction(function () use ($host, $members, $actor, $note, $didactic): CompositionVersion {
|
||||
return $this->materialize($host, $members, $didactic, $actor, $note, []);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<array<string, mixed>> $members
|
||||
* @param list<int> $stack
|
||||
* @param list<array{title: string, detail: string, depth: int}> $ready
|
||||
* @param list<array{title: string, detail: string, depth: int}> $pending
|
||||
* @param list<array{title: string, detail: string, depth: int, edit: array{type: string, id: int}|null}> $blocked
|
||||
*/
|
||||
private function inspectMembers(
|
||||
array $members,
|
||||
int $depth,
|
||||
array $stack,
|
||||
bool $frozen,
|
||||
array &$ready,
|
||||
array &$pending,
|
||||
array &$blocked,
|
||||
bool &$nestedDraft,
|
||||
): void {
|
||||
foreach ($members as $member) {
|
||||
if (! is_array($member)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$role = trim((string) ($member['role'] ?? ''));
|
||||
$target = (string) ($member['target'] ?? '');
|
||||
|
||||
if ($role === '' || $target === '') {
|
||||
$blocked[] = $this->block('Bestandteil', 'Jeder Bestandteil braucht eine Rolle und eine vorhandene Fassung.', $depth, null);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->inspectTarget($target, $role, $depth, $stack, $frozen, $ready, $pending, $blocked, $nestedDraft);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<int> $stack
|
||||
* @param list<array{title: string, detail: string, depth: int}> $ready
|
||||
* @param list<array{title: string, detail: string, depth: int}> $pending
|
||||
* @param list<array{title: string, detail: string, depth: int, edit: array{type: string, id: int}|null}> $blocked
|
||||
*/
|
||||
private function inspectTarget(
|
||||
string $target,
|
||||
string $role,
|
||||
int $depth,
|
||||
array $stack,
|
||||
bool $frozen,
|
||||
array &$ready,
|
||||
array &$pending,
|
||||
array &$blocked,
|
||||
bool &$nestedDraft,
|
||||
): void {
|
||||
if (preg_match('/^element:(\d+)$/', $target, $match) === 1) {
|
||||
$this->inspectElement((int) $match[1], $role, $depth, $frozen, $ready, $pending, $blocked);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (preg_match('/^composition:(\d+)$/', $target, $match) === 1) {
|
||||
$this->inspectReleasedComposition((int) $match[1], $role, $depth, $stack, $ready, $pending, $blocked, $nestedDraft);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (preg_match('/^composition-draft:(\d+)$/', $target, $match) === 1) {
|
||||
$this->inspectDraftComposition((int) $match[1], $role, $depth, $stack, $frozen, $ready, $pending, $blocked, $nestedDraft);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$blocked[] = $this->block('Bestandteil', 'Ein Bestandteil ist nicht mehr vorhanden.', $depth, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<array{title: string, detail: string, depth: int}> $ready
|
||||
* @param list<array{title: string, detail: string, depth: int}> $pending
|
||||
* @param list<array{title: string, detail: string, depth: int, edit: array{type: string, id: int}|null}> $blocked
|
||||
*/
|
||||
private function inspectElement(
|
||||
int $id,
|
||||
string $role,
|
||||
int $depth,
|
||||
bool $frozen,
|
||||
array &$ready,
|
||||
array &$pending,
|
||||
array &$blocked,
|
||||
): void {
|
||||
$version = ContentElementVersion::query()->with('element')->find($id);
|
||||
$title = $version?->element === null
|
||||
? 'Medium'
|
||||
: (filled($version->element->display_title) ? $version->element->display_title : $version->element->working_title);
|
||||
$edit = $version?->element === null ? null : ['type' => 'element', 'id' => $version->element->id];
|
||||
|
||||
if (! $version instanceof ContentElementVersion || $version->element === null) {
|
||||
$blocked[] = $this->block($title, 'Ein Medium ist nicht mehr vorhanden.', $depth, null);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$kind = $this->outputLabel((string) $version->element->output_class);
|
||||
|
||||
if ($version->status === ContentVersionStatus::Bereit) {
|
||||
$ready[] = $this->line($title, $kind.' · '.$role.' · Fassung '.$version->number.', bleibt unverändert', $depth);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($version->status === ContentVersionStatus::Gesperrt) {
|
||||
$blocked[] = $this->block($title, $kind.' · '.$role.'. Diese Fassung ist deaktiviert und kann nicht freigegeben werden.', $depth, $edit);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$problem = app(ContentService::class)->elementReleaseProblem($version);
|
||||
|
||||
if ($frozen) {
|
||||
$blocked[] = $this->block($title, $kind.' · '.$role.'. Eine bereits freigegebene Fassung verweist auf diesen Entwurf. Sie bleibt unverändert.', $depth, $edit);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($problem !== null) {
|
||||
$blocked[] = $this->block($title, $kind.' · '.$role.'. '.$problem, $depth, $edit);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$pending[] = $this->line($title, $kind.' · '.$role.'. Der Entwurf wird freigegeben. Es entsteht keine weitere Fassung.', $depth);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<int> $stack
|
||||
* @param list<array{title: string, detail: string, depth: int}> $ready
|
||||
* @param list<array{title: string, detail: string, depth: int}> $pending
|
||||
* @param list<array{title: string, detail: string, depth: int, edit: array{type: string, id: int}|null}> $blocked
|
||||
*/
|
||||
private function inspectReleasedComposition(
|
||||
int $id,
|
||||
string $role,
|
||||
int $depth,
|
||||
array $stack,
|
||||
array &$ready,
|
||||
array &$pending,
|
||||
array &$blocked,
|
||||
bool &$nestedDraft,
|
||||
): void {
|
||||
$version = CompositionVersion::query()->with('composition', 'members')->find($id);
|
||||
|
||||
if (! $version instanceof CompositionVersion || $version->composition === null) {
|
||||
$blocked[] = $this->block('Modul', 'Ein Bestandteil ist nicht mehr vorhanden.', $depth, null);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$title = $this->title($version->composition);
|
||||
$kind = $this->label($version->composition);
|
||||
|
||||
if (in_array($version->composition_id, $stack, true)) {
|
||||
$blocked[] = $this->block($title, $kind.' · '.$role.'. Der Aufbau verweist auf sich selbst. So kann nichts freigegeben werden.', $depth, ['type' => 'composition', 'id' => $version->composition_id]);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($version->status !== ContentVersionStatus::Bereit) {
|
||||
$blocked[] = $this->block($title, $kind.' · '.$role.'. Diese Fassung ist nicht freigegeben.', $depth, ['type' => 'composition', 'id' => $version->composition_id]);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$ready[] = $this->line($title, $kind.' · '.$role.' · Fassung '.$version->number.', bleibt unverändert', $depth);
|
||||
$nested = [];
|
||||
|
||||
foreach ($version->members()->orderBy('position')->get() as $member) {
|
||||
$target = $member->content_element_version_id
|
||||
? 'element:'.$member->content_element_version_id
|
||||
: 'composition:'.$member->nested_composition_version_id;
|
||||
$nested[] = ['role' => (string) $member->role, 'target' => $target, 'note' => (string) ($member->placement_note ?? '')];
|
||||
}
|
||||
|
||||
$this->inspectMembers($nested, $depth + 1, [...$stack, $version->composition_id], true, $ready, $pending, $blocked, $nestedDraft);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<int> $stack
|
||||
* @param list<array{title: string, detail: string, depth: int}> $ready
|
||||
* @param list<array{title: string, detail: string, depth: int}> $pending
|
||||
* @param list<array{title: string, detail: string, depth: int, edit: array{type: string, id: int}|null}> $blocked
|
||||
*/
|
||||
private function inspectDraftComposition(
|
||||
int $id,
|
||||
string $role,
|
||||
int $depth,
|
||||
array $stack,
|
||||
bool $frozen,
|
||||
array &$ready,
|
||||
array &$pending,
|
||||
array &$blocked,
|
||||
bool &$nestedDraft,
|
||||
): void {
|
||||
$composition = Composition::query()->find($id);
|
||||
$edit = ['type' => 'composition', 'id' => $id];
|
||||
|
||||
if (! $composition instanceof Composition) {
|
||||
$blocked[] = $this->block('Modul', 'Ein Modul ist nicht mehr vorhanden.', $depth, null);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$title = $this->title($composition);
|
||||
$kind = $this->label($composition);
|
||||
|
||||
if ($frozen || in_array($id, $stack, true)) {
|
||||
$blocked[] = $this->block($title, $kind.' · '.$role.'. Der Aufbau verweist auf sich selbst. So kann nichts freigegeben werden.', $depth, $edit);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$draft = is_array($composition->working_draft) ? $composition->working_draft : [];
|
||||
$members = is_array($draft['members'] ?? null) ? $draft['members'] : [];
|
||||
|
||||
if ($members === []) {
|
||||
$blocked[] = $this->block($title, $kind.' · '.$role.'. Der gespeicherte Entwurf hat keinen Bestandteil.', $depth, $edit);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$minutes = $draft['duration_minutes'] ?? null;
|
||||
|
||||
if ($minutes !== null && $minutes !== '' && ! is_int($minutes)) {
|
||||
$blocked[] = $this->block($title, $kind.' · '.$role.'. Der Zeitbedarf ist keine Zahl von Minuten.', $depth, $edit);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$nestedDraft = true;
|
||||
$number = ((int) $composition->versions()->max('number')) + 1;
|
||||
$pending[] = $this->line($title, $kind.' · '.$role.'. Es entsteht Fassung '.$number.'.', $depth);
|
||||
$this->inspectMembers($members, $depth + 1, [...$stack, $id], false, $ready, $pending, $blocked, $nestedDraft);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<array<string, mixed>> $members
|
||||
* @param array{learning_goal?: mixed, duration_minutes?: mixed, material_note?: mixed} $didactic
|
||||
* @param list<int> $stack
|
||||
*/
|
||||
private function materialize(
|
||||
Composition $composition,
|
||||
array $members,
|
||||
array $didactic,
|
||||
?User $actor,
|
||||
?string $note,
|
||||
array $stack,
|
||||
): CompositionVersion {
|
||||
if (isset($this->publishedDrafts[$composition->id])) {
|
||||
return $this->publishedDrafts[$composition->id];
|
||||
}
|
||||
|
||||
if (in_array($composition->id, $stack, true)) {
|
||||
throw new DomainRuleException('Der Aufbau verweist auf sich selbst. So kann nichts freigegeben werden.');
|
||||
}
|
||||
|
||||
$stack[] = $composition->id;
|
||||
$payload = [];
|
||||
|
||||
foreach (array_values($members) as $member) {
|
||||
$payload[] = [
|
||||
'role' => trim((string) ($member['role'] ?? '')),
|
||||
'note' => trim((string) ($member['note'] ?? '')),
|
||||
'target' => $this->resolveTarget((string) ($member['target'] ?? ''), $actor, $stack),
|
||||
];
|
||||
}
|
||||
|
||||
$version = app(ContentService::class)->publishComposition(
|
||||
$composition,
|
||||
$payload,
|
||||
$actor,
|
||||
$note,
|
||||
[
|
||||
'learning_goal' => $didactic['learning_goal'] ?? null,
|
||||
'duration_minutes' => $didactic['duration_minutes'] ?? null,
|
||||
'material_note' => $didactic['material_note'] ?? null,
|
||||
],
|
||||
);
|
||||
$this->publishedDrafts[$composition->id] = $version;
|
||||
|
||||
return $version;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<int> $stack
|
||||
*/
|
||||
private function resolveTarget(string $target, ?User $actor, array $stack): ContentElementVersion|CompositionVersion
|
||||
{
|
||||
if (preg_match('/^element:(\d+)$/', $target, $match) === 1) {
|
||||
$version = ContentElementVersion::query()->find($match[1]);
|
||||
|
||||
if (! $version instanceof ContentElementVersion) {
|
||||
throw new DomainRuleException('Ein Medium ist nicht mehr vorhanden.');
|
||||
}
|
||||
|
||||
if ($version->status === ContentVersionStatus::Entwurf) {
|
||||
$version = app(ContentService::class)->releaseElementVersion($version);
|
||||
}
|
||||
|
||||
if ($version->status !== ContentVersionStatus::Bereit) {
|
||||
throw new DomainRuleException('Eine deaktivierte Fassung lässt sich nicht freigeben.');
|
||||
}
|
||||
|
||||
return $version;
|
||||
}
|
||||
|
||||
if (preg_match('/^composition:(\d+)$/', $target, $match) === 1) {
|
||||
$version = CompositionVersion::query()->find($match[1]);
|
||||
|
||||
if (! $version instanceof CompositionVersion || $version->status !== ContentVersionStatus::Bereit) {
|
||||
throw new DomainRuleException('Eine bereits erwartete Fassung ist nicht mehr freigegeben.');
|
||||
}
|
||||
|
||||
return $version;
|
||||
}
|
||||
|
||||
if (preg_match('/^composition-draft:(\d+)$/', $target, $match) !== 1) {
|
||||
throw new DomainRuleException('Ein Bestandteil ist nicht mehr vorhanden.');
|
||||
}
|
||||
|
||||
$composition = Composition::query()->find($match[1]);
|
||||
|
||||
if (! $composition instanceof Composition) {
|
||||
throw new DomainRuleException('Ein Modul ist nicht mehr vorhanden.');
|
||||
}
|
||||
|
||||
if (isset($this->publishedDrafts[$composition->id])) {
|
||||
return $this->publishedDrafts[$composition->id];
|
||||
}
|
||||
|
||||
$draft = is_array($composition->working_draft) ? $composition->working_draft : [];
|
||||
$version = $this->materialize(
|
||||
$composition,
|
||||
is_array($draft['members'] ?? null) ? $draft['members'] : [],
|
||||
[
|
||||
'learning_goal' => $draft['learning_goal'] ?? null,
|
||||
'duration_minutes' => $draft['duration_minutes'] ?? null,
|
||||
'material_note' => $draft['material_note'] ?? null,
|
||||
],
|
||||
$actor,
|
||||
is_string($draft['revision_note'] ?? null) ? $draft['revision_note'] : null,
|
||||
$stack,
|
||||
);
|
||||
app(EditorialWorkingDraft::class)->clear($composition);
|
||||
|
||||
return $version;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{title: string, detail: string, depth: int}
|
||||
*/
|
||||
private function line(string $title, string $detail, int $depth): array
|
||||
{
|
||||
return ['title' => $title, 'detail' => $detail, 'depth' => $depth];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array{type: string, id: int}|null $edit
|
||||
* @return array{title: string, detail: string, depth: int, edit: array{type: string, id: int}|null}
|
||||
*/
|
||||
private function block(string $title, string $detail, int $depth, ?array $edit): array
|
||||
{
|
||||
return ['title' => $title, 'detail' => $detail, 'depth' => $depth, 'edit' => $edit];
|
||||
}
|
||||
|
||||
private function title(Composition $composition): string
|
||||
{
|
||||
return filled($composition->display_title) ? (string) $composition->display_title : (string) $composition->designation;
|
||||
}
|
||||
|
||||
private function outputLabel(string $outputClass): string
|
||||
{
|
||||
return match ($outputClass) {
|
||||
'film' => 'Film',
|
||||
'audio' => 'Hörstück',
|
||||
'bild' => 'Bild',
|
||||
'document', 'pdf' => 'Dokument',
|
||||
default => 'Text',
|
||||
};
|
||||
}
|
||||
|
||||
private function label(Composition $composition): string
|
||||
{
|
||||
$kind = $composition->kind;
|
||||
|
||||
return ($kind instanceof CompositionKind ? $kind : CompositionKind::from((string) $kind))->deskLabel();
|
||||
}
|
||||
}
|
||||
@@ -164,6 +164,66 @@ public function reviseElementContent(ContentElementVersion $version, string $bod
|
||||
return $version->refresh();
|
||||
}
|
||||
|
||||
public function elementReleaseProblem(ContentElementVersion $version): ?string
|
||||
{
|
||||
$version->loadMissing('element');
|
||||
|
||||
if ($version->status === ContentVersionStatus::Gesperrt) {
|
||||
return 'Diese Fassung ist deaktiviert und kann nicht freigegeben werden.';
|
||||
}
|
||||
|
||||
if ($version->status === ContentVersionStatus::Bereit) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$meta = is_array($version->metadata) ? $version->metadata : [];
|
||||
|
||||
if (isset($meta['incoming']) && ! isset($meta['file'])) {
|
||||
return 'Die Datei ist noch nicht übernommen. Die Freigabe wartet, bis die Datei bereitsteht.';
|
||||
}
|
||||
|
||||
if (isset($meta['error']) && is_string($meta['error']) && trim($meta['error']) !== '') {
|
||||
return trim($meta['error']);
|
||||
}
|
||||
|
||||
if ($version->element?->output_class === 'text' && trim((string) $version->body) === '') {
|
||||
return 'Der Text braucht einen Inhalt.';
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function releaseElementVersion(ContentElementVersion $version): ContentElementVersion
|
||||
{
|
||||
$version->loadMissing('element');
|
||||
|
||||
if ($version->status === ContentVersionStatus::Bereit) {
|
||||
return $version;
|
||||
}
|
||||
|
||||
if ($version->status !== ContentVersionStatus::Entwurf) {
|
||||
throw new DomainRuleException('Eine deaktivierte Fassung lässt sich nicht freigeben.');
|
||||
}
|
||||
|
||||
$problem = $this->elementReleaseProblem($version);
|
||||
|
||||
if ($problem !== null) {
|
||||
throw new DomainRuleException($problem);
|
||||
}
|
||||
|
||||
$meta = is_array($version->metadata) ? $version->metadata : [];
|
||||
unset($meta['held']);
|
||||
$version->metadata = $meta === [] ? null : $meta;
|
||||
$version->content_hash = hash('sha256', json_encode([
|
||||
'body' => $version->body,
|
||||
'metadata' => $meta,
|
||||
], JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
$version->status = ContentVersionStatus::Bereit;
|
||||
$version->save();
|
||||
|
||||
return $version->refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<array{role: string, target: ContentElementVersion|CompositionVersion}> $members
|
||||
*/
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -276,6 +276,23 @@ protected function getHeaderActions(): array
|
||||
}, 'Die Beschreibung ist gespeichert.');
|
||||
$this->getRecord()->refresh();
|
||||
}),
|
||||
Action::make('releaseVersion')
|
||||
->label('Fassung freigeben')
|
||||
->modalHeading('Fassung freigeben')
|
||||
->modalDescription('Diese Fassung wird freigegeben. Sie erscheint dadurch nicht in der Mitgliederbibliothek, nicht auf der Website und nicht in einem Angebot. Eine deaktivierte Fassung bleibt unverändert.')
|
||||
->modalSubmitActionLabel('Freigeben')
|
||||
->visible(fn (): bool => ContentElementResource::editor())
|
||||
->action(function (array $arguments): void {
|
||||
abort_unless(ContentElementResource::editor(), 403);
|
||||
$this->report(function () use ($arguments): string {
|
||||
$version = $this->ownedVersion((int) ($arguments['version'] ?? 0));
|
||||
abort_unless($version instanceof ContentElementVersion, 404);
|
||||
$released = app(ContentService::class)->releaseElementVersion($version);
|
||||
|
||||
return 'Fassung '.$released->number.' ist freigegeben.';
|
||||
}, 'Die Fassung ist freigegeben.');
|
||||
$this->getRecord()->unsetRelation('versions');
|
||||
}),
|
||||
Action::make('revise')
|
||||
->label('Neue Fassung anlegen')
|
||||
->visible(fn (): bool => ContentElementResource::editor())
|
||||
|
||||
@@ -59,6 +59,10 @@ public function rows(CompositionVersion $version, int $exceptCompositionId): arr
|
||||
*/
|
||||
public function rowForTarget(string $target, int $exceptCompositionId, bool $allowSelf = false, bool $allowDraft = false): ?array
|
||||
{
|
||||
if (preg_match('/^composition-draft:(\d+)$/', $target, $draftMatch) === 1) {
|
||||
return $this->draftCompositionRow((int) $draftMatch[1], $exceptCompositionId, $allowSelf);
|
||||
}
|
||||
|
||||
if (preg_match('/^(element|composition):(\d+)$/', $target, $match) !== 1) {
|
||||
return null;
|
||||
}
|
||||
@@ -134,6 +138,39 @@ public function rowForTarget(string $target, int $exceptCompositionId, bool $all
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string|null>|null
|
||||
*/
|
||||
private function draftCompositionRow(int $compositionId, int $exceptCompositionId, bool $allowSelf): ?array
|
||||
{
|
||||
if (! $allowSelf && $compositionId === $exceptCompositionId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$composition = Composition::query()->with('editorialContentKind')->find($compositionId);
|
||||
|
||||
if (! $composition instanceof Composition) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$kind = $composition->editorialContentKind?->label
|
||||
?: ($composition->kind instanceof CompositionKind ? $composition->kind->deskLabel() : 'Zusammenstellung');
|
||||
|
||||
return [
|
||||
'target' => 'composition-draft:'.$composition->id,
|
||||
'title' => $this->compositionTitle($composition),
|
||||
'kind' => $kind,
|
||||
'summary' => (string) ($composition->summary ?? ''),
|
||||
'tone' => $this->tone('', $kind),
|
||||
'image' => $this->cardUrl('komposition', $composition->id, $composition->thumbnail_path),
|
||||
'version_label' => 'Entwurf',
|
||||
'identity' => 'zusammenstellung:'.$composition->id,
|
||||
'open_url' => route('editorial.draft-preview', ['composition' => $composition]),
|
||||
'open_label' => 'Entwurf ansehen',
|
||||
'edit_url' => self::editUrl($composition),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<array<string, string|null>>
|
||||
*/
|
||||
@@ -280,6 +317,43 @@ public function browse(string $query, string $kind, string $dimension, int $exce
|
||||
$rows[] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
$unreleased = Composition::query()
|
||||
->where('id', '!=', $exceptCompositionId)
|
||||
->whereNotNull('working_draft')
|
||||
->whereDoesntHave('versions', function ($builder): void {
|
||||
$builder->where('status', ContentVersionStatus::Bereit);
|
||||
})
|
||||
->when($kind === 'modul', function ($builder): void {
|
||||
$builder->where('kind', CompositionKind::Uebung);
|
||||
})
|
||||
->orderByDesc('id')
|
||||
->get();
|
||||
|
||||
foreach ($unreleased as $composition) {
|
||||
$draft = is_array($composition->working_draft) ? $composition->working_draft : [];
|
||||
$draftMembers = is_array($draft['members'] ?? null) ? $draft['members'] : [];
|
||||
|
||||
if ($draftMembers === []) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($dimensionId > 0 && ! in_array($composition->id, $this->dimensionSubjectIds(Composition::class, $dimensionId), true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$title = $this->compositionTitle($composition);
|
||||
|
||||
if ($query !== '' && ! str_contains(mb_strtolower($title.' '.(string) ($composition->summary ?? '')), mb_strtolower($query))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$row = $this->rowForTarget('composition-draft:'.$composition->id, $exceptCompositionId);
|
||||
|
||||
if ($row !== null) {
|
||||
$rows[] = $row;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
@if ($url = $this->previewUrl())
|
||||
<a class="luf-link" href="{{ $url }}" target="_blank" rel="noopener">Vorschau für Trainer</a>
|
||||
@endif
|
||||
<button type="button" class="luf-quiet" wire:click="armRelease">Freigeben</button>
|
||||
<button type="button" class="luf-quiet" wire:click="armRelease">Fassung freigeben</button>
|
||||
<button type="button" class="luf-quiet" wire:click="discardDraft">Entwurf verwerfen</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -24,12 +24,70 @@
|
||||
<p class="luf-feedback" role="status">{{ $this->feedback }}</p>
|
||||
@endif
|
||||
@if ($this->releaseArmed)
|
||||
<div class="luf-confirm" role="alertdialog" aria-labelledby="freigabe-titel">
|
||||
<h2 id="freigabe-titel">Diesen Aufbau freigeben</h2>
|
||||
<p>Freigeben übernimmt den aktuellen Aufbau als neue unveränderliche Fassung. Eine frühere Fassung bleibt erhalten und wird nicht überschrieben. Der Entwurf wird danach geschlossen.</p>
|
||||
<div class="luf-actions">
|
||||
<button type="button" class="luf-primary" wire:click="publishRevision">Jetzt freigeben</button>
|
||||
<button type="button" class="luf-quiet" wire:click="cancelRelease">Abbrechen</button>
|
||||
@php($review = $this->releaseReview())
|
||||
<div class="luf-modal" role="dialog" aria-modal="true" aria-labelledby="freigabe-titel">
|
||||
<div class="luf-modal-card luf-modal-narrow">
|
||||
<div class="luf-pane-head">
|
||||
<h2 id="freigabe-titel">Fassung freigeben</h2>
|
||||
<button type="button" class="luf-quiet" wire:click="cancelRelease">Abbrechen</button>
|
||||
</div>
|
||||
<p>Freigegeben wird {{ $review['next_label'] }} von {{ $review['host_label'] }} „{{ $review['title'] }}“. Eine frühere Fassung bleibt unverändert. Der Entwurf wird danach geschlossen.</p>
|
||||
<p class="luf-note">Das zeigt die Fassung nicht in der Mitgliederbibliothek, nicht auf der Website und nicht als Angebot.</p>
|
||||
<h3>Bereits freigegeben</h3>
|
||||
@if ($review['ready'] === [])
|
||||
<p class="luf-empty">Keine Bestandteile sind schon freigegeben.</p>
|
||||
@else
|
||||
<ul class="luf-list">
|
||||
@foreach ($review['ready'] as $item)
|
||||
<li style="padding-left: {{ $item['depth'] }}rem;">
|
||||
<strong>{{ $item['title'] }}</strong>
|
||||
<span class="luf-meta">{{ $item['detail'] }}</span>
|
||||
</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
@endif
|
||||
<h3>Noch nicht freigegeben</h3>
|
||||
@if ($review['pending'] === [])
|
||||
<p class="luf-empty">Keine Bestandteile warten auf eine Freigabe.</p>
|
||||
@else
|
||||
<ul class="luf-list">
|
||||
@foreach ($review['pending'] as $item)
|
||||
<li style="padding-left: {{ $item['depth'] }}rem;">
|
||||
<strong>{{ $item['title'] }}</strong>
|
||||
<span class="luf-meta">{{ $item['detail'] }}</span>
|
||||
</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
@if ($review['nested_draft'])
|
||||
<p class="luf-note">Für ein untergeordnetes Modul gilt der gespeicherte Entwurf.</p>
|
||||
@endif
|
||||
<div class="luf-field">
|
||||
<label>
|
||||
<input type="checkbox" wire:model.live="releaseConsent">
|
||||
Diese Bestandteile gebe ich mit frei. Bereits freigegebene Fassungen bleiben unverändert.
|
||||
</label>
|
||||
</div>
|
||||
@endif
|
||||
<h3>Das verhindert die Freigabe</h3>
|
||||
@if ($review['blocked'] === [])
|
||||
<p class="luf-empty">Nichts steht der Freigabe entgegen.</p>
|
||||
@else
|
||||
<ul class="luf-list">
|
||||
@foreach ($review['blocked'] as $item)
|
||||
<li style="padding-left: {{ $item['depth'] }}rem;">
|
||||
<strong>{{ $item['title'] }}</strong>
|
||||
<span class="luf-meta">{{ $item['detail'] }}</span>
|
||||
@if (! empty($item['edit_url']))
|
||||
<a class="luf-link" href="{{ $item['edit_url'] }}">Bearbeiten</a>
|
||||
@endif
|
||||
</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
@endif
|
||||
<div class="luf-actions">
|
||||
<button type="button" class="luf-primary" wire:click="publishRevision" @disabled($review['blocked'] !== [] || ($review['needs_consent'] && ! $this->releaseConsent))>Jetzt freigeben</button>
|
||||
<button type="button" class="luf-quiet" wire:click="cancelRelease">Abbrechen</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
@@ -182,6 +240,10 @@
|
||||
</ul>
|
||||
@endif
|
||||
|
||||
@if ($follow = $this->releaseFollowUp())
|
||||
<p class="luf-note">{{ $follow }}</p>
|
||||
@endif
|
||||
|
||||
@if ($this->usageLines() !== [])
|
||||
<h3>Verwendung der letzten freigegebenen Fassung</h3>
|
||||
<ul>
|
||||
|
||||
@@ -95,9 +95,12 @@
|
||||
@php
|
||||
$status = match ($version->status) {
|
||||
ContentVersionStatus::Gesperrt => 'deaktiviert',
|
||||
ContentVersionStatus::Entwurf => 'Entwurf',
|
||||
default => 'bereit',
|
||||
ContentVersionStatus::Entwurf => 'Entwurf, noch nicht freigegeben',
|
||||
default => 'freigegeben',
|
||||
};
|
||||
$releaseProblem = $version->status === ContentVersionStatus::Entwurf
|
||||
? app(\App\Domain\Catalog\ContentService::class)->elementReleaseProblem($version)
|
||||
: null;
|
||||
@endphp
|
||||
<li style="display: grid; gap: 0.35rem; padding: 0.75rem 0; border-top: 1px solid rgba(0,0,0,0.12);">
|
||||
<strong>Fassung {{ $version->number }}</strong>
|
||||
@@ -108,6 +111,12 @@
|
||||
<span style="display: flex; flex-wrap: wrap; gap: 0.75rem;">
|
||||
<button type="button" wire:click="showVersion({{ $version->id }})">Fassung {{ $version->number }} ansehen</button>
|
||||
<a href="{{ route('content.preview', $version) }}" target="_blank" rel="noopener">Im eigenen Tab</a>
|
||||
@if ($canRevise && $version->status === ContentVersionStatus::Entwurf)
|
||||
@if ($releaseProblem)
|
||||
<span>{{ $releaseProblem }}</span>
|
||||
@endif
|
||||
<button type="button" wire:click="mountAction('releaseVersion', { version: {{ $version->id }} })">Fassung freigeben</button>
|
||||
@endif
|
||||
@if ($canRevise && $version->status === ContentVersionStatus::Bereit)
|
||||
<button type="button" wire:click="mountAction('deactivate', { version: {{ $version->id }} })">Deaktivieren</button>
|
||||
@endif
|
||||
|
||||
@@ -77,6 +77,7 @@ public function test_display_data_does_not_create_a_version_and_a_module_works_w
|
||||
->set('newTextTitle', 'Hinweis ohne Film')
|
||||
->set('newTextBody', 'Zuerst den Abstand ansprechen.')
|
||||
->call('addText')
|
||||
->set('releaseConsent', true)
|
||||
->call('publishRevision');
|
||||
|
||||
$module->refresh();
|
||||
@@ -130,7 +131,7 @@ public function test_reordering_reuses_a_medium_and_keeps_the_released_version()
|
||||
$members = $component->get('members');
|
||||
$component->set('members', array_reverse($members))
|
||||
->call('publishRevision')
|
||||
->assertSet('feedback', 'Die neue Fassung ist übernommen. Die bisherige Fassung bleibt erhalten.');
|
||||
->assertSet('feedback', 'Fassung 2 ist freigegeben. Der Entwurf ist geschlossen und die bisherige Fassung bleibt erhalten. Die Mitgliederbibliothek ändert sich dadurch nicht.');
|
||||
|
||||
$versions = $programVersion->composition->versions()->with('members')->orderBy('number')->get();
|
||||
|
||||
@@ -190,6 +191,10 @@ public function test_a_new_module_returns_into_the_program(): void
|
||||
->set('newTextBody', 'Nur für die Bedienprüfung.')
|
||||
->call('addText')
|
||||
->call('returnAndInclude')
|
||||
->assertSet('releaseArmed', true)
|
||||
->assertSee('Noch nicht freigegeben')
|
||||
->set('releaseConsent', true)
|
||||
->call('publishRevision')
|
||||
->assertRedirect();
|
||||
|
||||
$version = $module->versions()->firstOrFail();
|
||||
@@ -225,7 +230,7 @@ public function test_a_role_change_stays_on_the_selected_part_when_the_order_cha
|
||||
->assertSet('members.1.role', 'Film zum Einstieg')
|
||||
->call('movePart', 1, -1)
|
||||
->call('publishRevision')
|
||||
->assertSet('feedback', 'Die neue Fassung ist übernommen. Die bisherige Fassung bleibt erhalten.');
|
||||
->assertSet('feedback', 'Fassung 2 ist freigegeben. Der Entwurf ist geschlossen und die bisherige Fassung bleibt erhalten. Die Mitgliederbibliothek ändert sich dadurch nicht.');
|
||||
|
||||
$versions = $program->composition->versions()->with('members')->orderBy('number')->get();
|
||||
|
||||
@@ -259,8 +264,9 @@ public function test_saving_a_draft_ten_times_creates_one_version_only_when_rele
|
||||
Livewire::actingAs($editor, 'staff')
|
||||
->test(EditExercise::class, ['record' => $module->id])
|
||||
->assertSet('learningGoal', 'Durchgang 10')
|
||||
->set('releaseConsent', true)
|
||||
->call('publishRevision')
|
||||
->assertSet('feedback', 'Die neue Fassung ist übernommen. Die bisherige Fassung bleibt erhalten.');
|
||||
->assertSet('feedback', 'Fassung 1 ist freigegeben. Der Entwurf ist geschlossen und die bisherige Fassung bleibt erhalten. Die Mitgliederbibliothek ändert sich dadurch nicht.');
|
||||
|
||||
$module->refresh();
|
||||
$this->assertSame(1, $module->versions()->count());
|
||||
@@ -620,7 +626,7 @@ public function test_a_module_text_stays_editable_until_it_is_released_and_used(
|
||||
->assertSee('Hinweis')
|
||||
->assertSee('Entwurf');
|
||||
|
||||
$component->call('publishRevision');
|
||||
$component->set('releaseConsent', true)->call('publishRevision');
|
||||
$this->assertSame(ContentVersionStatus::Bereit, $version->fresh()->status);
|
||||
$this->assertSame($version->id, $module->fresh()->versions()->first()->members()->first()->content_element_version_id);
|
||||
|
||||
@@ -695,11 +701,115 @@ public function test_a_file_can_be_created_inside_the_module(): void
|
||||
$this->assertSame('Überarbeitet', $element->fresh()->description);
|
||||
$this->assertSame(1, $element->versions()->count());
|
||||
|
||||
$component->call('publishRevision');
|
||||
$component->set('releaseConsent', true)->call('publishRevision');
|
||||
$this->assertSame(ContentVersionStatus::Bereit, $version->fresh()->status);
|
||||
$this->assertSame($version->id, $module->fresh()->versions()->first()->members()->first()->content_element_version_id);
|
||||
}
|
||||
|
||||
public function test_release_reviews_the_structure_and_keeps_other_references(): void
|
||||
{
|
||||
$content = app(ContentService::class);
|
||||
$film = $content->publishElementVersion($content->createElement('film', 'film', 'Lara im Park'), 'Film');
|
||||
$guide = $content->draftElementVersion($content->createElement('text', 'text', 'Traineranleitung'), 'Zuerst vorlesen.');
|
||||
$soonBlocked = $content->publishElementVersion($content->createElement('text', 'text', 'Alter Hinweis'), 'Alt');
|
||||
$other = $content->publishComposition(
|
||||
$content->createComposition('Anderes Modul', CompositionKind::Uebung),
|
||||
[['role' => 'Film', 'target' => $film]],
|
||||
);
|
||||
$editor = $this->editor();
|
||||
$module = $content->createComposition('Freigabe Modul', CompositionKind::Uebung);
|
||||
|
||||
$readyOnly = Livewire::actingAs($editor, 'staff')
|
||||
->test(EditExercise::class, ['record' => $module->id])
|
||||
->call('addPart', 'element:'.$film->id)
|
||||
->call('armRelease')
|
||||
->assertSee('Bereits freigegeben')
|
||||
->assertSee('Lara im Park')
|
||||
->assertSee('bleibt unverändert')
|
||||
->assertSee('Keine Bestandteile warten')
|
||||
->call('cancelRelease')
|
||||
->assertSet('releaseArmed', false);
|
||||
|
||||
$this->assertSame(0, $module->fresh()->versions()->count());
|
||||
|
||||
$readyOnly
|
||||
->call('armRelease')
|
||||
->call('publishRevision')
|
||||
->assertSee('Fassung 1 ist freigegeben')
|
||||
->assertSee('keinen offenen Entwurf')
|
||||
->assertSee('In Mitgliederbibliothek anzeigen');
|
||||
|
||||
$this->assertSame($film->id, $module->fresh()->versions()->first()->members()->first()->content_element_version_id);
|
||||
$this->assertSame($film->id, $other->fresh()->members()->first()->content_element_version_id);
|
||||
$this->assertSame(1, $film->element->fresh()->versions()->count());
|
||||
|
||||
$withGuide = $content->createComposition('Mit Anleitung', CompositionKind::Uebung);
|
||||
$guideEditor = Livewire::actingAs($editor, 'staff')
|
||||
->test(EditExercise::class, ['record' => $withGuide->id])
|
||||
->call('addPart', 'element:'.$guide->id)
|
||||
->call('armRelease')
|
||||
->assertSee('Traineranleitung')
|
||||
->assertSee('Der Entwurf wird freigegeben')
|
||||
->call('publishRevision')
|
||||
->assertSee('ausdrücklicher Zustimmung');
|
||||
|
||||
$this->assertSame(ContentVersionStatus::Entwurf, $guide->fresh()->status);
|
||||
$this->assertSame(0, $withGuide->fresh()->versions()->count());
|
||||
|
||||
$guideEditor
|
||||
->set('releaseConsent', true)
|
||||
->call('publishRevision')
|
||||
->assertSee('Fassung 1 ist freigegeben');
|
||||
|
||||
$this->assertSame(ContentVersionStatus::Bereit, $guide->fresh()->status);
|
||||
$this->assertSame($guide->id, $withGuide->fresh()->versions()->first()->members()->first()->content_element_version_id);
|
||||
|
||||
$child = $content->createComposition('Untermodul', CompositionKind::Uebung);
|
||||
$child->working_draft = [
|
||||
'learning_goal' => 'Grenze erkennen',
|
||||
'duration_minutes' => 8,
|
||||
'material_note' => null,
|
||||
'revision_note' => null,
|
||||
'members' => [['role' => 'Film', 'target' => 'element:'.$film->id, 'note' => '']],
|
||||
];
|
||||
$child->save();
|
||||
$program = $content->createComposition('Freigabe Programm', CompositionKind::Kurs);
|
||||
|
||||
Livewire::actingAs($editor, 'staff')
|
||||
->test(EditCourse::class, ['record' => $program->id])
|
||||
->call('openPicker')
|
||||
->assertSee('Untermodul')
|
||||
->call('addPart', 'composition-draft:'.$child->id)
|
||||
->call('armRelease')
|
||||
->assertSee('Es entsteht Fassung 1')
|
||||
->set('releaseConsent', true)
|
||||
->call('publishRevision')
|
||||
->assertSee('Fassung 1 ist freigegeben');
|
||||
|
||||
$childVersion = $child->fresh()->versions()->first();
|
||||
$this->assertSame(ContentVersionStatus::Bereit, $childVersion->status);
|
||||
$this->assertSame($film->id, $childVersion->members()->first()->content_element_version_id);
|
||||
$this->assertSame($childVersion->id, $program->fresh()->versions()->first()->members()->first()->nested_composition_version_id);
|
||||
$this->assertSame(1, $other->composition->fresh()->versions()->count());
|
||||
$this->assertSame($film->id, $other->fresh()->members()->first()->content_element_version_id);
|
||||
|
||||
$broken = $content->createComposition('Mit Fehler', CompositionKind::Uebung);
|
||||
$brokenEditor = Livewire::actingAs($editor, 'staff')
|
||||
->test(EditExercise::class, ['record' => $broken->id])
|
||||
->call('addPart', 'element:'.$soonBlocked->id);
|
||||
$content->block($soonBlocked, 'Nicht mehr verwenden');
|
||||
$brokenEditor
|
||||
->call('armRelease')
|
||||
->assertSee('deaktiviert')
|
||||
->assertSee('content-elements/'.$soonBlocked->content_element_id)
|
||||
->call('publishRevision')
|
||||
->assertSet('releaseArmed', true);
|
||||
|
||||
$this->assertSame(0, $broken->fresh()->versions()->count());
|
||||
$this->assertSame(ContentVersionStatus::Gesperrt, $soonBlocked->fresh()->status);
|
||||
$this->assertSame(1, $other->composition->fresh()->versions()->count());
|
||||
}
|
||||
|
||||
private function filmWithPicture(ContentService $content, string $title): ContentElementVersion
|
||||
{
|
||||
$element = $content->createElement('film', 'film', $title);
|
||||
|
||||
@@ -136,7 +136,7 @@ public function test_an_exercise_can_gain_and_drop_a_medium_without_losing_the_o
|
||||
]])
|
||||
->set('revisionNote', 'Film statt Merkblatt')
|
||||
->call('publishRevision')
|
||||
->assertSet('feedback', 'Die neue Fassung ist übernommen. Die bisherige Fassung bleibt erhalten.');
|
||||
->assertSet('feedback', 'Fassung 2 ist freigegeben. Der Entwurf ist geschlossen und die bisherige Fassung bleibt erhalten. Die Mitgliederbibliothek ändert sich dadurch nicht.');
|
||||
|
||||
$versions = $exercise->composition->versions()->with('members')->orderBy('number')->get();
|
||||
|
||||
@@ -148,7 +148,7 @@ public function test_an_exercise_can_gain_and_drop_a_medium_without_losing_the_o
|
||||
Livewire::test(EditExercise::class, ['record' => $exercise->composition_id])
|
||||
->set('learningGoal', 'Den Abstand üben')
|
||||
->call('publishRevision')
|
||||
->assertSet('feedback', 'Die neue Fassung ist übernommen. Die bisherige Fassung bleibt erhalten.');
|
||||
->assertSet('feedback', 'Fassung 3 ist freigegeben. Der Entwurf ist geschlossen und die bisherige Fassung bleibt erhalten. Die Mitgliederbibliothek ändert sich dadurch nicht.');
|
||||
|
||||
$this->assertSame('Den Abstand üben', $exercise->composition->versions()->orderByDesc('number')->first()->learning_goal);
|
||||
$this->assertSame(3, $exercise->composition->versions()->count());
|
||||
@@ -470,4 +470,23 @@ public function test_staff_players_use_the_stored_film_ladder(): void
|
||||
->set('pickerSelected', 'element:'.$version->id)
|
||||
->assertSee('data-hls="'.$playlist.'"', false);
|
||||
}
|
||||
|
||||
public function test_a_draft_medium_can_be_released_from_its_editor(): void
|
||||
{
|
||||
$editor = User::factory()->redakteur()->create();
|
||||
$editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
|
||||
$version = app(ContentService::class)->draftElementVersion(
|
||||
app(ContentService::class)->createElement('text', 'text', 'Eigener Text'),
|
||||
'Wortlaut',
|
||||
);
|
||||
|
||||
Livewire::actingAs($editor, 'staff')
|
||||
->test(ViewContentElement::class, ['record' => $version->content_element_id])
|
||||
->assertSee('noch nicht freigegeben')
|
||||
->mountAction('releaseVersion', ['version' => $version->id])
|
||||
->callMountedAction();
|
||||
|
||||
$this->assertSame(ContentVersionStatus::Bereit, $version->fresh()->status);
|
||||
$this->assertSame(1, $version->element->fresh()->versions()->count());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user