CI Feature / test (push) Successful in 2m25s
Die Übungsliste verweist mit „Aus Shinkan übernehmen“ auf die Übernahmeseite. Die Seite zeigt Adresse (nur Host) und Schlüssel (nur ob hinterlegt) und prüft die Verbindung, ohne etwas zu übernehmen. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
131 lines
4.9 KiB
PHP
131 lines
4.9 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Pages;
|
|
|
|
use App\Domain\Catalog\DomainRuleException;
|
|
use App\Domain\Catalog\ExerciseImportRun;
|
|
use App\Domain\Catalog\ExerciseSource;
|
|
use App\Domain\Catalog\ExerciseSourceSnapshot;
|
|
use App\Domain\Catalog\ShinkanImport;
|
|
use App\Filament\Resources\ContentElements\ContentElementResource;
|
|
use App\Filament\Resources\Practices\PracticeResource;
|
|
use App\Models\User;
|
|
use Filament\Facades\Filament;
|
|
use Filament\Pages\Page;
|
|
use Filament\Support\Enums\Width;
|
|
use Illuminate\Contracts\Support\Htmlable;
|
|
|
|
/**
|
|
* Übernahme aus Shinkan: Welche Übungen stellt die Quelle bereit, was ist neu oder geändert, was ist übernommen und was
|
|
* stellt die Quelle nicht mehr bereit? Abrufen verändert nur den Quellenstand; erst „Übernehmen“ legt eine lokale
|
|
* Fassung an, und erst eine Produktveröffentlichung setzt sie ein.
|
|
*/
|
|
class Uebernahme extends Page
|
|
{
|
|
protected static string|\UnitEnum|null $navigationGroup = 'Inhalte';
|
|
|
|
protected static ?string $navigationLabel = 'Übungen aus Shinkan';
|
|
|
|
protected static ?int $navigationSort = 6;
|
|
|
|
protected static ?string $slug = 'uebernahme';
|
|
|
|
protected static ?string $title = 'Übungen aus Shinkan übernehmen';
|
|
|
|
protected string $view = 'filament.pages.uebernahme';
|
|
|
|
public string $feedback = '';
|
|
|
|
public bool $feedbackError = false;
|
|
|
|
public static function canAccess(): bool
|
|
{
|
|
return ContentElementResource::editor();
|
|
}
|
|
|
|
public function getHeading(): string|Htmlable|null
|
|
{
|
|
return null;
|
|
}
|
|
|
|
public function getMaxContentWidth(): Width|string|null
|
|
{
|
|
return Width::Full;
|
|
}
|
|
|
|
public function fetch(): void
|
|
{
|
|
abort_unless(static::canAccess(), 403);
|
|
|
|
$run = app(ShinkanImport::class)->fetch();
|
|
$this->feedbackError = $run->status !== 'ok';
|
|
$this->feedback = $run->status === 'ok'
|
|
? 'Abruf abgeschlossen: '.$run->added.' neu, '.$run->updated.' geändert, '.$run->removed.' nicht mehr bereitgestellt. Es wurde noch keine lokale Fassung angelegt.'
|
|
: (string) $run->error;
|
|
}
|
|
|
|
public function check(): void
|
|
{
|
|
abort_unless(static::canAccess(), 403);
|
|
|
|
$result = app(ShinkanImport::class)->check();
|
|
$this->feedbackError = ! $result['ok'];
|
|
$this->feedback = $result['message'];
|
|
}
|
|
|
|
public function adopt(int $snapshotId): void
|
|
{
|
|
abort_unless(static::canAccess(), 403);
|
|
|
|
try {
|
|
$user = Filament::auth()->user();
|
|
$version = app(ShinkanImport::class)->adopt(ExerciseSourceSnapshot::query()->findOrFail($snapshotId), $user instanceof User ? $user : null);
|
|
$this->feedbackError = false;
|
|
$this->feedback = 'Fassung '.$version->number.' ist lokal angelegt und unveränderlich. Produkte verwenden sie erst, wenn du sie dort bewusst einsetzt und das Produkt veröffentlichst.';
|
|
} catch (DomainRuleException $exception) {
|
|
$this->feedbackError = true;
|
|
$this->feedback = $exception->getMessage();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function daten(): array
|
|
{
|
|
$import = app(ShinkanImport::class);
|
|
$labels = [
|
|
'neu' => ['Neu bei der Quelle', 'offen'],
|
|
'geaendert' => ['Neue Quellfassung zur Übernahme', 'offen'],
|
|
'uebernommen' => ['Übernommen', 'gut'],
|
|
'nicht_mehr_bereitgestellt' => ['An der Quelle nicht mehr bereitgestellt', 'leise'],
|
|
];
|
|
$rows = [];
|
|
|
|
foreach (ExerciseSource::query()->with('composition')->orderBy('title')->get() as $source) {
|
|
$state = $import->state($source);
|
|
$latest = $source->latestSnapshot();
|
|
$payload = $latest?->payload ?? [];
|
|
$rows[] = [
|
|
'titel' => $source->title ?: $source->source_id,
|
|
'zustand' => $labels[$state][0],
|
|
'ton' => $labels[$state][1],
|
|
'snapshot' => $latest !== null && $latest->adopted_version_id === null ? $latest->id : null,
|
|
'lokal' => $source->composition === null ? null : PracticeResource::getUrl('edit', ['record' => $source->composition]),
|
|
'varianten' => count($payload['variants'] ?? []),
|
|
'quellmedien' => array_map(fn (array $media): string => ($media['title'] ?? '').' ('.($media['media_type'] ?? '').')', (array) ($payload['media'] ?? [])),
|
|
'hinweis' => $state === 'nicht_mehr_bereitgestellt'
|
|
? 'Lokale Fassungen und Verwendungen bleiben unverändert. Eine rechtliche Sperre ist ein eigener Vorgang am Medium.'
|
|
: null,
|
|
];
|
|
}
|
|
|
|
return [
|
|
'zeilen' => $rows,
|
|
'eingerichtet' => app(ShinkanImport::class)->configured(),
|
|
'anbindung' => app(ShinkanImport::class)->status(),
|
|
'letzterLauf' => ExerciseImportRun::query()->orderByDesc('id')->first(),
|
|
];
|
|
}
|
|
}
|