diff --git a/CLAUDE.md b/CLAUDE.md index f6a9d3f..df51dc2 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -63,6 +63,6 @@ ## Entwicklung ## Verwaltungsoberfläche - Maßgeblich sind `docs/ux/verwaltung/14-verwaltungsstandard.md` (Design und Interaktion) und `15-umbauauftrag.md` (Auftrag, Nachweise). Keine neue allgemeine Designabstimmung verlangen. Einstieg für alle Agenten: `AGENTS.md`, `.cursor/rules/verwaltung-ux.mdc`. -- Gemeinsame Bausteine wiederverwenden statt neue Masken bauen: `resources/views/filament/verwaltung/` (`kopf`, `redaktion`, `texte`, `praesentation`, `einordnung`, `picker`, `bestaetigung`, `abgang`, `aufbau`, `bestand`) mit dem Trait `App\Filament\Support\ManagesEditorialSurface`. Listen nutzen `verwaltung/bestand` mit `ShowsBestand` (bzw. `ListsCompositions`, `ListsCatalog`) und den Eintrag ``, den auch der Picker verwendet; Katalogobjekte die Seite `catalog/objekt`. CMS: Seitenkopf `cms/seite-kopf` (Register, Kontexte „Abschnitt gestalten“ und „Konfigurieren“); Seiten und Menüs in der Webpräsenz (`App\Filament\Pages\Webpraesenz`, Menüs als Arbeitsstand mit einer Speicherhandlung). Der Picker liegt im Trait `ChoosesMedia` (Redaktion über `ManagesEditorialSurface`, CMS-Bilder über `ChoosesWebsiteImages`); keine eigenen Auswahllisten für Medien bauen. Redaktionelle Auswahlwerte (Materialart, Einordnung) nur über `App\Domain\Catalog\EditorialVocabulary` anbieten und prüfen (aktiv, zulässiger Kontext, vorhandene Zuordnungen erhalten); gepflegt werden sie unter „Redaktionelle Stammdaten“. Ersetzt eine Seite die Filament-Tabelle, muss sie den Dialogbereich ausgeben (in `bestand` enthalten), sonst öffnen „… anlegen“-Dialoge nicht. Gestaltungswerte nur in `verwaltung/styles.blade.php` (Tokens `--vw-…`, dokumentiert in `docs/ux/verwaltung/tokens.md`). +- Gemeinsame Bausteine wiederverwenden statt neue Masken bauen: `resources/views/filament/verwaltung/` (`kopf`, `redaktion`, `texte`, `praesentation`, `einordnung`, `picker`, `bestaetigung`, `abgang`, `aufbau`, `bestand`) mit dem Trait `App\Filament\Support\ManagesEditorialSurface`. Listen nutzen `verwaltung/bestand` mit `ShowsBestand` (bzw. `ListsCompositions`, `ListsCatalog`) und den Eintrag ``, den auch der Picker verwendet; Katalogobjekte die Seite `catalog/objekt`. CMS: Seitenkopf `cms/seite-kopf` (Register, Kontexte „Abschnitt gestalten“ und „Konfigurieren“); Seiten und Menüs in der Webpräsenz (`App\Filament\Pages\Webpraesenz`, Menüs als Arbeitsstand mit einer Speicherhandlung). Der Picker liegt im Trait `ChoosesMedia` (Redaktion über `ManagesEditorialSurface`, CMS-Bilder über `ChoosesWebsiteImages`); keine eigenen Auswahllisten für Medien bauen. Redaktionelle Auswahlwerte (Materialart, Einordnung) nur über `App\Domain\Catalog\EditorialVocabulary` anbieten und prüfen (aktiv, zulässiger Kontext, vorhandene Zuordnungen erhalten); gepflegt werden sie unter „Redaktionelle Stammdaten“. Fachliche Säulen gibt es nur in der Säulenverwaltung (`pillars`); Zuordnung über `PillarService::assign`, nie über eine Dimension. Ersetzt eine Seite die Filament-Tabelle, muss sie den Dialogbereich ausgeben (in `bestand` enthalten), sonst öffnen „… anlegen“-Dialoge nicht. Gestaltungswerte nur in `verwaltung/styles.blade.php` (Tokens `--vw-…`, dokumentiert in `docs/ux/verwaltung/tokens.md`). - Die Redaktion ist ein Arbeitsstand: nur „Redaktion speichern“ schreibt Texte, Einordnung, Präsentationsmedien und Abweichungen. Kein verdecktes Mitspeichern aus anderen Dialogen, offene Eingaben bleiben beim Wechsel erhalten. - Jede UI-Änderung in der echten Anwendung prüfen (luf-test, breite und schmale Fenster, Tastatur) und mit Screenshots in `docs/ux/verwaltung/abnahme/` belegen. Stand der Abnahme: `abnahme/teil-a.md`, `abnahme/teil-b.md`, `abnahme/teil-c.md`, `abnahme/stammdaten.md`. diff --git a/app/Console/Commands/AdoptLegacyPillars.php b/app/Console/Commands/AdoptLegacyPillars.php new file mode 100644 index 0000000..f55abb7 --- /dev/null +++ b/app/Console/Commands/AdoptLegacyPillars.php @@ -0,0 +1,25 @@ +option('dry-run'); + $report = (new LegacyPillarAdoption)->run($dryRun); + + foreach (LegacyPillarAdoption::lines($report, $dryRun) as $line) { + $this->line($line); + } + + return $report['unresolved'] === [] ? self::SUCCESS : self::FAILURE; + } +} diff --git a/app/Domain/Catalog/Composition.php b/app/Domain/Catalog/Composition.php index f5e881a..0d5068a 100644 --- a/app/Domain/Catalog/Composition.php +++ b/app/Domain/Catalog/Composition.php @@ -4,6 +4,7 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\HasMany; class Composition extends Model @@ -44,4 +45,13 @@ public function versions(): HasMany { return $this->hasMany(CompositionVersion::class); } + + /** + * Direkt zugeordnete fachliche Säulen (zentrale Säulenverwaltung). Die Säulen der enthaltenen Medien sind davon + * getrennt und werden zur Laufzeit abgeleitet (CatalogReading::memberPillars). + */ + public function pillars(): BelongsToMany + { + return $this->belongsToMany(Pillar::class)->orderBy('pillars.sort_order')->orderBy('pillars.name'); + } } diff --git a/app/Domain/Catalog/EditorialDimension.php b/app/Domain/Catalog/EditorialDimension.php index fe177f0..46157c8 100644 --- a/app/Domain/Catalog/EditorialDimension.php +++ b/app/Domain/Catalog/EditorialDimension.php @@ -20,20 +20,15 @@ public function values(): HasMany } /** - * Inhaltselemente pflegen Themen über die Säulen, nicht noch einmal über die Dimension. - * Module, Programme und Lizenzartikel haben keine Säulenauswahl und behalten die Dimension. + * Fachliche Säulen werden für alle Objektarten über die zentrale Säulenverwaltung gewählt (`pillars`), nie über + * eine Dimension. Die alte Dimension „Fachliche Säule“ bleibt nur als Verlauf in der Datenbank und wird nirgends + * mehr angeboten, geändert oder gefiltert. * * @return Collection */ public static function forSubject(Model $subject): Collection { - $query = static::query()->with('values')->orderBy('label'); - - if ($subject instanceof ContentElement) { - $query->where('slug', '!=', self::PILLAR_SLUG); - } - - return $query->get(); + return static::query()->with('values')->where('slug', '!=', self::PILLAR_SLUG)->orderBy('label')->get(); } /** diff --git a/app/Domain/Catalog/EditorialDimensionValue.php b/app/Domain/Catalog/EditorialDimensionValue.php index e646517..008c5f3 100644 --- a/app/Domain/Catalog/EditorialDimensionValue.php +++ b/app/Domain/Catalog/EditorialDimensionValue.php @@ -7,7 +7,7 @@ class EditorialDimensionValue extends Model { - protected $fillable = ['editorial_dimension_id', 'slug', 'label', 'sort_order', 'is_active']; + protected $fillable = ['editorial_dimension_id', 'pillar_id', 'slug', 'label', 'sort_order', 'is_active']; protected function casts(): array { diff --git a/app/Domain/Catalog/EditorialVocabulary.php b/app/Domain/Catalog/EditorialVocabulary.php index efd7dea..9aa6a5b 100644 --- a/app/Domain/Catalog/EditorialVocabulary.php +++ b/app/Domain/Catalog/EditorialVocabulary.php @@ -181,13 +181,13 @@ public function dimensionGroups(Model $subject, array $assignedIds): array * @param list $selectedIds * @return list}> */ - public function dimensionFilterGroups(array $selectedIds = [], bool $withPillars = true): array + public function dimensionFilterGroups(array $selectedIds = []): array { $used = DB::table('identity_dimension_values')->distinct()->pluck('editorial_dimension_value_id')->map(fn ($id): int => (int) $id)->all(); $groups = []; foreach (EditorialDimension::query()->with('values')->orderBy('label')->get() as $dimension) { - if (! $withPillars && $dimension->slug === EditorialDimension::PILLAR_SLUG) { + if ($dimension->slug === EditorialDimension::PILLAR_SLUG) { continue; } @@ -217,7 +217,7 @@ public function dimensionFilterGroups(array $selectedIds = [], bool $withPillars */ public function memberFilterDimensions(array $selectedIds = []): Collection { - $dimensions = EditorialDimension::query()->with('values')->orderBy('label')->get(); + $dimensions = EditorialDimension::query()->with('values')->where('slug', '!=', EditorialDimension::PILLAR_SLUG)->orderBy('label')->get(); foreach ($dimensions as $dimension) { $dimension->setRelation('values', $dimension->values diff --git a/app/Domain/Catalog/LegacyPillarAdoption.php b/app/Domain/Catalog/LegacyPillarAdoption.php new file mode 100644 index 0000000..e232d7f --- /dev/null +++ b/app/Domain/Catalog/LegacyPillarAdoption.php @@ -0,0 +1,270 @@ + */ + private const TARGETS = [ + 'composition' => ['table' => 'composition_pillar', 'column' => 'composition_id', 'subjects' => 'compositions'], + 'license_article' => ['table' => 'license_article_pillar', 'column' => 'license_article_id', 'subjects' => 'license_articles'], + ]; + + /** + * @return array{ + * mapping: list>, + * unresolved: list>, + * copied: array, + * already: array, + * before: array, + * after: array, + * mirror: array + * } + */ + public function run(bool $dryRun = false): array + { + $report = [ + 'mapping' => [], + 'unresolved' => [], + 'copied' => ['composition' => 0, 'license_article' => 0], + 'already' => ['composition' => 0, 'license_article' => 0], + 'before' => $this->counts(), + 'after' => [], + 'mirror' => ['element_rows' => 0, 'missing_in_pivot' => 0, 'only_in_pivot' => 0], + ]; + + $dimension = DB::table('editorial_dimensions')->where('slug', 'saeule')->first(); + + if ($dimension === null) { + $report['after'] = $report['before']; + + return $report; + } + + $resolved = []; + + foreach (DB::table('editorial_dimension_values')->where('editorial_dimension_id', $dimension->id)->orderBy('id')->get() as $value) { + $pillar = $this->pillarFor($value); + + if (is_string($pillar)) { + $report['unresolved'][] = ['art' => 'Wert', 'wert_id' => (int) $value->id, 'wert' => $value->label, 'kennung' => $value->slug, 'grund' => $pillar]; + $report['mapping'][] = ['wert_id' => (int) $value->id, 'wert' => $value->label, 'saeule_id' => null, 'status' => 'offen']; + + continue; + } + + $resolved[(int) $value->id] = (int) $pillar->id; + $status = $value->pillar_id === null ? 'zugeordnet' : 'bereits zugeordnet'; + $hint = $value->label !== $pillar->name ? 'über Kennung zugeordnet, Bezeichnung weicht ab („'.$pillar->name.'“)' : null; + $report['mapping'][] = ['wert_id' => (int) $value->id, 'wert' => $value->label, 'saeule_id' => (int) $pillar->id, 'saeule' => $pillar->name, 'status' => $status, 'hinweis' => $hint]; + + if ($value->pillar_id === null && ! $dryRun) { + DB::table('editorial_dimension_values')->where('id', $value->id)->update(['pillar_id' => $pillar->id]); + } + } + + $subjectTypes = $this->subjectTypes(); + + foreach (DB::table('identity_dimension_values') + ->whereIn('editorial_dimension_value_id', DB::table('editorial_dimension_values')->where('editorial_dimension_id', $dimension->id)->select('id')) + ->orderBy('id')->get() as $row) { + $valueId = (int) $row->editorial_dimension_value_id; + $label = DB::table('editorial_dimension_values')->where('id', $valueId)->value('label'); + $target = $subjectTypes[$row->subject_type] ?? null; + + if ($target === 'content_element') { + $report['mirror']['element_rows']++; + + continue; + } + + $where = ['art' => 'Zuordnung', 'zuordnung_id' => (int) $row->id, 'wert_id' => $valueId, 'wert' => $label, 'objektart' => $row->subject_type, 'objekt_id' => (int) $row->subject_id, 'herkunft' => $row->origin]; + + if ($target === null) { + $report['unresolved'][] = $where + ['grund' => 'unbekannte Objektart']; + + continue; + } + + if ($row->origin !== 'direkt') { + $report['unresolved'][] = $where + ['grund' => 'abgeleitete Zuordnung (wird nicht als direkte übernommen)']; + + continue; + } + + if (! isset($resolved[$valueId])) { + $report['unresolved'][] = $where + ['grund' => 'Wert ohne belastbare Säule']; + + continue; + } + + $config = self::TARGETS[$target]; + + if (! DB::table($config['subjects'])->where('id', $row->subject_id)->exists()) { + $report['unresolved'][] = $where + ['grund' => 'Objekt nicht mehr vorhanden']; + + continue; + } + + $present = DB::table($config['table'])->where($config['column'], $row->subject_id)->where('pillar_id', $resolved[$valueId])->exists(); + + if ($present) { + $report['already'][$target]++; + + continue; + } + + if (! $dryRun) { + DB::table($config['table'])->insertOrIgnore([$config['column'] => $row->subject_id, 'pillar_id' => $resolved[$valueId]]); + } + + $report['copied'][$target]++; + } + + $report['mirror'] = array_merge($report['mirror'], $this->mirrorDivergence($dimension->id, $resolved)); + $report['after'] = $dryRun ? $report['before'] : $this->counts(); + + return $report; + } + + /** + * @param array $report + * @return list + */ + public static function lines(array $report, bool $dryRun = false): array + { + $names = ['composition' => 'Module und Programme', 'license_article' => 'Lizenzartikel']; + $lines = [$dryRun ? 'Probelauf, es wird nichts geschrieben.' : 'Übernahme abgeschlossen.', '']; + + foreach ($report['mapping'] as $row) { + $lines[] = sprintf('Wert %d „%s“ → %s%s', $row['wert_id'], $row['wert'], $row['saeule_id'] === null ? 'keine Säule (offen)' : 'Säule '.$row['saeule_id'].' „'.($row['saeule'] ?? '').'“ ('.$row['status'].')', ! empty($row['hinweis']) ? ' – '.$row['hinweis'] : ''); + } + + $lines[] = ''; + + foreach ($names as $key => $label) { + $lines[] = sprintf('%s: %d übernommen, %d bereits vorhanden, Zuordnungen vorher %d, nachher %d', $label, $report['copied'][$key], $report['already'][$key], $report['before'][$key], $report['after'][$key]); + } + + $lines[] = sprintf('Medien (nur Information): %d gespiegelte Zeilen, %d nicht mehr in der Medienzuordnung, %d nur dort. Maßgeblich bleibt die Medienzuordnung.', $report['mirror']['element_rows'], $report['mirror']['missing_in_pivot'], $report['mirror']['only_in_pivot']); + + if ($report['unresolved'] === []) { + $lines[] = 'Keine ungeklärten Fälle.'; + } else { + $lines[] = ''; + $lines[] = 'Ungeklärt, bitte entscheiden (nichts wurde geändert):'; + + foreach ($report['unresolved'] as $row) { + $lines[] = '- '.json_encode($row, JSON_UNESCAPED_UNICODE); + } + } + + return $lines; + } + + /** + * Die Säule zu einem alten Wert, oder der Grund, warum es keine belastbare gibt. + */ + private function pillarFor(object $value): object|string + { + if (preg_match('/^pfeiler-(\d+)$/', (string) $value->slug, $match) !== 1) { + return 'Kennung ist nicht „pfeiler-“, keine belastbare Verknüpfung'; + } + + $pillar = DB::table('pillars')->where('id', (int) $match[1])->first(); + + if ($pillar === null) { + return 'Die Säule zur Kennung existiert nicht mehr'; + } + + if ($value->pillar_id !== null && (int) $value->pillar_id !== (int) $pillar->id) { + return 'Gespeicherte Verknüpfung (Säule '.$value->pillar_id.') und Kennung (Säule '.$pillar->id.') widersprechen sich'; + } + + if ($pillar->created_at !== null && $value->created_at !== null && $pillar->created_at > $value->created_at) { + return 'Die Säule ist jünger als der Wert; die Kennung kann nicht aus ihr entstanden sein'; + } + + return $pillar; + } + + /** + * @return array Objektart wie gespeichert => Ziel + */ + private function subjectTypes(): array + { + $types = []; + + foreach ([ + 'composition' => [Composition::class], + 'license_article' => [LicenseArticle::class], + 'content_element' => [ContentElement::class], + ] as $target => $classes) { + foreach ($classes as $class) { + $types[$class] = $target; + $types[(new $class)->getMorphClass()] = $target; + } + } + + return $types; + } + + /** + * @return array + */ + private function counts(): array + { + return [ + 'composition' => DB::table('composition_pillar')->count(), + 'license_article' => DB::table('license_article_pillar')->count(), + ]; + } + + /** + * @param array $resolved + * @return array{missing_in_pivot: int, only_in_pivot: int} + */ + private function mirrorDivergence(int $dimensionId, array $resolved): array + { + $mirrored = []; + + foreach (DB::table('identity_dimension_values') + ->whereIn('subject_type', array_unique([ContentElement::class, (new ContentElement)->getMorphClass()])) + ->whereIn('editorial_dimension_value_id', array_keys($resolved) ?: [0]) + ->get() as $row) { + $mirrored[$row->subject_id.':'.$resolved[(int) $row->editorial_dimension_value_id]] = true; + } + + $pivot = []; + + foreach (DB::table('content_element_pillar')->get() as $row) { + $pivot[$row->content_element_id.':'.$row->pillar_id] = true; + } + + return [ + 'missing_in_pivot' => count(array_diff_key($mirrored, $pivot)), + 'only_in_pivot' => count(array_diff_key($pivot, $mirrored)), + ]; + } +} diff --git a/app/Domain/Catalog/LicenseArticle.php b/app/Domain/Catalog/LicenseArticle.php index 8116e63..197093f 100644 --- a/app/Domain/Catalog/LicenseArticle.php +++ b/app/Domain/Catalog/LicenseArticle.php @@ -4,6 +4,7 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\HasMany; class LicenseArticle extends Model @@ -49,4 +50,10 @@ public function editorialContentKind(): BelongsTo { return $this->belongsTo(EditorialContentKind::class); } + + /** Direkt zugeordnete fachliche Säulen (zentrale Säulenverwaltung). */ + public function pillars(): BelongsToMany + { + return $this->belongsToMany(Pillar::class)->orderBy('pillars.sort_order')->orderBy('pillars.name'); + } } diff --git a/app/Domain/Catalog/Pillar.php b/app/Domain/Catalog/Pillar.php index 91e4998..a408713 100644 --- a/app/Domain/Catalog/Pillar.php +++ b/app/Domain/Catalog/Pillar.php @@ -34,6 +34,16 @@ public function pages(): BelongsToMany return $this->belongsToMany(Page::class); } + public function compositions(): BelongsToMany + { + return $this->belongsToMany(Composition::class); + } + + public function licenseArticles(): BelongsToMany + { + return $this->belongsToMany(LicenseArticle::class); + } + /** * @param Builder $query * @return Builder diff --git a/app/Domain/Catalog/PillarFilterCompat.php b/app/Domain/Catalog/PillarFilterCompat.php new file mode 100644 index 0000000..d1814d2 --- /dev/null +++ b/app/Domain/Catalog/PillarFilterCompat.php @@ -0,0 +1,31 @@ +join('editorial_dimensions', 'editorial_dimensions.id', '=', 'editorial_dimension_values.editorial_dimension_id') + ->where('editorial_dimension_values.id', $valueId) + ->where('editorial_dimensions.slug', EditorialDimension::PILLAR_SLUG) + ->first(['editorial_dimension_values.pillar_id']); + + if ($row === null) { + return false; + } + + return $row->pillar_id === null ? null : (int) $row->pillar_id; + } +} diff --git a/app/Domain/Catalog/PillarService.php b/app/Domain/Catalog/PillarService.php index c8f14df..7b44a56 100644 --- a/app/Domain/Catalog/PillarService.php +++ b/app/Domain/Catalog/PillarService.php @@ -40,19 +40,55 @@ public function present(Pillar $pillar, string $name, string $slug, ?string $sum public function delete(Pillar $pillar): void { - if ($pillar->elements()->exists() || $pillar->pages()->exists()) { - throw new DomainRuleException('Eine Säule mit zugeordneten Medien oder Seiten wird nicht gelöscht.'); + $usage = $this->usage($pillar); + + if (array_sum($usage) > 0) { + throw new DomainRuleException('Eine Säule mit zugeordneten Objekten wird nicht gelöscht ('.$this->usageText($usage).'). Ordnen Sie sie zuerst anders zu.'); } $pillar->delete(); } /** - * @param list $pillarIds + * Zuordnungen je Objektart: Medien, Module und Programme, Lizenzartikel, Seiten. + * + * @return array{medien: int, zusammenstellungen: int, lizenzartikel: int, seiten: int} */ - public function assign(ContentElement $element, array $pillarIds): void + public function usage(Pillar $pillar): array { - $element->pillars()->sync($this->ids($pillarIds)); + return [ + 'medien' => $pillar->elements()->count(), + 'zusammenstellungen' => $pillar->compositions()->count(), + 'lizenzartikel' => $pillar->licenseArticles()->count(), + 'seiten' => $pillar->pages()->count(), + ]; + } + + /** + * @param array{medien: int, zusammenstellungen: int, lizenzartikel: int, seiten: int} $usage + */ + public function usageText(array $usage): string + { + $parts = []; + + foreach (['medien' => ['Medium', 'Medien'], 'zusammenstellungen' => ['Modul oder Programm', 'Module und Programme'], 'lizenzartikel' => ['Lizenzartikel', 'Lizenzartikel'], 'seiten' => ['Seite', 'Seiten']] as $key => [$one, $many]) { + if ($usage[$key] > 0) { + $parts[] = $usage[$key].' '.($usage[$key] === 1 ? $one : $many); + } + } + + return $parts === [] ? 'nirgends zugeordnet' : implode(', ', $parts); + } + + /** + * Ordnet einem Medium, Modul, Programm, Lizenzartikel oder einer Seite Säulen zu. Alle Objektarten verwenden + * dieselbe zentrale Säule und dieselbe Speicherregel; die Zuordnung ersetzt die bisherige vollständig. + * + * @param list $pillarIds + */ + public function assign(ContentElement|Composition|LicenseArticle|Page $subject, array $pillarIds): void + { + $subject->pillars()->sync($this->ids($pillarIds)); } /** @@ -60,7 +96,7 @@ public function assign(ContentElement $element, array $pillarIds): void */ public function assignPages(Page $page, array $pillarIds): void { - $page->pillars()->sync($this->ids($pillarIds)); + $this->assign($page, $pillarIds); } /** diff --git a/app/Filament/Resources/Compositions/Pages/EditComposition.php b/app/Filament/Resources/Compositions/Pages/EditComposition.php index 5fe04cf..31d4f0c 100644 --- a/app/Filament/Resources/Compositions/Pages/EditComposition.php +++ b/app/Filament/Resources/Compositions/Pages/EditComposition.php @@ -22,6 +22,7 @@ use App\Domain\Cms\Catalog\PublicCatalogReader; use App\Domain\Cms\Widgets\RenderContext; use App\Filament\Resources\ContentElements\ContentElementResource; +use App\Filament\Support\AssignsPillars; use App\Filament\Support\EditorialCatalog; use App\Filament\Support\ManagesEditorialSurface; use App\Filament\Support\MediumForm; @@ -43,6 +44,7 @@ abstract class EditComposition extends EditRecord { + use AssignsPillars; use ManagesEditorialSurface; use WithFileUploads; @@ -398,11 +400,15 @@ public function redaktionTexteHinweis(): string */ public function einordnungGruppen(): array { - return array_map(fn (array $group): array => [ + $groups = array_map(fn (array $group): array => [ 'legend' => $group['label'], 'model' => 'dimensionIds', 'values' => $group['values'], ], $this->dimensionGroups()); + + $pillars = $this->pillarGroup(); + + return $pillars === null ? $groups : [$pillars, ...$groups]; } /** @@ -466,7 +472,7 @@ public function einordnungUnsaved(): bool sort($stored); sort($current); - return $stored !== $current; + return $stored !== $current || $this->pillarsUnsaved($record); } public function openText(): void @@ -1654,6 +1660,7 @@ protected function fillRedaktion(): void ->pluck('editorial_dimension_value_id') ->map(fn (mixed $id): string => (string) (int) $id) ->all(); + $this->loadPillarIds($composition); } /** @@ -1913,6 +1920,7 @@ protected function persistRedaktion(): bool 'description' => $this->description, ], $this->actor()); $this->syncDimensions($record, array_map(intval(...), $this->dimensionIds)); + $this->persistPillarIds($record); $record->refresh(); $this->getRecord()->setRawAttributes($record->getAttributes()); diff --git a/app/Filament/Resources/ContentElements/Pages/ListContentElements.php b/app/Filament/Resources/ContentElements/Pages/ListContentElements.php index 4cbde8c..e9c9bb8 100644 --- a/app/Filament/Resources/ContentElements/Pages/ListContentElements.php +++ b/app/Filament/Resources/ContentElements/Pages/ListContentElements.php @@ -3,6 +3,7 @@ namespace App\Filament\Resources\ContentElements\Pages; use App\Domain\Catalog\EditorialVocabulary; +use App\Domain\Catalog\PillarFilterCompat; use App\Filament\Resources\ContentElements\ContentElementResource; use App\Filament\Support\Bestand; use App\Filament\Support\MediaLibrary; @@ -170,6 +171,11 @@ public function resetFilters(): void */ public function bestand(): array { + // Alte Adressen mit einem Säulenwert der Einordnung gelten für die zentrale Säule. + if (ctype_digit($this->einordnung) && $this->saeule === '' && is_int($pillar = PillarFilterCompat::pillarOfLegacyValue((int) $this->einordnung))) { + [$this->saeule, $this->einordnung] = [(string) $pillar, '']; + } + $optionen = fn (array $liste, string $wert, string $label): array => collect($liste) ->mapWithKeys(fn (array $eintrag): array => [(string) $eintrag[$wert] => $eintrag[$label]]) ->all(); diff --git a/app/Filament/Resources/LicenseArticles/Pages/ViewLicenseArticle.php b/app/Filament/Resources/LicenseArticles/Pages/ViewLicenseArticle.php index 9c17df4..955ce78 100644 --- a/app/Filament/Resources/LicenseArticles/Pages/ViewLicenseArticle.php +++ b/app/Filament/Resources/LicenseArticles/Pages/ViewLicenseArticle.php @@ -16,6 +16,7 @@ use App\Domain\Catalog\LicenseArticle; use App\Filament\Resources\ContentElements\ContentElementResource; use App\Filament\Resources\LicenseArticles\LicenseArticleResource; +use App\Filament\Support\AssignsPillars; use App\Filament\Support\CatalogOptions; use App\Filament\Support\EditorialCatalog; use App\Filament\Support\ManagesEditorialSurface; @@ -30,6 +31,7 @@ class ViewLicenseArticle extends ViewRecord { + use AssignsPillars; use ManagesEditorialSurface; use ReportsDomainRules; @@ -115,6 +117,7 @@ protected function saveRedaktionTexte(): bool ], auth()->user()); app(IdentityDimension::class)->replaceOffered($article, array_map(intval(...), $this->dimensionIds)); + $this->persistPillarIds($article); $article->refresh(); $this->fillLicenseEditorial(); @@ -159,7 +162,7 @@ public function einordnungUnsaved(): bool sort($stored); sort($current); - return $stored !== $current; + return $stored !== $current || $this->pillarsUnsaved($article); } /** @@ -270,11 +273,15 @@ public function einordnungArt(): array */ public function einordnungGruppen(): array { - return array_map(fn (array $group): array => [ + $groups = array_map(fn (array $group): array => [ 'legend' => $group['label'], 'model' => 'dimensionIds', 'values' => $group['values'], ], $this->licenseDimensionGroups()); + + $pillars = $this->pillarGroup(); + + return $pillars === null ? $groups : [$pillars, ...$groups]; } private function sourceTitle(Model $source): string @@ -312,6 +319,7 @@ private function fillLicenseEditorial(): void ->where('origin', 'direkt') ->pluck('editorial_dimension_value_id') ->all(); + $this->loadPillarIds($article); } protected function getHeaderActions(): array diff --git a/app/Filament/Resources/Pillars/Pages/ListPillars.php b/app/Filament/Resources/Pillars/Pages/ListPillars.php index 80122d7..3142257 100644 --- a/app/Filament/Resources/Pillars/Pages/ListPillars.php +++ b/app/Filament/Resources/Pillars/Pages/ListPillars.php @@ -22,7 +22,7 @@ class ListPillars extends ListRecords public function getSubheading(): string|Htmlable|null { - return 'Die fachlichen Säulen des Materials. Eine veröffentlichte Säule ist ein Themenbereich der Website. Ein Medium und eine Seite können mehreren Säulen zugeordnet sein.'; + return 'Die fachlichen Säulen des Materials. Eine veröffentlichte Säule ist ein Themenbereich der Website. Medien, Module, Programme, Lizenzartikel und Seiten können mehreren Säulen zugeordnet sein. Hier ist die einzige Pflegestelle der Säulen.'; } protected function getHeaderActions(): array @@ -50,11 +50,28 @@ protected function getHeaderActions(): array ]; } + /** + * Zuordnungen aller Objektarten; ohne Zuordnung wie bisher „0 Medien“. + */ + private function usageLabel(PillarService $service, Pillar $pillar): string + { + $usage = [ + 'medien' => (int) $pillar->elements_count, + 'zusammenstellungen' => (int) $pillar->compositions_count, + 'lizenzartikel' => (int) $pillar->license_articles_count, + 'seiten' => (int) $pillar->pages_count, + ]; + + return array_sum($usage) === 0 ? '0 Medien' : $service->usageText($usage); + } + protected function catalogRows(): array { $rows = []; - foreach (Pillar::query()->withCount('elements')->orderBy('sort_order')->orderBy('name')->get() as $pillar) { + $service = app(PillarService::class); + + foreach (Pillar::query()->withCount(['elements', 'compositions', 'licenseArticles', 'pages'])->orderBy('sort_order')->orderBy('name')->get() as $pillar) { $public = $pillar->published_at !== null; $url = PillarResource::getUrl('edit', ['record' => $pillar]); $rows[] = [ @@ -66,7 +83,7 @@ protected function catalogRows(): array 'url' => $url, 'chips' => [ $public ? ['label' => 'Auf der Website veröffentlicht', 'ton' => 'gut'] : ['label' => 'Intern', 'ton' => 'leise'], - ['label' => $pillar->elements_count === 1 ? '1 Medium' : $pillar->elements_count.' Medien', 'ton' => 'neutral'], + ['label' => $this->usageLabel($service, $pillar), 'ton' => 'neutral'], ], 'zustand' => [$public ? 'oeffentlich' : 'intern'], 'aktionen' => [['label' => 'Bearbeiten', 'href' => $url, 'icon' => 'stift']], diff --git a/app/Filament/Support/AssignsPillars.php b/app/Filament/Support/AssignsPillars.php new file mode 100644 index 0000000..aca17f0 --- /dev/null +++ b/app/Filament/Support/AssignsPillars.php @@ -0,0 +1,53 @@ + */ + public array $pillarIds = []; + + /** + * @return array{legend: string, model: string, values: list}|null + */ + public function pillarGroup(): ?array + { + $values = Pillar::query()->orderBy('sort_order')->orderBy('name')->get(['id', 'name']) + ->map(fn (Pillar $pillar): array => ['id' => (int) $pillar->id, 'label' => (string) $pillar->name]) + ->all(); + + return $values === [] ? null : ['legend' => 'Fachliche Säulen', 'model' => 'pillarIds', 'values' => $values]; + } + + protected function loadPillarIds(Composition|LicenseArticle $subject): void + { + $this->pillarIds = $subject->pillars()->pluck('pillars.id')->map(fn (mixed $id): string => (string) (int) $id)->all(); + } + + protected function persistPillarIds(Composition|LicenseArticle $subject): void + { + app(PillarService::class)->assign($subject, array_map(intval(...), $this->pillarIds)); + } + + protected function pillarsUnsaved(Composition|LicenseArticle $subject): bool + { + $stored = $subject->pillars()->pluck('pillars.id')->map(fn (mixed $id): int => (int) $id)->all(); + $current = array_map(intval(...), $this->pillarIds); + sort($stored); + sort($current); + + return $stored !== $current; + } +} diff --git a/app/Filament/Support/ChoosesMedia.php b/app/Filament/Support/ChoosesMedia.php index c8c0820..47bd4d2 100644 --- a/app/Filament/Support/ChoosesMedia.php +++ b/app/Filament/Support/ChoosesMedia.php @@ -5,6 +5,7 @@ use App\Domain\Catalog\ContentElement; use App\Domain\Catalog\ContentElementVersion; use App\Domain\Catalog\EditorialVocabulary; +use App\Domain\Catalog\Pillar; use App\Domain\Cms\Catalog\PublicMaterialReader; use App\Domain\Cms\Widgets\Support\WebsiteImage; use App\Http\Controllers\ContentPreviewController; @@ -27,6 +28,9 @@ trait ChoosesMedia public string $pickerDimension = ''; + /** Filter „Fachliche Säule“ (Kennung der Säule aus der zentralen Säulenverwaltung). */ + public string $pickerSaeule = ''; + /** Filter „Fachliche Materialart“ (Kennung), gleiche Regel wie Medieneditor und Medienfilter. */ public string $pickerMaterialart = ''; @@ -108,6 +112,8 @@ public function pickerResult(): array $this->pickerKind, $this->pickerDimension, $this->pickerExceptId(), + false, + ctype_digit($this->pickerSaeule) ? (int) $this->pickerSaeule : 0, )); } @@ -204,6 +210,7 @@ protected function resetPicker(string $purpose): void $this->pickerOpen = true; $this->pickerQuery = ''; $this->pickerDimension = ''; + $this->pickerSaeule = ''; $this->pickerMaterialart = ''; $this->pickerInspected = ''; $this->pickerSelected = ''; @@ -239,6 +246,17 @@ private function filterByMaterialart(array $result): array return $result; } + /** + * Säulen für den Picker-Filter, in der Reihenfolge der Säulenverwaltung. + * + * @return array + */ + public function pickerSaeulen(): array + { + return Pillar::query()->orderBy('sort_order')->orderBy('name')->pluck('name', 'id') + ->mapWithKeys(fn (string $name, int|string $id): array => [(string) $id => $name])->all(); + } + /** * Einordnungsfilter des Pickers: dieselbe Filterregel wie Medien- und Kompositionslisten (verwendete inaktive Werte * bleiben auffindbar, ein gewählter Filter bleibt sichtbar). diff --git a/app/Filament/Support/EditorialCatalog.php b/app/Filament/Support/EditorialCatalog.php index a01872a..36ef686 100644 --- a/app/Filament/Support/EditorialCatalog.php +++ b/app/Filament/Support/EditorialCatalog.php @@ -272,7 +272,7 @@ public function search(string $query, string $scope, int $exceptCompositionId): /** * @return array{items: list>, more: bool} */ - public function browse(string $query, string $kind, string $dimension, int $exceptCompositionId, bool $elementsOnly = false): array + public function browse(string $query, string $kind, string $dimension, int $exceptCompositionId, bool $elementsOnly = false, int $pillarId = 0): array { $query = trim($query); $like = '%'.str_replace(['%', '_'], ['', ''], $query).'%'; @@ -284,8 +284,8 @@ public function browse(string $query, string $kind, string $dimension, int $exce $latestElements = ContentElementVersion::query() ->selectRaw('MAX(id)') ->whereIn('status', [ContentVersionStatus::Bereit, ContentVersionStatus::Entwurf]) - ->whereHas('element', function ($builder) use ($query, $like, $kind, $dimensionId): void { - $this->constrainElement($builder, $query, $like, $kind, $dimensionId); + ->whereHas('element', function ($builder) use ($query, $like, $kind, $dimensionId, $pillarId): void { + $this->constrainElement($builder, $query, $like, $kind, $dimensionId, $pillarId); }) ->groupBy('content_element_id'); $elements = ContentElementVersion::query() @@ -309,7 +309,7 @@ public function browse(string $query, string $kind, string $dimension, int $exce ->selectRaw('MAX(id)') ->where('status', ContentVersionStatus::Bereit) ->where('composition_id', '!=', $exceptCompositionId) - ->whereHas('composition', function ($builder) use ($query, $like, $kind, $dimensionId): void { + ->whereHas('composition', function ($builder) use ($query, $like, $kind, $dimensionId, $pillarId): void { if ($kind === 'modul') { $builder->where('kind', CompositionKind::Uebung); } @@ -318,6 +318,10 @@ public function browse(string $query, string $kind, string $dimension, int $exce $builder->whereIn('id', $this->dimensionSubjectIds(Composition::class, $dimensionId)); } + if ($pillarId > 0) { + $builder->whereIn('id', $this->pillarSubjectIds(Composition::class, $pillarId)); + } + if ($query === '') { return; } @@ -370,6 +374,10 @@ public function browse(string $query, string $kind, string $dimension, int $exce continue; } + if ($pillarId > 0 && ! in_array($composition->id, $this->pillarSubjectIds(Composition::class, $pillarId), true)) { + continue; + } + $title = $this->compositionTitle($composition); if ($query !== '' && ! str_contains(mb_strtolower($title.' '.(string) ($composition->summary ?? '')), mb_strtolower($query))) { @@ -564,7 +572,7 @@ private function withVisibility(array $rows): array /** * @param Builder $builder */ - private function constrainElement($builder, string $query, string $like, string $kind, int $dimensionId): void + private function constrainElement($builder, string $query, string $like, string $kind, int $dimensionId, int $pillarId = 0): void { $outputs = match ($kind) { 'film' => ['film'], @@ -583,6 +591,10 @@ private function constrainElement($builder, string $query, string $like, string $builder->whereIn('id', $this->dimensionSubjectIds(ContentElement::class, $dimensionId)); } + if ($pillarId > 0) { + $builder->whereIn('id', $this->pillarSubjectIds(ContentElement::class, $pillarId)); + } + if ($query === '') { return; } @@ -597,6 +609,22 @@ private function constrainElement($builder, string $query, string $like, string }); } + /** + * Direkt einer Säule zugeordnete Medien oder Module und Programme (zentrale Säulenverwaltung). + * + * @param class-string $class + * @return list + */ + private function pillarSubjectIds(string $class, int $pillarId): array + { + [$table, $column] = $class === Composition::class + ? ['composition_pillar', 'composition_id'] + : ['content_element_pillar', 'content_element_id']; + + return DB::table($table)->where('pillar_id', $pillarId)->pluck($column) + ->map(fn (mixed $id): int => (int) $id)->all(); + } + /** * @param class-string $class * @return list diff --git a/app/Filament/Support/ListsCompositions.php b/app/Filament/Support/ListsCompositions.php index bf4345c..54fb114 100644 --- a/app/Filament/Support/ListsCompositions.php +++ b/app/Filament/Support/ListsCompositions.php @@ -7,9 +7,12 @@ use App\Domain\Catalog\ContentVersionStatus; use App\Domain\Catalog\EditorialVocabulary; use App\Domain\Catalog\IdentityDimensionValue; +use App\Domain\Catalog\Pillar; +use App\Domain\Catalog\PillarFilterCompat; use App\Filament\Resources\ContentElements\ContentElementResource; use Filament\Actions\Action; use Filament\Forms\Components\TextInput; +use Illuminate\Support\Facades\DB; use Livewire\Attributes\Url; /** @@ -29,6 +32,10 @@ trait ListsCompositions #[Url] public string $pillar = ''; + /** Fachliche Säule (zentrale Säulenverwaltung), direkt zugeordnet. */ + #[Url(as: 'saeule', except: '')] + public string $saeule = ''; + #[Url] public string $visibility = 'alle'; @@ -39,7 +46,7 @@ protected function fixedKind(): ?CompositionKind protected function bestandFilterEigenschaften(): array { - return ['query', 'kindFilter', 'pillar', 'visibility']; + return ['query', 'kindFilter', 'pillar', 'saeule', 'visibility']; } public function resetFilters(): void @@ -47,13 +54,14 @@ public function resetFilters(): void $this->query = ''; $this->kindFilter = 'alle'; $this->pillar = ''; + $this->saeule = ''; $this->visibility = 'alle'; $this->bestandGrenze = Bestand::SCHRITT; } public function hasActiveFilters(): bool { - return trim($this->query) !== '' || $this->kindFilter !== 'alle' || $this->pillar !== '' || $this->visibility !== 'alle'; + return trim($this->query) !== '' || $this->kindFilter !== 'alle' || $this->pillar !== '' || $this->saeule !== '' || $this->visibility !== 'alle'; } /** @@ -61,6 +69,7 @@ public function hasActiveFilters(): bool */ public function bestand(): array { + $this->normalizeLegacyPillarFilter(); $fixed = $this->fixedKind(); $einheit = match ($fixed) { CompositionKind::Kurs => ['Programm', 'Programme'], @@ -90,9 +99,14 @@ public function bestand(): array 'eigenschaft' => 'visibility', 'label' => 'Stand', 'vorgabe' => 'alle', 'optionen' => ['alle' => 'Jeder Stand', 'bibliothek' => 'In der Mitgliederbibliothek', 'verborgen' => 'Nicht in der Mitgliederbibliothek', 'entwurf' => 'Noch ohne Fassung'], ]], - 'weitere' => $gruppen === [] ? [] : [[ - 'eigenschaft' => 'pillar', 'label' => 'Fachliche Einordnung', 'vorgabe' => '', 'alle' => 'Alle Einordnungen', 'gruppen' => $gruppen, - ]], + 'weitere' => [ + ...($this->pillarOptions() === [] ? [] : [[ + 'eigenschaft' => 'saeule', 'label' => 'Fachliche Säule', 'vorgabe' => '', 'alle' => 'Alle Säulen', 'optionen' => $this->pillarOptions(), + ]]), + ...($gruppen === [] ? [] : [[ + 'eigenschaft' => 'pillar', 'label' => 'Fachliche Einordnung', 'vorgabe' => '', 'alle' => 'Alle Einordnungen', 'gruppen' => $gruppen, + ]]), + ], 'zeilen' => $this->entries(), 'einheit' => $einheit, 'leer' => [ @@ -124,7 +138,9 @@ public function entries(): array $needle = mb_strtolower(trim($this->query)); $catalog = app(EditorialCatalog::class); $offered = $catalog->offeredCompositionIds(); + $this->normalizeLegacyPillarFilter(); $pillarIds = $this->pillar === '' ? null : $this->pillarSubjects((int) $this->pillar); + $saeuleIds = ctype_digit($this->saeule) && $this->saeule !== '' ? $this->saeuleSubjects((int) $this->saeule) : null; $fixed = $this->fixedKind(); $kinds = $fixed !== null ? [$fixed] : match ($this->kindFilter) { 'programm' => [CompositionKind::Kurs], @@ -149,6 +165,10 @@ public function entries(): array continue; } + if ($saeuleIds !== null && ! in_array($composition->id, $saeuleIds, true)) { + continue; + } + $stand = $catalog->stand($composition); if (! $this->matchesVisibility($stand)) { @@ -249,6 +269,36 @@ private function coverMembers(Composition $composition): array return $members; } + /** + * Alte Adressen mit einem Säulenwert der Einordnung (`?pillar=…`) gelten für die zentrale Säule. + */ + private function normalizeLegacyPillarFilter(): void + { + if (ctype_digit($this->pillar) && $this->pillar !== '' && $this->saeule === '' && is_int($pillar = PillarFilterCompat::pillarOfLegacyValue((int) $this->pillar))) { + [$this->saeule, $this->pillar] = [(string) $pillar, '']; + } + } + + /** + * @return array + */ + private function pillarOptions(): array + { + return Pillar::query()->orderBy('sort_order')->orderBy('name')->pluck('name', 'id') + ->mapWithKeys(fn (string $name, int|string $id): array => [(string) $id => $name])->all(); + } + + /** + * Direkt zugeordnete Module und Programme einer Säule. Die Säulen der enthaltenen Medien zählen hier nicht. + * + * @return list + */ + private function saeuleSubjects(int $pillarId): array + { + return DB::table('composition_pillar')->where('pillar_id', $pillarId)->pluck('composition_id') + ->map(fn (mixed $id): int => (int) $id)->all(); + } + /** * @return list */ diff --git a/app/Filament/Support/MediaLibrary.php b/app/Filament/Support/MediaLibrary.php index 044645b..840cd36 100644 --- a/app/Filament/Support/MediaLibrary.php +++ b/app/Filament/Support/MediaLibrary.php @@ -11,6 +11,7 @@ use App\Domain\Catalog\EditorialVocabulary; use App\Domain\Catalog\IdentityDimensionValue; use App\Domain\Catalog\Pillar; +use App\Domain\Catalog\PillarFilterCompat; use App\Domain\Catalog\ReleaseContent; use App\Domain\Media\ThumbnailRef; use App\Filament\Resources\ContentElements\ContentElementResource; @@ -132,6 +133,13 @@ public function cards(array $filters, bool $canEdit): array */ private function normalize(array $filters): array { + $saeule = ctype_digit($filters['saeule'] ?? '') ? $filters['saeule'] : ''; + $einordnung = ctype_digit($filters['einordnung'] ?? '') ? $filters['einordnung'] : ''; + + if ($einordnung !== '' && $saeule === '' && is_int($pillar = PillarFilterCompat::pillarOfLegacyValue((int) $einordnung))) { + [$saeule, $einordnung] = [(string) $pillar, '']; + } + return [ 'suche' => trim($filters['suche'] ?? ''), 'art' => $this->choice($filters['art'] ?? '', ['film', 'text', 'document', 'bild', 'audio']), @@ -139,8 +147,8 @@ private function normalize(array $filters): array 'entwurf' => $this->choice($filters['entwurf'] ?? '', ['offen', 'keiner']), 'fassung' => $this->choice($filters['fassung'] ?? '', ['mit', 'nur']), 'nutzung' => $this->choice($filters['nutzung'] ?? '', ['verwendet', 'unbenutzt']), - 'saeule' => ctype_digit($filters['saeule'] ?? '') ? $filters['saeule'] : '', - 'einordnung' => ctype_digit($filters['einordnung'] ?? '') ? $filters['einordnung'] : '', + 'saeule' => $saeule, + 'einordnung' => $einordnung, 'inhaltsart' => ctype_digit($filters['inhaltsart'] ?? '') ? $filters['inhaltsart'] : '', 'verarbeitung' => $this->choice($filters['verarbeitung'] ?? '', ['fehler', 'uebernahme']), 'archiv' => $this->choice($filters['archiv'] ?? '', ['aktiv', 'archiviert', 'alle'], 'aktiv'), diff --git a/app/Http/Controllers/Member/LibraryController.php b/app/Http/Controllers/Member/LibraryController.php index 147fe63..0909c65 100644 --- a/app/Http/Controllers/Member/LibraryController.php +++ b/app/Http/Controllers/Member/LibraryController.php @@ -9,6 +9,8 @@ use App\Domain\Catalog\EditorialVocabulary; use App\Domain\Catalog\IdentityDimension; use App\Domain\Catalog\LicenseArticle; +use App\Domain\Catalog\Pillar; +use App\Domain\Catalog\PillarFilterCompat; use App\Domain\Entitlement\DecideAccess; use App\Domain\Entitlement\Grant; use App\Domain\Entitlement\GrantStatus; @@ -20,8 +22,10 @@ use App\Http\CourseOutline; use App\Http\LibraryCatalog; use App\Http\SignedLink; +use Illuminate\Database\Eloquent\Model; use Illuminate\Http\Request; use Illuminate\Http\Response; +use Illuminate\Support\Collection; use Illuminate\Support\Facades\Storage; use Illuminate\View\View; use Symfony\Component\HttpFoundation\StreamedResponse; @@ -35,8 +39,21 @@ public function index(Request $request, ?string $sicht = null): View $query = trim((string) $request->query('q', '')); $nutzung = (string) $request->query('nutzung', ''); $dimensionIds = array_values(array_filter(array_map(intval(...), (array) $request->query('dimension', [])))); + $saeuleIds = array_values(array_filter(array_map(intval(...), (array) $request->query('saeule', [])))); $dimensions = app(IdentityDimension::class); + // Alte Adressen: Säulen waren ein Wert der Einordnung. Mit belastbarer Verknüpfung gilt der Filter der Säule. + foreach ($dimensionIds as $index => $valueId) { + if (is_int($pillarId = PillarFilterCompat::pillarOfLegacyValue($valueId))) { + $saeuleIds[] = $pillarId; + unset($dimensionIds[$index]); + } + } + + $dimensionIds = array_values($dimensionIds); + $saeuleIds = array_values(array_unique($saeuleIds)); + $pillarOptions = $this->visiblePillars($catalog, $saeuleIds); + foreach (['programs', 'modules'] as $shelf) { if ($query !== '') { $catalog[$shelf] = array_values(array_filter( @@ -50,6 +67,12 @@ public function index(Request $request, ?string $sicht = null): View fn (array $card): bool => $dimensions->matches($card['composition'], $dimensionIds), )); } + if ($saeuleIds !== []) { + $catalog[$shelf] = array_values(array_filter( + $catalog[$shelf], + fn (array $card): bool => $this->hasPillar($card['composition'], $saeuleIds), + )); + } if (in_array($nutzung, ['nutzbar', 'teilweise', 'nicht enthalten'], true)) { $catalog[$shelf] = array_values(array_filter( $catalog[$shelf], @@ -79,6 +102,13 @@ function (array $card) use ($dimensions, $dimensionIds): bool { )); } + if ($saeuleIds !== []) { + $catalog['materials'] = array_values(array_filter( + $catalog['materials'], + fn (array $card): bool => $this->hasPillar($this->materialSubject($card), $saeuleIds), + )); + } + if ($nutzung === 'teilweise' || $nutzung === 'nicht enthalten') { $catalog['materials'] = []; } @@ -89,11 +119,65 @@ function (array $card) use ($dimensions, $dimensionIds): bool { 'sicht' => $sicht, 'nutzung' => $nutzung, 'dimensionIds' => $dimensionIds, + 'saeuleIds' => $saeuleIds, + 'filterPillars' => $pillarOptions, 'filterDimensions' => app(EditorialVocabulary::class)->memberFilterDimensions(array_map(intval(...), $dimensionIds)), 'libraryEmpty' => $untouched, ]); } + /** + * Subjekt eines Materialkarte: Programm oder Modul, Medium oder der Artikel selbst. + * + * @param array $card + */ + private function materialSubject(array $card): Model + { + $release = $card['article']->currentRelease; + + return $release?->rootCompositionVersion?->composition + ?? $release?->rootElementVersion?->element + ?? $card['article']; + } + + /** + * Direkte Säulenzuordnung des Objekts selbst; die Säulen enthaltener Medien zählen hier nicht. + * + * @param list $pillarIds + */ + private function hasPillar(Model $subject, array $pillarIds): bool + { + return $subject->pillars()->whereIn('pillars.id', $pillarIds)->exists(); + } + + /** + * Säulen für den Filter: nur solche, die ein sichtbares Objekt der Bibliothek tatsächlich trägt, und eine bereits + * gewählte. So erscheinen neue oder interne Säulen ohne Zuordnung nicht in der Bibliothek. + * + * @param array $catalog + * @param list $selected + * @return Collection + */ + private function visiblePillars(array $catalog, array $selected) + { + $used = []; + + foreach (array_merge($catalog['programs'], $catalog['modules']) as $card) { + foreach ($card['composition']->pillars()->pluck('pillars.id') as $id) { + $used[(int) $id] = true; + } + } + + foreach ($catalog['materials'] as $card) { + foreach ($this->materialSubject($card)->pillars()->pluck('pillars.id') as $id) { + $used[(int) $id] = true; + } + } + + return Pillar::query()->whereIn('id', array_values(array_unique([...array_keys($used), ...$selected]))) + ->orderBy('sort_order')->orderBy('name')->get(); + } + public function programs(Request $request): View { return $this->index($request, 'programme'); diff --git a/database/migrations/2026_11_21_100000_unify_pillar_assignments.php b/database/migrations/2026_11_21_100000_unify_pillar_assignments.php new file mode 100644 index 0000000..b1376c1 --- /dev/null +++ b/database/migrations/2026_11_21_100000_unify_pillar_assignments.php @@ -0,0 +1,59 @@ +foreignId('composition_id')->constrained()->cascadeOnDelete(); + $table->foreignId('pillar_id')->constrained()->restrictOnDelete(); + $table->primary(['composition_id', 'pillar_id']); + }); + + Schema::create('license_article_pillar', function (Blueprint $table) { + $table->foreignId('license_article_id')->constrained()->cascadeOnDelete(); + $table->foreignId('pillar_id')->constrained()->restrictOnDelete(); + $table->primary(['license_article_id', 'pillar_id']); + }); + + Schema::table('editorial_dimension_values', function (Blueprint $table) { + $table->foreignId('pillar_id')->nullable()->after('editorial_dimension_id')->constrained('pillars')->nullOnDelete(); + }); + + $report = (new LegacyPillarAdoption)->run(); + + foreach (LegacyPillarAdoption::lines($report) as $line) { + if ($line !== '') { + Log::info('Säulenübernahme: '.$line); + } + } + + if ($report['unresolved'] !== []) { + Log::warning('Säulenübernahme: '.count($report['unresolved']).' Fälle ungeklärt; „php artisan luf:saeulen-uebernehmen --dry-run“ listet sie.'); + } + } + + public function down(): void + { + Schema::table('editorial_dimension_values', function (Blueprint $table) { + $table->dropConstrainedForeignId('pillar_id'); + }); + + Schema::dropIfExists('license_article_pillar'); + Schema::dropIfExists('composition_pillar'); + } +}; diff --git a/docs/ux/verwaltung/16-funktionszuordnung.md b/docs/ux/verwaltung/16-funktionszuordnung.md index 00880e1..a9c394f 100644 --- a/docs/ux/verwaltung/16-funktionszuordnung.md +++ b/docs/ux/verwaltung/16-funktionszuordnung.md @@ -31,6 +31,7 @@ ## Bisher und jetzt | Filament-Kopfaktionen (Fassung freigeben, Neue Fassung, Bibliothek anzeigen/ausblenden, Stand veröffentlichen/zurückziehen) | Benannte Aktionen, aus dem gemeinsamen Kopf aufgerufen; seltene in „Weitere Aktionen“ | `kopf.blade.php`, `…Action()`-Methoden | | Lizenzartikel: Filament-Abschnitte und eingebettete Redaktion | Kopf, Überblick (Präsentation, Stand, Angebote), Redaktion als eigener Arbeitsplatz | `editorial/license-desk.blade.php` | | CMS-Seite: Filament-Kopf, Seitenformular mit Raster und Gestaltung an jedem Abschnitt, Revisionen als Tabelle unter dem Formular, Widgetdialog „Widget bearbeiten“ | Seitenaufbau als Überblick mit Miniaturvorschau je Baustein und knappen Abschnittsköpfen; Bildfelder über den gemeinsamen Picker (statt eigener Auswahlliste); Abschnittsgestaltung in drei Gruppen; „Entwurf speichern“ auch im Bausteindialog. Seitenkopf mit getrenntem Speicher- und Veröffentlichungszustand („Entwurf speichern“, Strg+S, „Veröffentlichen …“, Seitenvorschau, Live-Seite unter „Weitere Aktionen“); Register Seiteninhalt, Seiteneinstellungen, Verlauf. Seitenaufbau zeigt Abschnitte mit Plätzen; „Abschnitt gestalten“ öffnet einen Kontext für Raster und Gestaltung genau eines Abschnitts (Adresse `?abschnitt=N`, Esc und „Zur Seite“ zurück); „Konfigurieren“ öffnet den Baustein als großen Kontext mit Vorschau, Verlassen nur über „Zur Seite“ (übernimmt) oder „Änderungen verwerfen“. Ein Fehler in einem ausgeblendeten Register oder Abschnittsteil macht ihn sichtbar. Wiederherstellen einer Revision und Veröffentlichungsregeln unverändert | `cms/seite-kopf.blade.php`, `EditPage`, `SectionEditor`, `WidgetEditor` | +| Fachliche Säulen: Medien und Seiten über die Säulenverwaltung, Module, Programme und Lizenzartikel über eine nicht abgeglichene Kopie als Dimension | Eine Quelle: Säulenverwaltung (`pillars`) für alle fünf Objektarten; Auswahl in der Redaktion, Filter in Medien, Modulen und Programmen, Aufbau-Picker und Mitgliederbibliothek; alte Zuordnungen verlustfrei übernommen (`luf:saeulen-uebernehmen`); Kopie bleibt nur als Verlauf | `PillarService`, `AssignsPillars`, `LegacyPillarAdoption` | | Redaktionelle Auswahlwerte nur über Migrationen änderbar; „Inhaltsart“ bot allen Objekten alle Materialarten an | Arbeitsplatz „Redaktionelle Stammdaten“ (fachliche Materialarten, Altersbereich und Zielgruppe, Einsatzbereich, Verwendungszweck; Säulen verlinkt): Anlegen, Umbenennen bei fester Kennung, Deaktivieren, Reihenfolge, Verwendung; Materialarten mit zulässigen Kontexten. Redaktion, Medien- und Kompositionsfilter, Picker und Mitgliederbibliothek nutzen dieselbe Regel; „Fachliche Materialart“ durchgängig (FACH-56 bis FACH-58) | `RedaktionelleStammdaten`, `EditorialVocabulary` | | Seitenliste (Filament-Tabelle: Pfad, „Veröffentlicht: Ja/Entwurf“, Zuletzt bearbeitet, Duplizieren) | Webpräsenz, Register „Seiten“: gemeinsame Bestandsliste mit Titel und Adresse, Veröffentlichung (Revision, „Entwurf neuer“, „Nur Entwurf“), Menüzuordnung je Bereich oder „Ohne Menüeintrag“, Filter Veröffentlichung und Menü, Sortierung zuletzt bearbeitet (beide Richtungen) oder Adresse (beide Richtungen), Bearbeiten, Vorschau, Duplizieren (gleicher Dialog und Fehler). „Seite anlegen“ im Kopf. `/verwaltung/pages` leitet nach derselben Rechteprüfung dorthin | `Webpraesenz`, `verwaltung/bestand` | | Navigationsverwaltung (Filament-Tabelle je Platz, Dialoge Anlegen/Bearbeiten, Sofort-Ausblenden, Ziehen, Löschen) | Webpräsenz, Register „Menüs“: Bereichsauswahl, Menübaum mit einer Untermenüebene, Detailbereich rechts (breit) bzw. ein aufgeklappter Eintrag (schmal) mit Menütext, Ziel (Seitenwahl mit Zustand oder Adresse), Untermenü von, Im Menü anzeigen, Menübereich, Aus Menü entfernen; Umordnen per Ziehen, Knöpfen oder Alt+Pfeil innerhalb der Ebene. Änderungen bilden einen Arbeitsstand und werden mit „Menüänderungen speichern“ gemeinsam geschrieben (vorher wirkte jede Handlung sofort). Regeln der bisherigen Form unverändert geprüft. `/verwaltung/navigation-items` leitet dorthin | `Webpraesenz`, `cms/menues`, `cms/menue-zeile`, `cms/menue-detail`, `cms/ziel-auswahl`, `bestaetigung`, `abgang` | diff --git a/docs/ux/verwaltung/abnahme/stammdaten.md b/docs/ux/verwaltung/abnahme/stammdaten.md index 38c6eec..0551c03 100644 --- a/docs/ux/verwaltung/abnahme/stammdaten.md +++ b/docs/ux/verwaltung/abnahme/stammdaten.md @@ -68,12 +68,51 @@ ## Prüfung ## Einschränkungen - **Kontexte:** gibt es nur für Materialarten. Einordnungswerte gelten wie bisher für alle Objektarten. Fachliche Kombinationen tragen keine Materialart. -- **Säulen-Spiegel (bestehender Restpunkt, nicht geändert):** Die Dimension „Fachliche Säule“ ist eine Kopie der Säulen aus der Migration vom 16.11. Module, Programme und Lizenzartikel bieten sie weiterhin an, sie wird aber nicht mit der Säulenverwaltung abgeglichen. Medien verwenden die Säulen direkt. +- **Säulen-Spiegel: behoben am 21.11.2026**, siehe „Nachtrag: Säulen aus einer Quelle“. - **Löschen:** nur ohne Zuordnung. Es gibt kein Zusammenführen und kein Umdeuten von Werten. - **Bezeichnungen:** Innerhalb einer Gruppe darf eine Bezeichnung nur einmal vorkommen, ohne Unterscheidung von Groß- und Kleinschreibung. - **Picker-Filter:** Der Filter „Fachliche Materialart“ grenzt nur Medien ein. Module im Aufbau-Picker bleiben davon unberührt. - **Schmale Fenster:** Unter etwa 1100 px Inhaltsbreite scrollt die Tabelle waagerecht (Filament-Tabelle). +## Nachtrag: Säulen aus einer Quelle (21.11.2026) + +**Geprüfter Code-Stand:** `develop` mit `7c48a64` auf `luf-test` (Migration `2026_11_21_100000` gelaufen). + +**Gemeinsame Quelle:** die Säulenverwaltung (Tabelle `pillars`). Medien (`content_element_pillar`), Seiten (`page_pillar`) und jetzt auch Module und Programme (`composition_pillar`) sowie Lizenzartikel (`license_article_pillar`) verweisen mit demselben Fremdschlüssel auf sie; die Datenbank verhindert das Löschen einer verwendeten Säule (`restrictOnDelete`). Auswahl, Anzeige und Filter lesen die Säule selbst, deshalb gilt ein neuer oder geänderter Name sofort überall. + +**Befund vorher:** +- Medien und Seiten verwendeten die Säulen direkt. Module, Programme und Lizenzartikel nutzten die Dimension „Fachliche Säule“, eine Kopie, die die Migration vom 16.11. einmal gespiegelt hat. Später angelegte oder umbenannte Säulen fehlten dort. +- Dieselbe Kopie speiste Filter in Medienliste („Einordnung“), Aufbau-Picker, Listen für Programme und Module und die Mitgliederbibliothek. Für Medien waren die Spiegelzeilen veraltet. +- Abgeleitete Säulen (aus enthaltenen Medien) sind nur eine Laufzeitableitung (`CatalogReading::memberPillars`). Der Code schreibt nirgends Zuordnungen mit Herkunft „abgeleitet“. +- Veröffentlichte Seiten, Revisionen und Widgets verweisen auf `pillars`, nicht auf die alten Werte. Außer den Zuordnungszeilen verweist nichts auf die Kopie. + +**Umsetzung:** +- Editoren: Modul, Programm und Lizenzartikel wählen „Fachliche Säulen“ aus der Säulenverwaltung (gemeinsam über `AssignsPillars`, Mehrfachauswahl, wie bei Medien). Die Zuordnung ersetzt die bisherige vollständig; andere Angaben zu speichern lässt sie unverändert. +- Filter: Module und Programme (Arbeitsplatz und Listen) und Aufbau-Picker haben „Fachliche Säule“. Die Mitgliederbibliothek bietet nur Säulen an, die ein sichtbares Objekt tatsächlich trägt (Entscheidung, damit neue oder interne Säulen ohne Zuordnung nicht erscheinen). Es zählt die direkte Zuordnung. Alte Adressen mit einem Säulenwert in `?einordnung=`, `?pillar=` oder `dimension[]=` gelten für die verknüpfte Säule. +- Ausgeblendet: Die alte Dimension erscheint in keinem Editor, Filter oder in den Stammdaten. Ihre Tabellen und Zeilen bleiben als Verlauf unverändert bestehen. +- Löschschutz: Eine Säule mit zugeordneten Medien, Modulen, Programmen, Lizenzartikeln oder Seiten wird nicht gelöscht; die Meldung nennt die Zahlen. Die Säulenliste zählt alle Objektarten. +- Rechte: Modul und Programm bearbeitet nur die Redaktion, den Lizenzartikel die Redaktion mit Katalogrolle; ein Konto ohne diese Rollen erhält 403, auch über direkte Livewire-Aufrufe. +- Veröffentlichung: Anlegen und Zuordnen einer Säule veröffentlicht nichts. Die Themenseite bleibt Sache der Säulenverwaltung. + +**Übernahme der alten Zuordnungen** (`LegacyPillarAdoption`, in der Migration und mit `php artisan luf:saeulen-uebernehmen [--dry-run]`): +- Ein alter Wert gilt nur dann als Säule, wenn seine Kennung `pfeiler-` (die die Spiegelung geschrieben hat) auf eine vorhandene Säule zeigt, die nicht jünger als der Wert ist. Gleiche Nummern ohne Kennung oder ähnliche Namen genügen nicht. Die Verknüpfung steht in `editorial_dimension_values.pillar_id`; eine abweichende Bezeichnung nach einem Umbenennen wird nur berichtet. +- Übernommen werden nur direkte Zuordnungen von Modulen, Programmen und Lizenzartikeln. Wiederholte Läufe fügen nichts hinzu (insert-or-ignore, Test). +- Nicht übernommen, sondern mit Datensatz und Grund gemeldet: Werte ohne belastbare Kennung, Kennungen auf fehlende Säulen, abgeleitete Zuordnungen, Zuordnungen zu fehlenden Objekten, unbekannte Objektarten. Es wird nichts gelöscht oder geraten. +- Medien bleiben bei ihrer Zuordnung (`content_element_pillar`); die gespiegelten Zeilen sind veraltet und werden nur gezählt. +- Alte Zeilen werden nie geändert oder gelöscht. + +**Ergebnis auf luf-test:** +- 5 alte Säulenwerte sind über ihre Kennung mit den Säulen 1 bis 5 verknüpft. +- Zu übernehmen waren 0 Zuordnungen (Module und Programme 0, Lizenzartikel 0). 0 gespiegelte Medienzeilen; 3 Medienzuordnungen bestehen nur in der Medienzuordnung. +- Keine ungeklärten Fälle. +- Auf Prod hat die Kopie noch keine Werte, weil dort noch keine Säulen angelegt waren; die Migration hat dort nichts zu übernehmen. Nach dem nächsten Merge bieten Module, Programme und Lizenzartikel auf Prod die dort angelegten Säulen an (vorher gab es dort keine Auswahl). + +**Tests:** `PillarUnificationTest` (13): anlegen und bei Modul, Programm und Lizenzartikel wählen (ohne Veröffentlichung); umbenennen (Editoren, Filter, Säulenliste, Zuordnungen bleiben); andere Angaben speichern; Übernahme vollständig und wiederholbar; mehrdeutige, abgeleitete und verwaiste Fälle werden gemeldet und nicht zugeordnet; zu junge Säule; direkte und abgeleitete Zuordnung getrennt; Filter und alte Adressen; Löschschutz (Dienst und Datenbank); Rechte; Stammdaten ohne Säulenkopie; Mitgliederbibliothek; öffentliche Seiten, Fassungen und Themen unverändert. Ein Test hat dabei einen Fehler im Übernahmebericht gefunden und ist behoben. Der bisherige Test, der die alte Kopie bei Modulen erwartete, ist bewusst ersetzt. Gesamt 358 Tests grün. + +**Browser auf luf-test** (1440 × 900 und 1280 × 800): Prüfsäule „UX-Prüfung Säule“ in der Säulenverwaltung angelegt (unveröffentlicht), im Modul „UX-Prüfung Modul“ und im Lizenzartikel `abstand-trainer` gewählt und gespeichert, umbenannt, beide Objekte erneut geöffnet (neuer Name, Auswahl erhalten, alter Name weg), Arbeitsplatz nach der Säule gefiltert (1 Treffer, Filter übersteht das Neuladen), Säulenfilter im Aufbau-Picker, Löschversuch abgewiesen („1 Modul oder Programm, 1 Lizenzartikel“). Danach Zuordnungen gelöst und die Prüfsäule gelöscht. Vorher und nachher stimmen Säulen, Medien- und Seitenzuordnungen, Zähler der Fassungen und Revisionen überein; 13 öffentliche Seiten sind identisch. Die Kennungen 6 und 7 der Prüfsäulen sind verbraucht. Bilder 08 bis 12. + +**Offen:** Die alte Dimension und ihre Zeilen bleiben als Verlauf bestehen; sie ließen sich in einem späteren, eigenen Schritt entfernen. + ## Belege | | | @@ -81,4 +120,6 @@ ## Belege | ![Materialarten 1440](stammdaten/01-materialarten-1440.jpg) | ![Materialarten 1280](stammdaten/02-materialarten-1280.jpg) | | ![Zielgruppe mit Prüfwert](stammdaten/03-zielgruppe.jpg) | ![Verwendung](stammdaten/04-verwendung.jpg) | | ![Einordnung im Medium](stammdaten/05-einordnung.jpg) | ![Inaktive Zuordnung bleibt sichtbar](stammdaten/06-inaktiv.jpg) | -| ![Picker mit fachlicher Materialart](stammdaten/07-picker.jpg) | | +| ![Picker mit fachlicher Materialart](stammdaten/07-picker.jpg) | ![Säule beim Modul zuordnen](stammdaten/08-saeule-modul-zuordnen.jpg) | +| ![Säule umbenannt, Modul erneut geöffnet](stammdaten/09-saeule-modul-umbenannt.jpg) | ![Filter nach Säule bei 1280 px](stammdaten/10-saeule-filter-module-1280.jpg) | +| ![Picker mit Säulenfilter](stammdaten/11-saeule-picker.jpg) | ![Löschschutz](stammdaten/12-saeule-loeschschutz.jpg) | diff --git a/docs/ux/verwaltung/abnahme/stammdaten/08-saeule-modul-zuordnen.jpg b/docs/ux/verwaltung/abnahme/stammdaten/08-saeule-modul-zuordnen.jpg new file mode 100644 index 0000000..a1bdd4f Binary files /dev/null and b/docs/ux/verwaltung/abnahme/stammdaten/08-saeule-modul-zuordnen.jpg differ diff --git a/docs/ux/verwaltung/abnahme/stammdaten/09-saeule-modul-umbenannt.jpg b/docs/ux/verwaltung/abnahme/stammdaten/09-saeule-modul-umbenannt.jpg new file mode 100644 index 0000000..c22ea11 Binary files /dev/null and b/docs/ux/verwaltung/abnahme/stammdaten/09-saeule-modul-umbenannt.jpg differ diff --git a/docs/ux/verwaltung/abnahme/stammdaten/10-saeule-filter-module-1280.jpg b/docs/ux/verwaltung/abnahme/stammdaten/10-saeule-filter-module-1280.jpg new file mode 100644 index 0000000..beddad9 Binary files /dev/null and b/docs/ux/verwaltung/abnahme/stammdaten/10-saeule-filter-module-1280.jpg differ diff --git a/docs/ux/verwaltung/abnahme/stammdaten/11-saeule-picker.jpg b/docs/ux/verwaltung/abnahme/stammdaten/11-saeule-picker.jpg new file mode 100644 index 0000000..3e24201 Binary files /dev/null and b/docs/ux/verwaltung/abnahme/stammdaten/11-saeule-picker.jpg differ diff --git a/docs/ux/verwaltung/abnahme/stammdaten/12-saeule-loeschschutz.jpg b/docs/ux/verwaltung/abnahme/stammdaten/12-saeule-loeschschutz.jpg new file mode 100644 index 0000000..b7e3f3f Binary files /dev/null and b/docs/ux/verwaltung/abnahme/stammdaten/12-saeule-loeschschutz.jpg differ diff --git a/resources/views/filament/verwaltung/picker.blade.php b/resources/views/filament/verwaltung/picker.blade.php index 4ff3965..c6b5498 100644 --- a/resources/views/filament/verwaltung/picker.blade.php +++ b/resources/views/filament/verwaltung/picker.blade.php @@ -69,6 +69,15 @@ @endforeach @endif + @if ($zweck === 'aufbau' && ($saeulen = $this->pickerSaeulen()) !== []) + + + @endif @if ($zweck === 'aufbau' && ($dimensionen = $this->pickerDimensionGroups()) !== []) + @if ($filterPillars->isNotEmpty()) +
+ Fachliche Säulen + @foreach ($filterPillars as $pillar) + + @endforeach +
+ @endif @if ($filterDimensions->isNotEmpty()) @foreach ($filterDimensions as $dimension)
@@ -54,7 +65,7 @@ @if ($visible === 0)
- @if ($libraryEmpty && ($query ?? '') === '' && ($nutzung ?? '') === '' && $dimensionIds === []) + @if ($libraryEmpty && ($query ?? '') === '' && ($nutzung ?? '') === '' && $dimensionIds === [] && $saeuleIds === [])

