Optimierung 2.9: HandlesAdminPressReleaseActions::findAdminPR()
Den ~15x duplizierten Admin-Lookup PressRelease::withoutGlobalScopes() ->findOrFail($id) in einen findAdminPR()-Helfer (Concern) zentralisiert; index/edit/show nutzen ihn. Die eager-load-Query in show::with() bleibt unberuehrt (anderer Zweck). Bewusst NICHT vereinheitlicht: das Status-Badge-Mapping divergiert real (index: archived/draft -> muted; edit/show: -> hub via default) -> waere eine Design-Entscheidung ueber kanonische Badge-Farben, keine mechanische Dedup. Tests: volle Suite gruen (799 passed, 1 skipped). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
28e9064410
commit
af86a16061
4 changed files with 38 additions and 15 deletions
|
|
@ -23,6 +23,7 @@ use Livewire\Attributes\Title;
|
|||
use Livewire\Volt\Component;
|
||||
|
||||
new #[Layout('components.layouts.app'), Title('Pressemitteilung bearbeiten')] class extends Component {
|
||||
use \App\Livewire\Concerns\HandlesAdminPressReleaseActions;
|
||||
use \App\Livewire\Concerns\InteractsWithPressReleaseContacts;
|
||||
use \App\Livewire\Concerns\InteractsWithPressReleaseScheduling;
|
||||
use \App\Livewire\Concerns\InteractsWithPressReleaseTags;
|
||||
|
|
@ -90,7 +91,7 @@ new #[Layout('components.layouts.app'), Title('Pressemitteilung bearbeiten')] cl
|
|||
{
|
||||
$this->id = $id;
|
||||
|
||||
$pr = PressRelease::withoutGlobalScopes()->findOrFail($id);
|
||||
$pr = $this->findAdminPR($id);
|
||||
|
||||
$this->portal = $pr->portal->value;
|
||||
$this->language = $pr->language;
|
||||
|
|
@ -166,7 +167,7 @@ new #[Layout('components.layouts.app'), Title('Pressemitteilung bearbeiten')] cl
|
|||
throw $e;
|
||||
}
|
||||
|
||||
$pr = PressRelease::withoutGlobalScopes()->findOrFail($this->id);
|
||||
$pr = $this->findAdminPR($this->id);
|
||||
|
||||
if ($pr->title !== $this->title || $pr->portal !== $this->portal || $pr->language !== $this->language) {
|
||||
$slug = $pr->generateUniqueSlug($this->title, [
|
||||
|
|
@ -216,7 +217,7 @@ new #[Layout('components.layouts.app'), Title('Pressemitteilung bearbeiten')] cl
|
|||
|
||||
public function submitForReview(): void
|
||||
{
|
||||
$pr = PressRelease::withoutGlobalScopes()->findOrFail($this->id);
|
||||
$pr = $this->findAdminPR($this->id);
|
||||
|
||||
try {
|
||||
app(PressReleaseService::class)->submitForReview($pr);
|
||||
|
|
@ -269,7 +270,7 @@ new #[Layout('components.layouts.app'), Title('Pressemitteilung bearbeiten')] cl
|
|||
|
||||
public function publish(): void
|
||||
{
|
||||
$pr = PressRelease::withoutGlobalScopes()->findOrFail($this->id);
|
||||
$pr = $this->findAdminPR($this->id);
|
||||
|
||||
try {
|
||||
app(PressReleaseService::class)->publish($pr);
|
||||
|
|
@ -286,7 +287,7 @@ new #[Layout('components.layouts.app'), Title('Pressemitteilung bearbeiten')] cl
|
|||
|
||||
public function reject(): void
|
||||
{
|
||||
$pr = PressRelease::withoutGlobalScopes()->findOrFail($this->id);
|
||||
$pr = $this->findAdminPR($this->id);
|
||||
app(PressReleaseService::class)->reject($pr);
|
||||
$this->currentStatus = PressReleaseStatus::Rejected->value;
|
||||
Flux::toast(text: __('Pressemitteilung abgelehnt. Autor wurde benachrichtigt.'), variant: 'warning');
|
||||
|
|
@ -294,7 +295,7 @@ new #[Layout('components.layouts.app'), Title('Pressemitteilung bearbeiten')] cl
|
|||
|
||||
public function backToDraft(): void
|
||||
{
|
||||
$pr = PressRelease::withoutGlobalScopes()->findOrFail($this->id);
|
||||
$pr = $this->findAdminPR($this->id);
|
||||
app(PressReleaseService::class)->backToDraft($pr);
|
||||
$this->currentStatus = PressReleaseStatus::Draft->value;
|
||||
Flux::toast(text: __('Zurück auf Entwurf gesetzt.'), variant: 'success');
|
||||
|
|
@ -302,7 +303,7 @@ new #[Layout('components.layouts.app'), Title('Pressemitteilung bearbeiten')] cl
|
|||
|
||||
public function archive(): void
|
||||
{
|
||||
$pr = PressRelease::withoutGlobalScopes()->findOrFail($this->id);
|
||||
$pr = $this->findAdminPR($this->id);
|
||||
app(PressReleaseService::class)->archive($pr);
|
||||
$this->currentStatus = PressReleaseStatus::Archived->value;
|
||||
$this->targetStatus = $this->currentStatus;
|
||||
|
|
@ -322,7 +323,7 @@ new #[Layout('components.layouts.app'), Title('Pressemitteilung bearbeiten')] cl
|
|||
}
|
||||
|
||||
$status = PressReleaseStatus::from($this->targetStatus);
|
||||
$pr = PressRelease::withoutGlobalScopes()->findOrFail($this->id);
|
||||
$pr = $this->findAdminPR($this->id);
|
||||
|
||||
app(PressReleaseService::class)->changeStatusFromAdmin($pr, $status);
|
||||
|
||||
|
|
@ -335,7 +336,7 @@ new #[Layout('components.layouts.app'), Title('Pressemitteilung bearbeiten')] cl
|
|||
|
||||
public function deletePressRelease(): void
|
||||
{
|
||||
$pr = PressRelease::withoutGlobalScopes()->findOrFail($this->id);
|
||||
$pr = $this->findAdminPR($this->id);
|
||||
$wasPublished = $pr->status === PressReleaseStatus::Published;
|
||||
|
||||
app(PressReleaseService::class)->deleteFromAdmin($pr);
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ use Livewire\WithPagination;
|
|||
|
||||
new #[Layout('components.layouts.app'), Title('Pressemitteilungen')] class extends Component
|
||||
{
|
||||
use \App\Livewire\Concerns\HandlesAdminPressReleaseActions;
|
||||
use WithPagination;
|
||||
|
||||
public string $search = '';
|
||||
|
|
@ -162,7 +163,7 @@ new #[Layout('components.layouts.app'), Title('Pressemitteilungen')] class exten
|
|||
|
||||
public function publish(int $id): void
|
||||
{
|
||||
$pr = PressRelease::withoutGlobalScopes()->findOrFail($id);
|
||||
$pr = $this->findAdminPR($id);
|
||||
|
||||
try {
|
||||
app(PressReleaseService::class)->publish($pr);
|
||||
|
|
@ -186,7 +187,7 @@ new #[Layout('components.layouts.app'), Title('Pressemitteilungen')] class exten
|
|||
|
||||
public function reject(int $id): void
|
||||
{
|
||||
$pr = PressRelease::withoutGlobalScopes()->findOrFail($id);
|
||||
$pr = $this->findAdminPR($id);
|
||||
|
||||
try {
|
||||
app(PressReleaseService::class)->reject($pr, __('Bitte überarbeiten Sie die Pressemitteilung.'));
|
||||
|
|
@ -201,7 +202,7 @@ new #[Layout('components.layouts.app'), Title('Pressemitteilungen')] class exten
|
|||
|
||||
public function archive(int $id): void
|
||||
{
|
||||
$pr = PressRelease::withoutGlobalScopes()->findOrFail($id);
|
||||
$pr = $this->findAdminPR($id);
|
||||
|
||||
try {
|
||||
app(PressReleaseService::class)->archive($pr);
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ use Livewire\Volt\Component;
|
|||
|
||||
new #[Layout('components.layouts.app'), Title('Pressemitteilung')] class extends Component
|
||||
{
|
||||
use \App\Livewire\Concerns\HandlesAdminPressReleaseActions;
|
||||
|
||||
#[Locked]
|
||||
public int $id;
|
||||
|
||||
|
|
@ -24,7 +26,7 @@ new #[Layout('components.layouts.app'), Title('Pressemitteilung')] class extends
|
|||
|
||||
public function publish(): void
|
||||
{
|
||||
$pr = PressRelease::withoutGlobalScopes()->findOrFail($this->id);
|
||||
$pr = $this->findAdminPR($this->id);
|
||||
|
||||
try {
|
||||
app(PressReleaseService::class)->publish($pr);
|
||||
|
|
@ -50,7 +52,7 @@ new #[Layout('components.layouts.app'), Title('Pressemitteilung')] class extends
|
|||
'rejectReason' => ['required', 'string', 'min:5', 'max:2000'],
|
||||
]);
|
||||
|
||||
$pr = PressRelease::withoutGlobalScopes()->findOrFail($this->id);
|
||||
$pr = $this->findAdminPR($this->id);
|
||||
app(PressReleaseService::class)->reject($pr, trim($this->rejectReason));
|
||||
|
||||
$this->rejectReason = '';
|
||||
|
|
@ -61,7 +63,7 @@ new #[Layout('components.layouts.app'), Title('Pressemitteilung')] class extends
|
|||
|
||||
public function archive(): void
|
||||
{
|
||||
$pr = PressRelease::withoutGlobalScopes()->findOrFail($this->id);
|
||||
$pr = $this->findAdminPR($this->id);
|
||||
app(PressReleaseService::class)->archive($pr);
|
||||
Flux::toast(text: __('Archiviert.'), variant: 'success');
|
||||
Flux::modal('confirm-show-archive')->close();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue