Files
VITEC-website/migrations/fix_why_band_position.php
T
orascheandClaude Fable 5 ad1f3c179c why-vitec band: move it before the "Product range" intro
- new migration fix_why_band_position.php: on the 7 overview pages the
  band (Why VITEC? intro + icon cards) had landed between the "Product
  range" heading and its product cards; reorders the top-level column
  to hero -> band -> Product range -> cards (ticket 0042-FE section 3)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-11-04 20:51:42 +01:00

135 lines
4.4 KiB
PHP

<?php
/**
* fix_why_band_position.php (2026-11-04)
*
* Verschiebt das "Why VITEC?"-Band (introparagraph + folgende icon_card-
* Elemente aus vitec:build-why-vitec-bands) auf den 7 Produkt-Uebersichts-
* seiten VOR das "Product range"-Intro. Der Band-Lauf hatte es dahinter
* einsortiert und damit die Ueberschrift von ihren Produktkarten getrennt
* (Arne, 0042-FE Abschnitt 3).
*
* Soll: Hero -> Why-VITEC-Band -> "Product range" -> Produktkarten.
*
* php migrations/fix_why_band_position.php # INSPECT (default)
* php migrations/fix_why_band_position.php --apply # schreibt
*/
declare(strict_types=1);
$apply = in_array('--apply', $argv, true);
$settings = require __DIR__ . '/../config/system/settings.php';
$db = $settings['DB']['Connections']['Default'];
$pdo = new PDO(
sprintf('mysql:host=%s;dbname=%s;charset=utf8mb4', $db['host'], $db['dbname']),
$db['user'],
$db['password'],
[PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]
);
echo $apply ? "APPLY\n\n" : "INSPECT - nichts wird geschrieben (--apply zum Schreiben)\n\n";
$slugs = [
'/products/activesqx',
'/products/aetria',
'/products/aligo',
'/products/avedia-modular-system',
'/products/image-graphics-cards',
'/products/operator-workstations',
'/products/prism-transcoder',
];
$moved = 0;
foreach ($slugs as $slug) {
$page = $pdo->prepare('SELECT uid, title FROM pages WHERE deleted = 0 AND slug = ?');
$page->execute([$slug]);
$page = $page->fetch(PDO::FETCH_ASSOC);
if ($page === false) {
echo "$slug: Seite NICHT gefunden - uebersprungen\n\n";
continue;
}
$pid = (int)$page['uid'];
$stmt = $pdo->prepare(
'SELECT uid, CType, header, sorting, hidden FROM tt_content
WHERE pid = ? AND deleted = 0 AND colPos = 0
AND (tx_container_parent IS NULL OR tx_container_parent = 0)
ORDER BY sorting, uid'
);
$stmt->execute([$pid]);
$elements = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Band finden: "Why VITEC?"-Intro + direkt folgende vitec_card-Elemente
$bandStart = null;
foreach ($elements as $i => $el) {
if ($el['CType'] === 'vitec_introparagraph' && trim((string)$el['header']) === 'Why VITEC?') {
$bandStart = $i;
break;
}
}
if ($bandStart === null) {
echo "$slug (pid $pid): kein 'Why VITEC?'-Intro - uebersprungen\n\n";
continue;
}
$bandEnd = $bandStart;
while (isset($elements[$bandEnd + 1]) && $elements[$bandEnd + 1]['CType'] === 'vitec_card') {
$bandEnd++;
}
// Ziel: das erste andere Intro ("Product range")
$target = null;
foreach ($elements as $i => $el) {
if ($i >= $bandStart && $i <= $bandEnd) {
continue;
}
if ($el['CType'] === 'vitec_introparagraph') {
$target = $i;
break;
}
}
if ($target === null) {
echo "$slug (pid $pid): kein zweites Intro gefunden - uebersprungen\n\n";
continue;
}
echo "$slug (pid $pid) - Band: Elemente " . ($bandEnd - $bandStart + 1)
. " (#" . $elements[$bandStart]['uid'] . "..#" . $elements[$bandEnd]['uid'] . ")"
. ", Ziel-Intro: #" . $elements[$target]['uid'] . " \"" . $elements[$target]['header'] . "\"\n";
if ($target > $bandEnd) {
echo " Band steht bereits VOR dem Ziel-Intro - nichts zu tun\n\n";
continue;
}
// neue Reihenfolge: Band raus, vor das Ziel-Intro wieder rein
$band = array_slice($elements, $bandStart, $bandEnd - $bandStart + 1);
$rest = array_merge(array_slice($elements, 0, $bandStart), array_slice($elements, $bandEnd + 1));
$newOrder = [];
foreach ($rest as $el) {
if ((int)$el['uid'] === (int)$elements[$target]['uid']) {
foreach ($band as $b) {
$newOrder[] = $b;
}
}
$newOrder[] = $el;
}
echo " Neue Reihenfolge:\n";
$sorting = 0;
foreach ($newOrder as $el) {
$sorting += 256;
printf(" %5d #%-6d %-24s %s\n", $sorting, $el['uid'], $el['CType'], (string)$el['header']);
if ($apply) {
$pdo->prepare('UPDATE tt_content SET sorting = ? WHERE uid = ?')->execute([$sorting, (int)$el['uid']]);
}
}
$moved++;
echo "\n";
}
echo ($apply ? "FERTIG" : "WUERDE") . ": $moved Seite(n) umsortiert.\n";
if ($apply && $moved > 0) {
echo "Danach: vendor/bin/typo3 cache:flush\n";
}