PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC] ); // --- workbook coverage from the manifest ------------------------------------ $manifest = json_decode((string)file_get_contents($root . '/migrations/products_xlsx/manifest.json'), true) ?: []; $workbookSlugs = []; foreach (($manifest['workbooks'] ?? []) as $file => $entry) { if (!empty($entry['product'])) { $workbookSlugs[(string)$entry['product']] = basename((string)$file); } } // --- data --------------------------------------------------------------------- $products = $pdo->query('SELECT uid, title, slug, hidden, legacy, supportproduct, subproduct FROM tx_vitec_domain_model_product WHERE deleted = 0 ORDER BY title')->fetchAll(); $downloads = $pdo->query('SELECT uid, title, hidden FROM tx_vitec_domain_model_download WHERE deleted = 0')->fetchAll(); $downloadTitle = array_column($downloads, 'title', 'uid'); $linksByProduct = []; $linkedDownloadUids = []; foreach ($pdo->query('SELECT uid_local, uid_foreign FROM tx_vitec_product_download_mm') as $r) { $linksByProduct[(int)$r['uid_local']][] = (int)$r['uid_foreign']; $linkedDownloadUids[(int)$r['uid_foreign']] = true; } $sheetsByProduct = []; foreach ($pdo->query('SELECT uid_local, COUNT(*) c FROM tx_vitec_product_datasheet_mm GROUP BY uid_local') as $r) { $sheetsByProduct[(int)$r['uid_local']] = (int)$r['c']; } $isDatasheet = static function (string $title): bool { return (bool)preg_match('/data\s*sheet\s*$/i', trim($title)); }; $docType = static function (string $title): string { foreach (['datasheet', 'data sheet', 'brochure', 'user guide', 'quick start guide', 'application note', 'white paper', 'case study', 'success story', 'manual', 'firmware', 'software', 'flyer', 'guide'] as $suffix) { if (preg_match('/' . preg_quote($suffix, '/') . '\s*$/i', trim($title))) { return $suffix; } } return '(no type suffix)'; }; // --- per-product evaluation ------------------------------------------------------ $noDownloads = []; $noDatasheet = []; $okCount = 0; $withoutWorkbook = []; foreach ($products as $p) { $uid = (int)$p['uid']; $slug = (string)$p['slug']; $linked = $linksByProduct[$uid] ?? []; $hasSheet = false; foreach ($linked as $dUid) { if ($isDatasheet((string)($downloadTitle[$dUid] ?? ''))) { $hasSheet = true; break; } } $flag = ((int)$p['legacy'] ? ' [legacy]' : '') . ((int)$p['hidden'] ? ' [hidden]' : '') . ((int)$p['supportproduct'] ? ' [support]' : '') . ((int)$p['subproduct'] ? ' [sub]' : ''); $line = sprintf('#%-4d %-45s dl=%-2d sheetsTab=%d%s', $uid, $p['title'], count($linked), $sheetsByProduct[$uid] ?? 0, $flag); if (!isset($workbookSlugs[$slug])) { $withoutWorkbook[] = $line; } if (isset($workbookSlugs[$slug])) { if ($linked === []) { $noDownloads[] = $line; } elseif (!$hasSheet) { $noDatasheet[] = $line; } else { $okCount++; } } } // --- orphan downloads --------------------------------------------------------------- $orphans = []; $orphanTypes = []; foreach ($downloads as $d) { if (!isset($linkedDownloadUids[(int)$d['uid']])) { $type = $docType((string)$d['title']); $orphanTypes[$type] = ($orphanTypes[$type] ?? 0) + 1; $orphans[] = $d['title']; } } printf("Produkte: %d (davon %d mit Workbook) ยท Downloads: %d (davon %d verlinkt, %d verwaist)\n\n", count($products), count($workbookSlugs), count($downloads), count($linkedDownloadUids), count($orphans)); echo "=== A) Workbook-Produkte OHNE verknuepfte Downloads (" . count($noDownloads) . ") ===\n"; foreach ($noDownloads as $l) { echo " $l\n"; } echo "\n=== B) Workbook-Produkte mit Downloads, aber OHNE Datasheet (" . count($noDatasheet) . ") ===\n"; foreach ($noDatasheet as $l) { echo " $l\n"; } echo "\n=== C) Workbook-Produkte mit Datasheet-Abdeckung: $okCount ===\n"; echo "\n=== D) Produkte OHNE Workbook (" . count($withoutWorkbook) . ") - zur Einordnung ===\n"; foreach ($withoutWorkbook as $l) { echo " $l\n"; } arsort($orphanTypes); echo "\n=== E) Verwaiste Downloads nach Typ ===\n"; foreach ($orphanTypes as $type => $n) { printf(" %-22s %d\n", $type, $n); } echo "\n Beispiele (max 30):\n"; foreach (array_slice($orphans, 0, 30) as $t) { echo " - $t\n"; }