From cda26947f28bd364b220837e13cb4dd2de946f23 Mon Sep 17 00:00:00 2001 From: Oliver Rasche Date: Wed, 11 Nov 2026 10:59:02 +0100 Subject: [PATCH] Ordner mit genau einer Uebersichtsseite leiten auf diese (RF Gateway, AV over IP & KVM) Nachtrag zu 1b72e65 (Vorschlag Content-Import-Session): statt /products zeigen die Redirects der Ordner rf-gateway und av-over-ip-and-kvm samt ihrer Alt-URL-Redirects auf /products/avedia-modular-system bzw. /products/aligo. Migration folder_redirect_targets_20261111 (angewendet). Co-Authored-By: Claude Fable 5.1 --- .../folder_redirect_targets_20261111.php | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 migrations/folder_redirect_targets_20261111.php diff --git a/migrations/folder_redirect_targets_20261111.php b/migrations/folder_redirect_targets_20261111.php new file mode 100644 index 0000000..911bca6 --- /dev/null +++ b/migrations/folder_redirect_targets_20261111.php @@ -0,0 +1,55 @@ + Avedia Modular System, AV over IP & KVM -> Aligo). + * Applies to the folder's own redirects and to older redirects that were + * pointed at /products in the previous step because they targeted the folder. + * + * Dry run: php migrations/folder_redirect_targets_20261111.php + * Write: php migrations/folder_redirect_targets_20261111.php --apply + */ + +error_reporting(E_ALL); +ini_set('display_errors', '1'); + +$apply = in_array('--apply', $argv, true); + +$root = null; +$dir = __DIR__; +for ($i = 0; $i < 5; $i++) { + if (is_file($dir . '/config/system/settings.php')) { $root = $dir; break; } + $dir = dirname($dir); +} +if ($root === null) { exit("no project root\n"); } +$settings = require $root . '/config/system/settings.php'; +$db = $settings['DB']['Connections']['Default']; +$pdo = new PDO( + sprintf('mysql:host=%s;port=%s;dbname=%s;charset=utf8mb4', $db['host'] ?? 'localhost', $db['port'] ?? 3306, $db['dbname'] ?? ''), + $db['user'] ?? '', $db['password'] ?? '', + [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC] +); + +echo $apply ? "== APPLY ==\n" : "== DRY RUN (add --apply to write) ==\n"; + +// Older redirects (sys_redirect uid) that targeted the folder before the previous step. +$legacyByFolder = [566 => [34, 124, 125], 590 => [63, 66]]; +$n = 0; +foreach ($pdo->query("SELECT uid, slug, title FROM pages WHERE deleted = 0 AND hidden = 0 AND doktype = 254 AND slug LIKE '/products/%' ORDER BY slug") as $folder) { + $children = $pdo->query("SELECT uid, slug, title FROM pages WHERE deleted = 0 AND hidden = 0 AND doktype = 1 AND pid = {$folder['uid']}")->fetchAll(); + if (count($children) !== 1) { continue; } + $target = $children[0]['slug']; + printf(" Ordner #%d %s -> einzige Seite #%d %s\n", $folder['uid'], $folder['slug'], $children[0]['uid'], $target); + $uids = $legacyByFolder[(int)$folder['uid']] ?? []; + $st = $pdo->prepare("SELECT uid, source_path, target FROM sys_redirect WHERE deleted = 0 AND target = '/products' AND (source_path = ? OR source_path = ?" . ($uids ? ' OR uid IN (' . implode(',', array_map('intval', $uids)) . ')' : '') . ")"); + $st->execute([$folder['slug'], $folder['slug'] . '/']); + foreach ($st->fetchAll() as $r) { + printf(" redirect #%-4d %-55s /products -> %s\n", $r['uid'], $r['source_path'], $target); + $n++; + if ($apply) { $pdo->prepare("UPDATE sys_redirect SET target = ?, updatedon = UNIX_TIMESTAMP() WHERE uid = ?")->execute([$target, (int)$r['uid']]); } + } +} +echo "\n$n Redirect(s) " . ($apply ? 'umgebogen' : 'wuerden umgebogen') . ".\n";