Noch nichts in der Bibliothek

Unter Angebote können Sie ein kostenloses Material abrufen oder ein Angebot im Testmodus kaufen.

Zu den Angeboten

diff --git a/tests/Feature/EditorialDeskTest.php b/tests/Feature/EditorialDeskTest.php index 553b22e..24902d9 100644 --- a/tests/Feature/EditorialDeskTest.php +++ b/tests/Feature/EditorialDeskTest.php @@ -334,7 +334,7 @@ public function test_a_license_article_overrides_only_its_own_presentation(): vo $this->assertSame('leer', app(EditorialProfileReader::class)->read($ambiguous->fresh())->origin('summary')); } - public function test_content_elements_do_not_offer_the_pillar_dimension_a_second_time(): void + public function test_no_object_offers_the_legacy_pillar_dimension_any_more(): void { $pillar = Pillar::query()->create(['name' => 'Nähe', 'slug' => 'naehe', 'sort_order' => 1]); $dimension = EditorialDimension::query()->where('slug', 'saeule')->firstOrFail(); @@ -363,7 +363,7 @@ public function test_content_elements_do_not_offer_the_pillar_dimension_a_second ->where('subject_id', $film->id) ->pluck('editorial_dimension_value_id') ->all(); - $this->assertContains($value->id, $assigned); + $this->assertContains($value->id, $assigned, 'Die alte Zeile bleibt als Verlauf erhalten.'); $this->assertContains($kinder->id, $assigned); $module = $content->createComposition('Modul mit Säule'); @@ -373,8 +373,9 @@ public function test_content_elements_do_not_offer_the_pillar_dimension_a_second ]]); Livewire::test(EditExercise::class, ['record' => $module->getKey()]) ->call('openRedaktion', 'einordnung') - ->assertSee('Nähe als Dimension') - ->assertDontSee('Fachliche Säulen'); + ->assertDontSee('Nähe als Dimension') + ->assertSee('Fachliche Säulen') + ->assertSee('Nähe'); } public function test_classification_is_filterable_and_does_not_change_use_or_release(): void diff --git a/tests/Feature/PillarUnificationTest.php b/tests/Feature/PillarUnificationTest.php new file mode 100644 index 0000000..a52c36e --- /dev/null +++ b/tests/Feature/PillarUnificationTest.php @@ -0,0 +1,462 @@ +createComposition('Modul Abstand', CompositionKind::Uebung); + $program = $content->createComposition('Programm Schulweg', CompositionKind::Kurs); + $article = app(ArticleService::class)->create('artikel-abstand'); + $pillar = app(PillarService::class)->create('Meine Grenzen'); + $editor = $this->editor(); + $keeper = $this->keeper(); + + Livewire::actingAs($editor, 'staff')->test(EditExercise::class, ['record' => $module->getKey()]) + ->call('openRedaktion', 'einordnung')->assertSee('Fachliche Säulen')->assertSee('Meine Grenzen') + ->set('pillarIds', [(string) $pillar->id])->call('saveDisplay')->assertSet('feedbackError', false); + Livewire::actingAs($editor, 'staff')->test(EditCourse::class, ['record' => $program->getKey()]) + ->call('openRedaktion', 'einordnung')->assertSee('Meine Grenzen') + ->set('pillarIds', [(string) $pillar->id])->call('saveDisplay'); + Livewire::actingAs($keeper, 'staff')->test(ViewLicenseArticle::class, ['record' => $article->getKey()]) + ->call('openRedaktion', 'einordnung')->assertSee('Meine Grenzen') + ->set('pillarIds', [(string) $pillar->id])->call('saveLicenseEditorial'); + + $this->assertSame([$pillar->id], $module->fresh()->pillars->pluck('id')->all()); + $this->assertSame([$pillar->id], $program->fresh()->pillars->pluck('id')->all()); + $this->assertSame([$pillar->id], $article->fresh()->pillars->pluck('id')->all()); + $this->assertNull($pillar->fresh()->published_at, 'Anlegen und Zuordnen veröffentlicht keine Themenseite.'); + } + + public function test_renaming_a_pillar_shows_the_new_name_everywhere_and_keeps_every_assignment(): void + { + $content = app(ContentService::class); + $module = $content->createComposition('Modul Abstand', CompositionKind::Uebung); + $article = app(ArticleService::class)->create('artikel-abstand'); + $film = $content->createElement('film', 'film', 'Lara im Park'); + $pillar = app(PillarService::class)->create('Nähe'); + foreach ([$module, $article, $film] as $subject) { + app(PillarService::class)->assign($subject, [$pillar->id]); + } + $editor = $this->editor(); + $keeper = $this->keeper(); + + app(PillarService::class)->present($pillar, 'Nähe und Distanz', $pillar->slug, null, false, 0); + + Livewire::actingAs($editor, 'staff')->test(EditExercise::class, ['record' => $module->getKey()]) + ->call('openRedaktion', 'einordnung')->assertSee('Nähe und Distanz')->assertSet('pillarIds', [(string) $pillar->id]); + Livewire::actingAs($keeper, 'staff')->test(ViewLicenseArticle::class, ['record' => $article->getKey()]) + ->call('openRedaktion', 'einordnung')->assertSee('Nähe und Distanz')->assertSet('pillarIds', [(string) $pillar->id]); + Livewire::actingAs($editor, 'staff')->test(ListExercises::class)->assertOk(); + Livewire::withQueryParams(['saeule' => (string) $pillar->id])->actingAs($editor, 'staff') + ->test(ListContentElements::class)->assertSee('Lara im Park'); + Livewire::actingAs($editor, 'staff')->test(ListPillars::class)->assertSee('Nähe und Distanz')->assertSee('1 Medium, 1 Modul oder Programm, 1 Lizenzartikel'); + + $this->assertSame($pillar->id, $module->pillars()->value('pillars.id')); + $this->assertSame($pillar->id, $article->pillars()->value('pillars.id')); + $this->assertSame($pillar->id, $film->pillars()->value('pillars.id')); + } + + public function test_saving_other_details_keeps_the_pillar_assignments(): void + { + $content = app(ContentService::class); + $module = $content->createComposition('Modul Abstand', CompositionKind::Uebung); + $article = app(ArticleService::class)->create('artikel-abstand'); + $first = app(PillarService::class)->create('Eins'); + $second = app(PillarService::class)->create('Zwei'); + app(PillarService::class)->assign($module, [$first->id, $second->id]); + app(PillarService::class)->assign($article, [$second->id]); + $editor = $this->editor(); + $keeper = $this->keeper(); + + Livewire::actingAs($editor, 'staff')->test(EditExercise::class, ['record' => $module->getKey()]) + ->set('teaser', 'Nur der Teaser ändert sich.')->call('saveDisplay'); + Livewire::actingAs($keeper, 'staff')->test(ViewLicenseArticle::class, ['record' => $article->getKey()]) + ->call('openRedaktion')->set('summary', 'Nur die Beschreibung ändert sich.')->call('saveLicenseEditorial'); + + $this->assertEqualsCanonicalizing([$first->id, $second->id], $module->fresh()->pillars->pluck('id')->all()); + $this->assertSame([$second->id], $article->fresh()->pillars->pluck('id')->all()); + $this->assertSame('Nur der Teaser ändert sich.', $module->fresh()->teaser); + + // Gezieltes Abwählen entfernt genau diese Säule. + Livewire::actingAs($editor, 'staff')->test(EditExercise::class, ['record' => $module->getKey()]) + ->set('pillarIds', [(string) $second->id])->call('saveDisplay'); + $this->assertSame([$second->id], $module->fresh()->pillars->pluck('id')->all()); + } + + public function test_the_adoption_carries_every_direct_assignment_over_and_is_repeatable(): void + { + $content = app(ContentService::class); + $module = $content->createComposition('Modul Abstand', CompositionKind::Uebung); + $program = $content->createComposition('Programm Schulweg', CompositionKind::Kurs); + $article = app(ArticleService::class)->create('artikel-abstand'); + $film = $content->createElement('film', 'film', 'Lara im Park'); + $nahe = Pillar::query()->create(['name' => 'Nähe', 'slug' => 'naehe']); + $mut = Pillar::query()->create(['name' => 'Mut', 'slug' => 'mut']); + $nahe->refresh(); + $nearValue = $this->legacyValue($nahe, 'Nähe'); + $courageValue = $this->legacyValue($mut, 'Mut (alter Name)'); + $identity = app(IdentityDimension::class); + $identity->assign($module, $nearValue); + $identity->assign($module, $courageValue); + $identity->assign($program, $nearValue); + $identity->assign($article, $courageValue); + $identity->assign($film, $nearValue); + // Medien: maßgeblich ist die Medienzuordnung, die Spiegelzeile wird nicht zurückgemischt. + app(PillarService::class)->assign($film, [$mut->id]); + $legacyBefore = IdentityDimensionValue::query()->count(); + + $report = (new LegacyPillarAdoption)->run(); + + $this->assertEqualsCanonicalizing([$nahe->id, $mut->id], $module->pillars()->pluck('pillars.id')->all()); + $this->assertSame([$nahe->id], $program->pillars()->pluck('pillars.id')->all()); + $this->assertSame([$mut->id], $article->pillars()->pluck('pillars.id')->all()); + $this->assertSame([$mut->id], $film->pillars()->pluck('pillars.id')->all(), 'Die Medienzuordnung bleibt maßgeblich.'); + $this->assertSame(['composition' => 3, 'license_article' => 1], $report['copied']); + $this->assertSame([], $report['unresolved']); + $this->assertSame($nahe->id, $nearValue->fresh()->pillar_id); + $this->assertSame($mut->id, $courageValue->fresh()->pillar_id); + $this->assertSame($legacyBefore, IdentityDimensionValue::query()->count(), 'Alte Zeilen bleiben unverändert erhalten.'); + $this->assertSame(1, $report['mirror']['element_rows'], 'Eine gespiegelte Medienzeile wird nur gezählt.'); + $this->assertSame(1, $report['mirror']['missing_in_pivot']); + $this->assertTrue(collect($report['mapping'])->contains(fn (array $row): bool => $row['wert_id'] === $courageValue->id && str_contains((string) $row['hinweis'], 'Bezeichnung weicht ab'))); + + $again = (new LegacyPillarAdoption)->run(); + $this->assertSame(['composition' => 0, 'license_article' => 0], $again['copied']); + $this->assertSame(['composition' => 3, 'license_article' => 1], $again['already']); + $this->assertSame(4, DB::table('composition_pillar')->count() + DB::table('license_article_pillar')->count()); + + $dry = (new LegacyPillarAdoption)->run(dryRun: true); + $this->assertSame(4, $dry['before']['composition'] + $dry['before']['license_article']); + } + + public function test_ambiguous_old_values_are_reported_and_never_assigned_by_guessing(): void + { + $content = app(ContentService::class); + $module = $content->createComposition('Modul Abstand', CompositionKind::Uebung); + $program = $content->createComposition('Programm Schulweg', CompositionKind::Kurs); + $article = app(ArticleService::class)->create('artikel-abstand'); + $film = $content->createElement('film', 'film', 'Lara im Park'); + $nahe = Pillar::query()->create(['name' => 'Nähe', 'slug' => 'naehe']); + $good = $this->legacyValue($nahe, 'Nähe'); + // Gleicher Name, aber ohne Kennung zur Säule: ähnlich klingend ist kein Nachweis. + $sameName = $this->legacyValue($nahe, 'Nähe', slug: 'naehe-kopie'); + // Kennung verweist auf eine Säule, die es nicht mehr gibt. + $gone = $this->legacyValue($nahe, 'Verschwunden', slug: 'pfeiler-9999'); + $identity = app(IdentityDimension::class); + $identity->assign($module, $good); + $identity->assign($module, $sameName); + $identity->assign($program, $gone); + $identity->assign($article, $good, 'abgeleitet'); + $identity->assign($film, $sameName); + DB::table('identity_dimension_values')->insert([ + 'subject_type' => $module->getMorphClass(), 'subject_id' => 99999, 'editorial_dimension_value_id' => $good->id, + 'origin' => 'direkt', 'created_at' => now(), 'updated_at' => now(), + ]); + + $report = (new LegacyPillarAdoption)->run(); + + $this->assertSame([$nahe->id], $module->pillars()->pluck('pillars.id')->all(), 'Nur der belastbare Wert wird übernommen.'); + $this->assertSame([], $program->pillars()->pluck('pillars.id')->all()); + $this->assertSame([], $article->pillars()->pluck('pillars.id')->all(), 'Eine abgeleitete Zuordnung wird nicht zur direkten.'); + $this->assertNull($sameName->fresh()->pillar_id); + $this->assertNull($gone->fresh()->pillar_id); + $reasons = collect($report['unresolved'])->pluck('grund')->implode(' | '); + $this->assertStringContainsString('keine belastbare Verknüpfung', $reasons); + $this->assertStringContainsString('existiert nicht mehr', $reasons); + $this->assertStringContainsString('abgeleitete Zuordnung', $reasons); + $this->assertStringContainsString('Objekt nicht mehr vorhanden', $reasons); + $this->assertStringContainsString('Wert ohne belastbare Säule', $reasons); + $lines = implode("\n", LegacyPillarAdoption::lines($report)); + $this->assertStringContainsString('Ungeklärt, bitte entscheiden', $lines); + $this->assertStringContainsString('naehe-kopie', $lines); + $this->assertSame(1, DB::table('identity_dimension_values')->where('origin', 'abgeleitet')->count(), 'Nichts wurde gelöscht.'); + + $this->artisan('luf:saeulen-uebernehmen', ['--dry-run' => true])->assertFailed(); + } + + public function test_a_pillar_younger_than_the_old_value_is_not_a_reliable_reference(): void + { + Carbon::setTestNow('2026-11-16 08:00:00'); + $value = $this->legacyValue(Pillar::query()->create(['name' => 'Alt', 'slug' => 'alt']), 'Alt', slug: 'pfeiler-2'); + Carbon::setTestNow('2026-11-20 08:00:00'); + Pillar::query()->create(['id' => 2, 'name' => 'Später angelegt', 'slug' => 'spaeter']); + + $report = (new LegacyPillarAdoption)->run(); + + $this->assertNull($value->fresh()->pillar_id); + $this->assertStringContainsString('jünger', (string) ($report['unresolved'][0]['grund'] ?? '')); + } + + public function test_direct_and_derived_pillars_keep_their_own_meaning(): void + { + $content = app(ContentService::class); + $film = $content->publishElementVersion($content->createElement('film', 'film', 'Hofszene'), null, ['file' => 'inhalte/hof.mp4']); + $module = $content->createComposition('Modul Hof', CompositionKind::Uebung); + $content->publishComposition($module, [['role' => 'Film', 'target' => $film]]); + $fromMedia = app(PillarService::class)->create('Aus dem Medium'); + $direct = app(PillarService::class)->create('Direkt am Modul'); + app(PillarService::class)->assign($film->element, [$fromMedia->id]); + app(PillarService::class)->assign($module, [$direct->id]); + + $derived = app(CatalogReading::class)->memberPillars($module); + $this->assertSame(['Hofszene — Aus dem Medium'], array_map(fn (string $line): string => str_replace('Film: ', '', $line), $derived)); + $this->assertSame([$direct->id], $module->pillars()->pluck('pillars.id')->all(), 'Die Säule des Mediums wird nicht zur direkten Zuordnung des Moduls.'); + + $editor = $this->editor(); + Livewire::withQueryParams(['saeule' => (string) $fromMedia->id])->actingAs($editor, 'staff') + ->test(ListExercises::class)->assertDontSee('Modul Hof'); + Livewire::withQueryParams(['saeule' => (string) $direct->id])->actingAs($editor, 'staff') + ->test(ListExercises::class)->assertSee('Modul Hof'); + } + + public function test_filters_find_exactly_the_assigned_objects_and_old_addresses_follow_the_pillar(): void + { + $content = app(ContentService::class); + $withPillar = $content->createComposition('Mit Säule', CompositionKind::Uebung); + $content->createComposition('Ohne Säule', CompositionKind::Uebung); + $pillar = Pillar::query()->create(['name' => 'Nähe', 'slug' => 'naehe']); + $value = $this->legacyValue($pillar, 'Nähe'); + app(PillarService::class)->assign($withPillar, [$pillar->id]); + (new LegacyPillarAdoption)->run(); + $editor = $this->editor(); + + Livewire::withQueryParams(['saeule' => (string) $pillar->id])->actingAs($editor, 'staff')->test(ListExercises::class) + ->assertSee('Mit Säule')->assertDontSee('Ohne Säule'); + // Alte Adresse mit dem früheren Säulenwert der Einordnung. + Livewire::withQueryParams(['pillar' => (string) $value->id])->actingAs($editor, 'staff')->test(ListExercises::class) + ->assertSet('saeule', (string) $pillar->id)->assertSet('pillar', '')->assertSee('Mit Säule')->assertDontSee('Ohne Säule'); + Livewire::withQueryParams(['einordnung' => (string) $value->id])->actingAs($editor, 'staff')->test(ListContentElements::class) + ->assertSet('saeule', (string) $pillar->id)->assertSet('einordnung', ''); + + // Der Picker im Aufbau filtert Medien und Module nach der Säule. + $film = $content->publishElementVersion($content->createElement('film', 'film', 'Film mit Säule'), 'Film'); + $content->publishElementVersion($content->createElement('film', 'film', 'Film ohne Säule'), 'Film'); + app(PillarService::class)->assign($film->element, [$pillar->id]); + $picker = Livewire::actingAs($editor, 'staff')->test(EditExercise::class, ['record' => $withPillar->getKey()]) + ->call('openPicker'); + $this->assertSame($pillar->name, $picker->instance()->pickerSaeulen()[(string) $pillar->id]); + $ids = fn (array $items): array => array_column($items, 'title'); + $picker->set('pickerKind', 'film'); + $this->assertContains('Film ohne Säule', $ids($picker->instance()->pickerResult()['items']), 'Ohne Filter erscheinen beide.'); + $picker->set('pickerSaeule', (string) $pillar->id); + $this->assertSame(['Film mit Säule'], array_values(array_filter($ids($picker->instance()->pickerResult()['items']), fn ($t) => str_starts_with((string) $t, 'Film ')))); + } + + public function test_a_used_pillar_cannot_be_deleted_by_the_service_or_the_database(): void + { + $content = app(ContentService::class); + $service = app(PillarService::class); + $module = $content->createComposition('Modul Abstand', CompositionKind::Uebung); + $article = app(ArticleService::class)->create('artikel-abstand'); + $byModule = $service->create('Durch Modul'); + $byArticle = $service->create('Durch Artikel'); + $service->assign($module, [$byModule->id]); + $service->assign($article, [$byArticle->id]); + + foreach ([$byModule, $byArticle] as $pillar) { + try { + $service->delete($pillar); + $this->fail('Eine verwendete Säule darf nicht gelöscht werden.'); + } catch (DomainRuleException $exception) { + $this->assertStringContainsString('zugeordneten Objekten', $exception->getMessage()); + } + } + + $this->assertStringContainsString('1 Modul oder Programm', $service->usageText($service->usage($byModule))); + $this->assertStringContainsString('1 Lizenzartikel', $service->usageText($service->usage($byArticle))); + + // Auch ein Zugriff an der Anwendung vorbei scheitert in der Datenbank. + $this->expectException(QueryException::class); + DB::table('pillars')->where('id', $byModule->id)->delete(); + } + + public function test_pillar_assignment_follows_the_editorial_permissions(): void + { + $content = app(ContentService::class); + $module = $content->createComposition('Modul Abstand', CompositionKind::Uebung); + $article = app(ArticleService::class)->create('artikel-abstand'); + $pillar = app(PillarService::class)->create('Nähe'); + $moderator = User::factory()->systemverwalter()->create(); + $moderator->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP'); + + Livewire::actingAs($moderator, 'staff')->test(EditExercise::class, ['record' => $module->getKey()])->assertForbidden(); + Livewire::actingAs($moderator, 'staff')->test(ViewLicenseArticle::class, ['record' => $article->getKey()])->assertForbidden(); + Livewire::actingAs($moderator, 'staff')->test(ListPillars::class)->assertForbidden(); + $this->assertSame([], $module->pillars()->pluck('pillars.id')->all()); + $this->assertNotNull($pillar->fresh()); + } + + public function test_the_stammdaten_workplace_points_to_the_pillar_management_and_offers_no_pillar_copy(): void + { + Livewire::actingAs($this->editor(), 'staff')->test(RedaktionelleStammdaten::class) + ->assertSee('Fachliche Säulen') + ->assertSee(route('filament.verwaltung.resources.saeulen.index', [], false), false); + + $this->assertArrayNotHasKey(EditorialDimension::PILLAR_SLUG, (new RedaktionelleStammdaten)->gruppen()); + foreach ([Composition::class, LicenseArticle::class] as $class) { + $this->assertNotContains(EditorialDimension::PILLAR_SLUG, EditorialDimension::forSubject(new $class)->pluck('slug')->all()); + } + $vocabulary = app(EditorialVocabulary::class); + $this->legacyValue(Pillar::query()->create(['name' => 'Nähe', 'slug' => 'naehe']), 'Nähe'); + $this->assertNotContains('Fachliche Säule', array_column($vocabulary->dimensionFilterGroups(), 'label')); + $this->assertNotContains('Fachliche Säule', $vocabulary->memberFilterDimensions()->pluck('label')->all()); + } + + public function test_the_member_library_filters_by_direct_pillars_and_lists_only_used_ones(): void + { + $content = app(ContentService::class); + $film = $content->publishElementVersion($content->createElement('film', 'film', 'Hofszene'), null, ['file' => 'inhalte/hof.mp4']); + $withPillar = $content->publishComposition($content->createComposition('Schulweg mit Säule'), [['role' => 'Film', 'target' => $film]]); + $without = $content->publishComposition($content->createComposition('Schulweg ohne Säule'), [['role' => 'Film', 'target' => $film]]); + $pillar = app(PillarService::class)->create('Sicher unterwegs'); + $unused = app(PillarService::class)->create('Noch ohne Zuordnung'); + app(PillarService::class)->assign($withPillar->composition, [$pillar->id]); + + $articles = app(ArticleService::class); + $offers = app(OfferService::class); + $rights = $offers->createRightsProfile('Film', 'ehrenamtlich', ['film' => ['streamen']]); + $offer = $offers->create('Zugang'); + $items = []; + foreach ([[$withPillar, 'mit'], [$without, 'ohne']] as [$version, $code]) { + $article = $articles->create($code); + $articles->publishRelease($article, $version, 'Text'); + $items[] = ['target' => $article->fresh(), 'rights' => $rights]; + } + $offers->activate($offer, $items, ['grant_kind' => 'auf_abruf']); + $member = User::factory()->create(); + app(GrantIssuer::class)->claim($member, $offer); + foreach ([$withPillar, $without] as $version) { + app(CompositionDisplayRelease::class)->release($version, $member); + } + + $this->actingAs($member)->get(route('member.library')) + ->assertOk()->assertSee('Schulweg mit Säule')->assertSee('Schulweg ohne Säule') + ->assertSee('Fachliche Säulen')->assertSee('Sicher unterwegs')->assertDontSee('Noch ohne Zuordnung'); + $this->actingAs($member)->get(route('member.library', ['saeule' => [$pillar->id]])) + ->assertOk()->assertSee('Schulweg mit Säule')->assertDontSee('Schulweg ohne Säule'); + $this->assertNotNull($unused->fresh()); + } + + public function test_published_pages_and_saved_versions_stay_unchanged_by_the_adoption(): void + { + $content = app(ContentService::class); + $film = $content->publishElementVersion($content->createElement('film', 'film', 'Hofszene'), null, ['file' => 'inhalte/hof.mp4']); + $module = $content->createComposition('Modul Hof', CompositionKind::Uebung); + $version = $content->publishComposition($module, [['role' => 'Film', 'target' => $film]]); + $pillar = Pillar::query()->create(['name' => 'Nähe', 'slug' => 'naehe', 'published_at' => null]); + $theme = Pillar::query()->create(['name' => 'Veröffentlicht', 'slug' => 'oeffentlich', 'published_at' => now()]); + $page = Page::query()->where('path', '/praevention')->firstOrFail(); + app(PillarService::class)->assignPages($page, [$theme->id]); + app(IdentityDimension::class)->assign($module, $this->legacyValue($pillar, 'Nähe')); + + $before = [ + 'seite' => $this->page('/praevention'), + 'thema' => $this->page('/themen/oeffentlich'), + 'fassungen' => DB::table('composition_versions')->orderBy('id')->get()->toJson(), + 'revisionen' => DB::table('page_revisions')->orderBy('id')->get()->toJson(), + 'themen' => DB::table('pillars')->orderBy('id')->get(['id', 'name', 'slug', 'published_at'])->toJson(), + 'freigaben' => DB::table('article_releases')->count(), + ]; + + (new LegacyPillarAdoption)->run(); + + $this->assertSame($before['seite'], $this->page('/praevention')); + $this->assertSame($before['thema'], $this->page('/themen/oeffentlich')); + $this->assertSame($before['fassungen'], DB::table('composition_versions')->orderBy('id')->get()->toJson()); + $this->assertSame($before['revisionen'], DB::table('page_revisions')->orderBy('id')->get()->toJson()); + $this->assertSame($before['themen'], DB::table('pillars')->orderBy('id')->get(['id', 'name', 'slug', 'published_at'])->toJson(), 'Die Übernahme veröffentlicht nichts.'); + $this->assertSame($before['freigaben'], DB::table('article_releases')->count()); + $this->assertSame([$pillar->id], $module->pillars()->pluck('pillars.id')->all()); + $this->assertNotNull($version); + } + + private function legacyValue(Pillar $pillar, string $label, ?string $slug = null): EditorialDimensionValue + { + $dimension = EditorialDimension::query()->where('slug', EditorialDimension::PILLAR_SLUG)->firstOrFail(); + + return EditorialDimensionValue::query()->create([ + 'editorial_dimension_id' => $dimension->id, + 'slug' => $slug ?? 'pfeiler-'.$pillar->id, + 'label' => $label, + ]); + } + + private function keeper(): User + { + $keeper = User::factory()->redakteur()->katalogverwalter()->create(); + $keeper->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP'); + + return $keeper; + } + + /** Seiten ohne Vorladehinweise der Schriften, die ein zweiter Aufruf im selben Test weglässt. */ + private function page(string $path): string + { + return preg_replace('/]*>\s*/', '', (string) $this->get($path)->getContent()); + } + + private function editor(): User + { + $editor = User::factory()->redakteur()->create(); + $editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP'); + + return $editor; + } +}