Halte Auswirkung und Rückzug beim Veröffentlichen eines Artikel-Stands fest.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
fd6860efda
commit
fef0ea2ac2
11 files changed
+298
-25
No files matched your search
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Domain\Catalog;
|
||||
|
||||
use App\Domain\Entitlement\Acquisition;
|
||||
use App\Domain\Entitlement\GrantStatus;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ArticleService
|
||||
@@ -34,22 +36,17 @@ public function publishRelease(
|
||||
throw new DomainRuleException('Ein neuer Stand braucht eine Einordnung, warum er zum selben Artikel gehört.');
|
||||
}
|
||||
|
||||
if ($root->status !== ContentVersionStatus::Bereit) {
|
||||
throw new DomainRuleException('Ein Artikel-Stand kann nur eine bereitgestellte Fassung festschreiben.');
|
||||
}
|
||||
$this->checkedRows($root);
|
||||
|
||||
$rows = $this->resolver->expand($root);
|
||||
|
||||
if ($rows === []) {
|
||||
throw new DomainRuleException('Ein Artikel-Stand braucht mindestens eine Inhaltsfassung.');
|
||||
}
|
||||
|
||||
return DB::transaction(function () use ($article, $root, $classification, $changeNote, $rows): ArticleRelease {
|
||||
return DB::transaction(function () use ($article, $root, $classification, $changeNote): ArticleRelease {
|
||||
$rows = $this->checkedRows($root);
|
||||
$impact = $this->impact($article, count($rows));
|
||||
$release = $article->releases()->create([
|
||||
'number' => ((int) $article->releases()->max('number')) + 1,
|
||||
'classification_note' => $classification,
|
||||
'status' => ReleaseStatus::Entwurf,
|
||||
'change_note' => $changeNote,
|
||||
'impact_report' => $impact,
|
||||
'root_element_version_id' => $root instanceof ContentElementVersion ? $root->id : null,
|
||||
'root_composition_version_id' => $root instanceof CompositionVersion ? $root->id : null,
|
||||
]);
|
||||
@@ -80,4 +77,115 @@ public function publishRelease(
|
||||
return $release->load('contents');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{fallback_number: int|null, holders: list<string>}
|
||||
*/
|
||||
public function withdraw(LicenseArticle $article, string $reason): array
|
||||
{
|
||||
$reason = trim($reason);
|
||||
|
||||
if ($reason === '') {
|
||||
throw new DomainRuleException('Ein Rückzug braucht eine Begründung.');
|
||||
}
|
||||
|
||||
return DB::transaction(function () use ($article, $reason): array {
|
||||
$article->refresh();
|
||||
$current = $article->currentRelease;
|
||||
|
||||
if ($current === null || $current->status !== ReleaseStatus::Veroeffentlicht) {
|
||||
throw new DomainRuleException('Zurückziehen lässt sich nur der aktuell veröffentlichte Stand.');
|
||||
}
|
||||
|
||||
$fallback = ArticleRelease::query()
|
||||
->where('license_article_id', $article->id)
|
||||
->where('status', ReleaseStatus::AbgeloestVerfuegbar)
|
||||
->orderByDesc('number')
|
||||
->first();
|
||||
|
||||
$current->status = ReleaseStatus::Gesperrt;
|
||||
$current->block_reason = $reason;
|
||||
$current->fallback_release_id = $fallback?->id;
|
||||
$current->save();
|
||||
|
||||
if ($fallback instanceof ArticleRelease) {
|
||||
$fallback->status = ReleaseStatus::Veroeffentlicht;
|
||||
$fallback->save();
|
||||
$article->current_release_id = $fallback->id;
|
||||
} else {
|
||||
$article->current_release_id = null;
|
||||
}
|
||||
|
||||
$article->save();
|
||||
|
||||
return [
|
||||
'fallback_number' => $fallback?->number,
|
||||
'holders' => Acquisition::query()
|
||||
->whereHas('grants', fn ($query) => $query
|
||||
->where('license_article_id', $article->id)
|
||||
->where('status', GrantStatus::Aktiv))
|
||||
->with('party')
|
||||
->get()
|
||||
->map(fn (Acquisition $acquisition): string => $acquisition->party->display_name)
|
||||
->unique()
|
||||
->values()
|
||||
->all(),
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<array{version_id: int, role: string, path: string}>
|
||||
*/
|
||||
private function checkedRows(ContentElementVersion|CompositionVersion $root): array
|
||||
{
|
||||
$root->refresh();
|
||||
|
||||
if ($root->status !== ContentVersionStatus::Bereit) {
|
||||
throw new DomainRuleException('Ein Artikel-Stand kann nur eine bereitgestellte Fassung festschreiben.');
|
||||
}
|
||||
|
||||
$rows = $this->resolver->expand($root);
|
||||
|
||||
if ($rows === []) {
|
||||
throw new DomainRuleException('Ein Artikel-Stand braucht mindestens eine Inhaltsfassung.');
|
||||
}
|
||||
|
||||
$blocked = ContentElementVersion::query()
|
||||
->whereIn('id', array_column($rows, 'version_id'))
|
||||
->where('status', '!=', ContentVersionStatus::Bereit->value)
|
||||
->exists();
|
||||
|
||||
if ($blocked) {
|
||||
throw new DomainRuleException('Eine gesperrte Inhaltsfassung kann nicht veröffentlicht werden.');
|
||||
}
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{holders: int, offers: list<string>, contents: int, replaces_number: int|null}
|
||||
*/
|
||||
private function impact(LicenseArticle $article, int $contents): array
|
||||
{
|
||||
$article->loadMissing('currentRelease');
|
||||
|
||||
return [
|
||||
'holders' => Acquisition::query()
|
||||
->whereHas('grants', fn ($query) => $query
|
||||
->where('license_article_id', $article->id)
|
||||
->where('status', GrantStatus::Aktiv))
|
||||
->distinct()
|
||||
->count('party_id'),
|
||||
'offers' => Offer::query()
|
||||
->whereHas('versions', fn ($query) => $query
|
||||
->where('status', OfferStatus::Aktiv)
|
||||
->whereHas('resolvedScopes', fn ($scope) => $scope->where('license_article_id', $article->id)))
|
||||
->orderBy('name')
|
||||
->pluck('name')
|
||||
->all(),
|
||||
'contents' => $contents,
|
||||
'replaces_number' => $article->currentRelease?->number,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user