Files
VITEC-website/migrations/news_story_canonical_20261110.php
orascheandClaude Fable 5.1 4b6731786d News: Canonical auf Success Story (Feld vitec_canonical_usecase), 13 Paare gesetzt
13 Pressemeldungen tragen denselben Text wie eine Success Story
(Seobility: doppelter Inhalt). Neues Feld am News-Datensatz (Tab
'VITEC SEO', Auswahl der Story); VitecMetaHandler ersetzt damit den
Canonical-Link durch /success-stories/<slug>. Die Meldung bleibt in der
Liste, Suchmaschinen werten die Story als Original. Migration
news_story_canonical_20261110 setzt die 13 Zuordnungen (angewendet).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-11-10 18:20:03 +01:00

75 lines
3.2 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
declare(strict_types=1);
/**
* News articles that carry the same text as a success story get the story
* as canonical (field tx_news_domain_model_news.vitec_canonical_usecase,
* evaluated by VitecMetaHandler). The article stays in the news list.
*
* Pairs from the Seobility duplicate-content report of 2026-11-10.
*
* Dry run: php migrations/news_story_canonical_20261110.php
* Write: php migrations/news_story_canonical_20261110.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";
// news uid => usecase (story) uid
$pairs = [
361 => 56, // Denver Sportsbook Bar & Grill
121 => 24, // European Space Agency
164 => 26, // Feature Story News
336 => 62, // Kyndryl Cyber Operations Center
388 => 74, // Leading Video Capture for the Medical Market
239 => 66, // RRS Sir David Attenborough
158 => 46, // Sacramento Kings
310 => 68, // SENTRY Video Walls – 2024 Olympic Games
290 => 72, // UK Mission Critical Control Room
389 => 59, // Intercity Istanbul Park
436 => 64, // NHS tribute onto Parliament
395 => 54, // Bahrain International Circuit
327 => 60, // ITV News Headquarters
];
$news = $pdo->prepare("SELECT uid, title, path_segment, vitec_canonical_usecase FROM tx_news_domain_model_news WHERE deleted = 0 AND uid = ?");
$story = $pdo->prepare("SELECT uid, title, slug, hidden FROM tx_vitec_domain_model_usecase WHERE deleted = 0 AND uid = ?");
$update = $pdo->prepare("UPDATE tx_news_domain_model_news SET vitec_canonical_usecase = ?, tstamp = UNIX_TIMESTAMP() WHERE uid = ?");
$set = 0;
$paths = [];
foreach ($pairs as $newsUid => $storyUid) {
$news->execute([$newsUid]); $n = $news->fetch();
$story->execute([$storyUid]); $s = $story->fetch();
if (!$n || !$s) { echo " #$newsUid -> #$storyUid: Datensatz fehlt, uebersprungen\n"; continue; }
if ((int)$s['hidden'] === 1) { echo " #$newsUid -> #$storyUid: Story versteckt, uebersprungen\n"; continue; }
$state = (int)$n['vitec_canonical_usecase'] === $storyUid ? 'schon gesetzt' : 'setzen';
printf(" news #%-4d %-70s -> story #%-3d /success-stories/%s [%s]\n", $newsUid, mb_substr($n['title'], 0, 70), $storyUid, $s['slug'], $state);
$paths[] = '/news/article/' . $n['path_segment'];
if ($state === 'setzen') {
$set++;
if ($apply) { $update->execute([$storyUid, $newsUid]); }
}
}
echo "\n$set Zuordnung(en) " . ($apply ? 'geschrieben' : 'wuerden geschrieben') . ".\n";
echo "SSR-Pfade:\n " . implode("\n ", $paths) . "\n";