Skip to content

Commit

Permalink
Url-Addon-Einträge löschen verbessert
Browse files Browse the repository at this point in the history
  • Loading branch information
christophboecker committed Aug 21, 2024
1 parent 6f6896c commit bca4b58
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
6 changes: 4 additions & 2 deletions install.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use rex_path;
use rex_sql;
use rex_yform_manager_table_api;
use Url\Profile;

/** @var rex_addon $this */

Expand Down Expand Up @@ -86,16 +87,17 @@
*/
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()) {
$this->includeFile(__DIR__ . '/install/url_profile_category.php', $subScriptParams);
}

// 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()) {
Expand Down
31 changes: 28 additions & 3 deletions uninstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit bca4b58

Please sign in to comment.