dbxapp 4.1.3
CMS, Shop, Workflows und modulare Geschäftsanwendungen
Loading...
Searching...
No Matches
cms_media_usage_maintenance_test.php
Go to the documentation of this file.
1<?php
2declare(strict_types=1);
3
4require_once dirname(__DIR__) . '/include/dbxContentMediaUsageMaintenance.class.php';
5
7
8$failures = array();
9$assert = static function(bool $condition, string $message) use (&$failures): void {
10 if (!$condition) $failures[] = $message;
11};
12
13$expected = array();
14$inlineKey = dbxContentMediaUsageMaintenance::usageKey(10, 7, 3, 'inline');
15$heroKey = dbxContentMediaUsageMaintenance::usageKey(11, 7, 3, 'hero');
16$folderHeroKey = dbxContentMediaUsageMaintenance::usageKey(12, 0, 4, 'hero');
18 'media_id' => 10,
19 'content_id' => 7,
20 'folder_id' => 3,
21 'slot' => 'inline',
22 'template' => 'image-inline',
23 'valid_folders' => array(3 => 1),
24);
26 'media_id' => 11,
27 'content_id' => 7,
28 'folder_id' => 3,
29 'slot' => 'hero',
30 'template' => 'image-hero',
31 'valid_folders' => array(3 => 1),
32);
34 'media_id' => 12,
35 'content_id' => 0,
36 'folder_id' => 4,
37 'slot' => 'hero',
38 'template' => 'image-hero',
39 'valid_folders' => array(),
40);
41
42$rows = array(
43 array('id' => 1, 'active' => 0, 'media_id' => 10, 'content_id' => 7, 'folder_id' => 3, 'slot' => 'inline'),
44 array('id' => 2, 'active' => 1, 'media_id' => 10, 'content_id' => 7, 'folder_id' => 0, 'slot' => 'inline'),
45 array('id' => 3, 'active' => 1, 'media_id' => 10, 'content_id' => 7, 'folder_id' => 3, 'slot' => 'inline'),
46 array('id' => 4, 'active' => 1, 'media_id' => 13, 'content_id' => 7, 'folder_id' => 3, 'slot' => 'inline'),
47 array('id' => 5, 'active' => 1, 'media_id' => 13, 'content_id' => 7, 'folder_id' => 3, 'slot' => 'gallery'),
48 array('id' => 6, 'active' => 1, 'media_id' => 99, 'content_id' => 7, 'folder_id' => 3, 'slot' => 'gallery'),
49 array('id' => 7, 'active' => 1, 'media_id' => 13, 'content_id' => 7, 'folder_id' => 3, 'slot' => 'unknown'),
50 array('id' => 8, 'active' => 1, 'media_id' => 13, 'content_id' => 999, 'folder_id' => 3, 'slot' => 'gallery'),
51 array('id' => 9, 'active' => 1, 'media_id' => 12, 'content_id' => 0, 'folder_id' => 4, 'slot' => 'hero'),
52);
53
54$plan = dbxContentMediaUsageMaintenance::plan(
55 $rows,
56 array(10 => 1, 11 => 1, 12 => 1, 13 => 1),
58 array(7 => array(3 => 1)),
59 array(3 => 1, 4 => 1),
60 array('hero', 'gallery', 'inline', 'header', 'teaser', 'footer', 'shop')
61);
62
63$assert(($plan['delete'][1] ?? '') === 'inactive', 'Inactive history must be deleted physically.');
64$assert(($plan['delete'][3] ?? '') === 'duplicate', 'A second controlled usage must be removed as duplicate.');
65$assert(($plan['delete'][4] ?? '') === 'not_in_content', 'Stale inline usage must be removed.');
66$assert(($plan['delete'][6] ?? '') === 'media_invalid', 'Usage of an invalid medium must be removed.');
67$assert(($plan['delete'][7] ?? '') === 'slot_invalid', 'Unknown usage slots must be removed.');
68$assert(($plan['delete'][8] ?? '') === 'content_missing', 'Usage with a missing target must be removed.');
69$assert(($plan['update'][2]['folder_id'] ?? 0) === 3, 'The page folder of a controlled usage must be corrected.');
70$assert(!isset($plan['delete'][5]), 'A valid manually managed gallery usage must be preserved.');
71$assert(!isset($plan['delete'][9]), 'A real folder hero usage must be preserved.');
72$assert(isset($plan['insert'][$heroKey]), 'A missing hero usage must be rebuilt from the real page field.');
73$assert(!isset($plan['insert'][$inlineKey]), 'An existing inline usage must not be inserted twice.');
74
75$base = dirname(__DIR__, 4);
76$cmsSource = (string)file_get_contents($base . '/dbx/modules/dbxContent_admin/include/dbxContent_cms.class.php');
77$cmsJs = (string)file_get_contents($base . '/dbx/js/lib/cms.js');
79 str_contains($cmsSource, "array('type' => 'usage_reconcile')")
80 && str_contains($cmsSource, "array('type' => 'media_record_purge')")
81 && str_contains($cmsSource, 'cleanup_invalid_structured_media_references'),
82 'The maintenance process must schedule usage reconciliation, invalid media purging and structured reference cleanup.'
83);
85 str_contains($cmsJs, 'Medien und Nutzung pruefen')
86 && str_contains($cmsJs, 'Analyse &amp; Reparatur starten')
87 && str_contains($cmsJs, 'Nachweislich ungueltige und deaktivierte Datenbankeintraege'),
88 'The destructive maintenance workflow must be explained and confirmed in the UI.'
89);
90foreach (array('dbxapp', 'dbxdocs', 'flowers', 'steal') as $design) {
91 $css = (string)file_get_contents($base . '/dbx/design/' . $design . '/css/c-cms.css');
92 $assert(str_contains($css, '.dbx-cms-media-maintenance-report'), 'The maintenance report is not styled in design ' . $design . '.');
93}
94
96 fwrite(STDERR, "FAIL\n- " . implode("\n- ", $failures) . "\n");
97 exit(1);
98}
99
100echo "OK media usage reconciliation removes stale history and rebuilds real references.\n";
101
103$deKey = dbxContentMediaUsageMaintenance::usageKey(21, 5, 2, 'inline', 'de');
104$enKey = dbxContentMediaUsageMaintenance::usageKey(22, 5, 2, 'inline', 'en');
105$multiExpected[$deKey] = array('media_id' => 21, 'content_id' => 5, 'folder_id' => 2, 'content_lng' => 'de', 'slot' => 'inline', 'valid_folders' => array(2 => 1));
106$multiExpected[$enKey] = array('media_id' => 22, 'content_id' => 5, 'folder_id' => 2, 'content_lng' => 'en', 'slot' => 'inline', 'valid_folders' => array(2 => 1));
107$multiPlan = dbxContentMediaUsageMaintenance::plan(
108 array(
109 array('id' => 101, 'active' => 1, 'media_id' => 21, 'content_id' => 5, 'folder_id' => 2, 'content_lng' => 'de', 'slot' => 'inline'),
110 array('id' => 102, 'active' => 1, 'media_id' => 22, 'content_id' => 5, 'folder_id' => 2, 'content_lng' => 'en', 'slot' => 'inline'),
111 array('id' => 103, 'active' => 1, 'media_id' => 23, 'content_id' => 5, 'folder_id' => 2, 'content_lng' => 'de', 'slot' => 'gallery'),
112 array('id' => 104, 'active' => 1, 'media_id' => 23, 'content_id' => 5, 'folder_id' => 2, 'content_lng' => 'de', 'slot' => 'gallery'),
113 ),
114 array(21 => 1, 22 => 1, 23 => 1),
116 array('de:5' => array(2 => 1), 'en:5' => array(2 => 1)),
117 array('de:2' => 1, 'en:2' => 1),
118 array('hero', 'gallery', 'inline', 'header', 'teaser', 'footer', 'shop')
119);
121if (isset($multiPlan['delete'][101]) || isset($multiPlan['delete'][102])) $multiFailures[] = 'Same numeric page IDs in different languages must stay independent.';
122if (($multiPlan['delete'][104] ?? '') !== 'duplicate') $multiFailures[] = 'Exact duplicates must be removed for manually managed slots too.';
123if (isset($multiPlan['insert'][$deKey]) || isset($multiPlan['insert'][$enKey])) $multiFailures[] = 'Existing language-specific usages must not be inserted again.';
124if ($multiFailures) {
125 fwrite(STDERR, "FAIL\n- " . implode("\n- ", $multiFailures) . "\n");
126 exit(1);
127}
128echo "OK multilingual media usage targets and all-slot duplicate cleanup.\n";
Erstellt ohne Datenbankzugriffe einen sicheren Reparaturplan fuer dbxMediaUsage.
foreach( $iterator as $file) if(! $groups) $expected
if(trim($second) !=='second') $design
exit
Definition index.php:146