88 lines
3.1 KiB
PHP
88 lines
3.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* Diagnose: why does a VITEC container emit an empty `background`?
|
|
*
|
|
* READ-ONLY, plain PDO against config/system/settings.php - same pattern as
|
|
* migrations/export_news.php, so it needs no TYPO3 bootstrap and cannot be
|
|
* affected by any cache.
|
|
*
|
|
* Usage: php migrations/check_bg.php [uid] (default uid 729)
|
|
*/
|
|
|
|
error_reporting(E_ALL);
|
|
ini_set('display_errors', '1');
|
|
|
|
$uid = (int)($argv[1] ?? 729);
|
|
|
|
$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]
|
|
);
|
|
|
|
echo "=== 1) Do the three columns exist? ===\n";
|
|
$cols = $pdo->query("SHOW COLUMNS FROM tt_content LIKE 'tx_vitec_bg_%'")->fetchAll();
|
|
if ($cols === []) {
|
|
echo " NONE. database:updateschema has not created them.\n";
|
|
} else {
|
|
foreach ($cols as $c) {
|
|
echo sprintf(" %-24s %-18s default=%s\n", $c['Field'], $c['Type'], var_export($c['Default'], true));
|
|
}
|
|
}
|
|
|
|
echo "\n=== 2) The record itself (uid $uid) ===\n";
|
|
// Column list built from section 1 rather than hard-coded, so every tx_vitec_bg_*
|
|
// field added later shows up here without the script needing an edit.
|
|
$select = array_merge(
|
|
['uid', 'pid', 'CType', 'deleted', 'hidden', 'sys_language_uid', 'l18n_parent'],
|
|
array_column($cols, 'Field')
|
|
);
|
|
$row = $pdo->query('SELECT ' . implode(', ', $select) . " FROM tt_content WHERE uid = $uid")->fetch();
|
|
if (!$row) {
|
|
echo " no tt_content row with uid $uid\n";
|
|
} else {
|
|
foreach ($row as $k => $v) {
|
|
echo sprintf(" %-24s %s\n", $k, var_export($v, true));
|
|
}
|
|
}
|
|
|
|
echo "\n=== 3) File references pointing at this record ===\n";
|
|
$refs = $pdo->query(
|
|
"SELECT r.uid, r.tablenames, r.fieldname, r.uid_local, r.uid_foreign, r.deleted, r.hidden, r.sorting_foreign,
|
|
f.identifier, f.name, f.mime_type
|
|
FROM sys_file_reference r LEFT JOIN sys_file f ON f.uid = r.uid_local
|
|
WHERE r.uid_foreign = $uid AND r.tablenames = 'tt_content'"
|
|
)->fetchAll();
|
|
if ($refs === []) {
|
|
echo " NONE - nothing references this record. The image was not saved.\n";
|
|
} else {
|
|
foreach ($refs as $r) {
|
|
echo sprintf(" ref %-6s field=%-22s file=%s deleted=%s hidden=%s\n",
|
|
$r['uid'], $r['fieldname'], (string)$r['identifier'], $r['deleted'], $r['hidden']);
|
|
}
|
|
}
|
|
|
|
echo "\n=== 4) Which fieldnames does tt_content use at all? (top 15) ===\n";
|
|
foreach ($pdo->query("SELECT fieldname, COUNT(*) c FROM sys_file_reference WHERE tablenames='tt_content' AND deleted=0 GROUP BY fieldname ORDER BY c DESC LIMIT 15")->fetchAll() as $r) {
|
|
echo sprintf(" %-28s %d\n", $r['fieldname'], $r['c']);
|
|
}
|