Files
VITEC-website/migrations/check_productlist_ces.php
Oliver Rasche 5499ca54af Align product records with sitemap V2; product family model; CLI workbook import
- vitec:migrate-product-structure: exact V2 titles, Milestone typo fix (incl.
  slug), QTX100 stray VSN category removed, Aligo record moved to its own
  category with slug /product/aligo, new Aligo Workstation record takes over
  /product/aligo-workstation
- product families (sitemap column K) are ordinary content pages now:
  vitec:remove-family-records deletes the interim landing records again,
  reset_subproduct_flags.php clears the misused subproduct flag (the list
  renderer has always excluded subproduct=1)
- vitec:import-product-workbook: non-interactive counterpart of the module
  import (same reader, mapping and DataHandler path); Arqa imported, Aligo
  re-applied with the corrected capabilities markup
- ProductXlsxReader: new :copy cell selector (Body Copy with CTA fallback)
  absorbs the agency's column drift; default teaser mapping uses it
- ProductListJsonRenderer: selected categories now match their whole subtree,
  results ordered by category tree position, sheet order within a category
- read-only diagnostics: check_product_structure.php, check_productlist_ces.php
2026-09-04 12:59:17 +02:00

70 lines
2.7 KiB
PHP

<?php
declare(strict_types=1);
/**
* Read-only: print the FlexForm settings (categories, allproducts, layout)
* of every vitec_productlist content element, plus which of the configured
* category uids still exist and how many products they carry.
*
* Usage: php migrations/check_productlist_ces.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]
);
$ces = $pdo->query(
"SELECT uid, pid, header, hidden, pi_flexform FROM tt_content
WHERE CType = 'vitec_productlist' AND deleted = 0 ORDER BY pid, sorting"
)->fetchAll();
$flexValue = function (string $xml, string $field): string {
if (preg_match('/<field index="settings\.' . preg_quote($field, '/') . '">.*?<value index="vDEF">(.*?)<\/value>/s', $xml, $m)) {
return trim($m[1]);
}
return '';
};
foreach ($ces as $ce) {
printf("CE %d (pid %d)%s | header: %s\n", $ce['uid'], $ce['pid'], $ce['hidden'] ? ' HIDDEN' : '', $ce['header'] ?: '-');
$cats = $flexValue((string)$ce['pi_flexform'], 'categories');
printf(" categories: %s | allproducts: %s | layout: %s\n",
$cats === '' ? '(leer)' : $cats,
$flexValue((string)$ce['pi_flexform'], 'allproducts') ?: '0',
$flexValue((string)$ce['pi_flexform'], 'layout') ?: '-'
);
foreach (array_filter(array_map('intval', explode(',', $cats))) as $catUid) {
$cat = $pdo->query("SELECT title, deleted, hidden FROM sys_category WHERE uid = " . $catUid)->fetch();
$count = (int)$pdo->query(
"SELECT COUNT(DISTINCT p.uid) FROM sys_category_record_mm mm
JOIN tx_vitec_domain_model_product p ON p.uid = mm.uid_foreign AND p.deleted = 0
WHERE mm.uid_local = $catUid AND mm.tablenames = 'tx_vitec_domain_model_product' AND mm.fieldname = 'categories'"
)->fetchColumn();
printf(" cat %d: %s | %d products\n",
$catUid,
$cat ? ($cat['title'] . ($cat['deleted'] ? ' [DELETED]' : '') . ($cat['hidden'] ? ' [HIDDEN]' : '')) : 'EXISTIERT NICHT',
$count
);
}
}
echo count($ces) . " productlist elements total\n";