Files
VITEC-website/migrations/reset_product_mapping.php
2026-08-28 13:57:54 +02:00

52 lines
1.8 KiB
PHP

<?php
declare(strict_types=1);
/**
* One-shot: clear the SAVED field mapping of the product-text import
* (tx_vitec_import_mapping, model "product_xlsx") so the corrected
* DEFAULT_MAPPING seed applies again.
*
* Deliberately clears ONLY the `mapping` column - the same row also stores
* `record_aliases` (the editor's manual related-product matches), and those
* must survive.
*
* Usage: php migrations/reset_product_mapping.php
*/
$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("Could not locate project root above " . __DIR__ . "\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]
);
$row = $pdo->query("SELECT uid, mapping, record_aliases FROM tx_vitec_import_mapping WHERE model = 'product_xlsx'")->fetch();
if (!$row) {
exit("No row for model 'product_xlsx' - nothing to clear, defaults apply already.\n");
}
echo "Row uid " . $row['uid'] . "\n";
echo " mapping (cleared) : " . ($row['mapping'] ?: '(empty)') . "\n";
echo " aliases (KEPT) : " . ($row['record_aliases'] ?: '(empty)') . "\n";
$pdo->prepare("UPDATE tx_vitec_import_mapping SET mapping = '', tstamp = ? WHERE model = 'product_xlsx'")
->execute([time()]);
echo "Done - the saved field mapping is cleared, the corrected defaults apply on the next preview.\n";