diff --git a/Internal/de/PROJECT_CONTEXT.md b/Internal/de/PROJECT_CONTEXT.md index e7721d8..224af1e 100644 --- a/Internal/de/PROJECT_CONTEXT.md +++ b/Internal/de/PROJECT_CONTEXT.md @@ -54,6 +54,7 @@ Papa-Kind-Treff ist eine PHP-basierte Plattform für Väter. Kernbereiche sind l - Kategorien liegen nicht mehr unter `System`, sondern in einem eigenen Mitgliederbereichspunkt `Kategorien`; dort werden nur neue Kategorien angezeigt und per Vorschlagsfeld mit bestehenden Kategorien aus der Datenbank zusammengeführt. - Neue Kategorien bleiben dort sichtbar, bis sie von einem Berechtigten bestätigt oder mit einer bestehenden Kategorie zusammengeführt werden. - Im Bereich `Kategorien` gibt es zusätzlich eine Suche über bestehende Kategorien, damit sie gezielt gefunden und zusammengeführt werden können. +- Beim Zusammenführen wird die nicht zu behaltende Kategorie anschließend vollständig entfernt und die Ansicht danach frisch neu geladen. - Beim Zusammenführen kann explizit festgelegt werden, welche der beiden Kategorien erhalten bleibt. - Community-Level können zusätzlich die Rechte für Kategorien sowie für die Freigabe von Orten und Veranstaltungen tragen. diff --git a/Internal/en/PROJECT_CONTEXT.md b/Internal/en/PROJECT_CONTEXT.md index 0dd205d..4d28a3c 100644 --- a/Internal/en/PROJECT_CONTEXT.md +++ b/Internal/en/PROJECT_CONTEXT.md @@ -54,6 +54,7 @@ Papa-Kind-Treff is a PHP-based platform for fathers. Core areas are local events - Categories no longer live under `System`, but in their own member-area section `Categories`; that area only shows newly created categories and merges them into existing database categories through a suggestion field. - New categories remain visible there until an authorized user confirms them or merges them into an existing category. - The `Categories` area also includes a search across existing categories so they can be found and merged directly. +- During merging, the category that should not be kept is removed completely and the view is reloaded fresh afterwards. - During merging, it is now possible to explicitly choose which of the two categories should be kept. - Community levels can now additionally carry the rights for category handling as well as place and event approvals. diff --git a/README.md b/README.md index 99f5ce7..7ff7f7b 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ Papa-Kind-Treff ist eine PHP-basierte Plattform für Väter mit Fokus auf: - Kategorien wurden aus `System` in den eigenen Mitgliederbereichspunkt `Kategorien` verschoben; dort werden nur neue Kategorien angezeigt und per Vorschlagsfeld mit bestehenden Kategorien aus der Datenbank zusammengeführt - Neue Kategorien bleiben im Bereich `Kategorien` sichtbar, bis sie von einem Berechtigten bestätigt oder zusammengeführt werden - Im Bereich `Kategorien` gibt es zusätzlich eine Suche über bestehende Kategorien, damit sie gezielt gefunden und zusammengeführt werden können +- Beim Zusammenführen wird die nicht zu behaltende Kategorie anschließend vollständig entfernt und die Ansicht danach frisch neu geladen - Beim Zusammenführen von Kategorien kann jetzt explizit festgelegt werden, welche der beiden Kategorien erhalten bleibt - Community-Level können jetzt zusätzlich die Rechte für Kategorien sowie für die Freigabe von Orten und Veranstaltungen tragen - neue interne Grundstruktur: `listing_places`, `listings`, `listing_occurrences`, `listing_prices`, `listing_benefits` diff --git a/src/App/AccountPages.php b/src/App/AccountPages.php index f79c260..4034be7 100755 --- a/src/App/AccountPages.php +++ b/src/App/AccountPages.php @@ -351,13 +351,15 @@ final class AccountPages $sourceCategorySlug, $targetCategorySlug ); - $info = 'Kategorie zusammengeführt.'; + $app->flash()->set('success', 'Kategorie zusammengeführt.'); + redirect('/dashboard?section=categories'); } elseif ($action === 'category_confirm') { if (!$canManageCategories || !$listingCatalog) { throw new \RuntimeException('Keine Berechtigung für die Kategorien-Verwaltung.'); } $listingCatalog->confirmCategory((string)($_POST['source_category_slug'] ?? '')); - $info = 'Kategorie bestätigt.'; + $app->flash()->set('success', 'Kategorie bestätigt.'); + redirect('/dashboard?section=categories'); } elseif ($action === 'child_add' || $action === 'child_update') { $crypto = self::requireCrypto($crypto, 'Kinder'); $childId = (int)($_POST['child_id'] ?? 0); diff --git a/src/App/ListingCatalog.php b/src/App/ListingCatalog.php index d46578b..99602be 100644 --- a/src/App/ListingCatalog.php +++ b/src/App/ListingCatalog.php @@ -385,7 +385,7 @@ final class ListingCatalog throw new \RuntimeException('Bitte zwei unterschiedliche Kategorien auswählen.'); } - $lookup = $this->pdo->prepare('SELECT id, slug FROM listing_categories WHERE slug = :slug LIMIT 1'); + $lookup = $this->pdo->prepare('SELECT id, slug, title FROM listing_categories WHERE slug = :slug LIMIT 1'); $lookup->execute(['slug' => $sourceSlug]); $source = $lookup->fetch(\PDO::FETCH_ASSOC); $lookup->execute(['slug' => $targetSlug]); @@ -396,6 +396,7 @@ final class ListingCatalog $sourceId = (int)$source['id']; $targetId = (int)$target['id']; + $sourceTitle = (string)($source['title'] ?? ''); $this->pdo->beginTransaction(); try { @@ -420,7 +421,23 @@ final class ListingCatalog 'target' => $targetSlug, 'source' => $sourceSlug, ]); - $this->pdo->prepare('DELETE FROM listing_categories WHERE id = :id')->execute(['id' => $sourceId]); + $deleteCategory = $this->pdo->prepare('DELETE FROM listing_categories WHERE id = :id'); + $deleteCategory->execute(['id' => $sourceId]); + + $verifyStmt = $this->pdo->prepare( + 'SELECT COUNT(*) + FROM listing_categories + WHERE id = :id OR slug = :slug OR (LOWER(title) = LOWER(:title) AND id <> :targetId)' + ); + $verifyStmt->execute([ + 'id' => $sourceId, + 'slug' => $sourceSlug, + 'title' => $sourceTitle, + 'targetId' => $targetId, + ]); + if ((int)$verifyStmt->fetchColumn() > 0) { + throw new \RuntimeException('Die alte Kategorie konnte nicht vollständig entfernt werden.'); + } $this->pdo->commit(); } catch (\Throwable $e) { if ($this->pdo->inTransaction()) {