From bca4b589090617f222658fa3090dd37637e47369 Mon Sep 17 00:00:00 2001 From: christophboecker Date: Wed, 21 Aug 2024 11:43:46 +0200 Subject: [PATCH] =?UTF-8?q?=20Url-Addon-Eintr=C3=A4ge=20l=C3=B6schen=20ver?= =?UTF-8?q?bessert?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- install.php | 6 ++++-- uninstall.php | 31 ++++++++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/install.php b/install.php index befcd45..31a41a0 100644 --- a/install.php +++ b/install.php @@ -12,6 +12,7 @@ use rex_path; use rex_sql; use rex_yform_manager_table_api; +use Url\Profile; /** @var rex_addon $this */ @@ -86,8 +87,9 @@ */ if (rex_addon::get('url')->isAvailable()) { if (false === rex_config::get('neues', 'url_profile', false)) { + $urlProfileTable = rex::getTable(Profile::TABLE_NAME); // Category - $sql->setTable(rex::getTable('url_generator_profile')); + $sql->setTable($urlProfileTable); $sql->setWhere('table_name = :tn', [':tn' => '1_xxx_rex_neues_category']); $sql->select(); if (0 === $sql->getRows()) { @@ -95,7 +97,7 @@ } // Entry - $sql->setTable(rex::getTable('url_generator_profile')); + $sql->setTable($urlProfileTable); $sql->setWhere('table_name = :tn', [':tn' => '1_xxx_rex_neues_entry']); $sql->select(); if (0 === $sql->getRows()) { diff --git a/uninstall.php b/uninstall.php index 06cc1cd..c11f592 100644 --- a/uninstall.php +++ b/uninstall.php @@ -15,6 +15,8 @@ */ use FriendsOfRedaxo\Neues\Cronjob\Publish; +use Url\Cache; +use Url\Profile; /** * Url-Parameter nscope auswerten: unbekannt oder ungültig lösen die @@ -63,9 +65,32 @@ } try { - $sql->setTable(rex::getTable('url_generator_profile')); - $sql->setWhere('table_name LIKE :tn', [':tn' => '1_xxx_rex_neues_%']); - $sql->delete(); + /** + * In enger Anlehnung an den Originalcode (Profil-Löschen) in der Datei + * «pages/generator.profiles.php» des Url-Addons. + * Siehe: if ($func == 'delete' && $id > 0) usw. + * + * Funktioniert nur bei aktiviertem Url-Addon. Bei deaktiviertem Url-Addon + * bleiben die Einträge erhalten. + */ + $urlProfileTable = rex::getTable(Profile::TABLE_NAME); + + $profiles = $sql->setTable($urlProfileTable) + ->setWhere('table_name LIKE :tn', [':tn' => '1_xxx_rex_neues_%']) + ->select('id') + ->getArray(fetchType: PDO::FETCH_COLUMN); + + foreach ($profiles as $profileId) { + $profile = Profile::get($profileId); + if (null !== $profile) { + $profile->deleteUrls(); + } + $sql->setTable($urlProfileTable) + ->setWhere('id = :id', ['id' => $profileId]) + ->delete(); + } + + Cache::deleteProfiles(); } catch (Throwable $th) { // void; falls rex_url_generator_profile nicht existiert / Url-Addon fehlt }