5use dbx\dbxContent\dbxContentMediaUsageScope;
8 'id' =>
'core-4.1.2-media-usage-schema-repair',
10 'description' =>
'Repariert das Media-Usage-Schema updatefest und wiederholt die Sprachzuordnung.',
11 'affected_dd' => array(
'dbx|dbxMediaUsage'),
12 'operations' => array(
13 array(
'type' =>
'sync_dd',
'dd' =>
'dbx|dbxMediaUsage'),
15 'up' =>
static function(
$db,
$dd):
void {
17 require_once
$moduleRoot .
'/dbxContent/include/dbxContent_bootstrap_sync.php';
18 require_once
$moduleRoot .
'/dbxContent/include/dbxContentMediaUsageScope.class.php';
20 $ddFile = dirname(__DIR__) .
'/dd/dbxMediaUsage.dd.php';
33 throw new RuntimeException(
'Release-DD dbxMediaUsage ist ungueltig.');
36 $server = (string)
$db->get_dd_server(
'dbx|dbxMediaUsage');
37 $table = (string)
$db->get_dd_table(
'dbx|dbxMediaUsage');
39 throw new RuntimeException(
'Media-Usage-Datenbankziel ist ungueltig.');
45 if (!isset(
$_SESSION[
'dbx'][
'cache'][
'dd'][
'dbx'])
46 || !is_array(
$_SESSION[
'dbx'][
'cache'][
'dd'][
'dbx'])
48 $_SESSION[
'dbx'][
'cache'][
'dd'][
'dbx'] = array();
50 $hadCache = array_key_exists(
54 $previousCache = $hadCache
55 ?
$_SESSION[
'dbx'][
'cache'][
'dd'][
'dbx'][
'dbxMediaUsage']
58 $_SESSION[
'dbx'][
'cache'][
'dd'][
'dbx'][
'dbxMediaUsage'] = array(
63 'language_dynamic' =>
false,
68 $dd->sync_dd_to_db(
'dbx',
'dbxMediaUsage',
'reset');
70 for ($step = 0; $step < 1000; $step++) {
71 $sync =
$dd->sync_dd_to_db(
'dbx',
'dbxMediaUsage',
'apply');
73 (
string)($sync[
'status'] ??
''),
74 array(
'finished',
'error',
'cancelled'),
80 if (($sync[
'status'] ??
'') !==
'finished') {
81 throw new RuntimeException(
82 'dbxMediaUsage: ' . (
string)($sync[
'message'] ??
'DD-Sync fehlgeschlagen')
86 $physicalNames = array_map(
87 static fn(array
$field):
string => (
string)(
$field[
'name'] ??
''),
88 is_array($physicalFields) ? $physicalFields : array()
90 if (!in_array(
'content_lng', $physicalNames,
true)) {
91 throw new RuntimeException(
'content_lng wurde physisch nicht angelegt.');
94 $languages = array_values(array_unique(array_map(
95 static fn(
$lng):
string => dbxContentMediaUsageScope::language((
string)
$lng),
96 dbxContentLngSync::accessibleLngs()
99 $master = dbxContentMediaUsageScope::language(dbxContentLngSync::masterLng());
101 $pageCache = array();
102 $folderCache = array();
104 $pageCache[
$lng] = array();
105 $folderCache[
$lng] = array();
107 dbxContentLng::ddContent(
$lng),
109 'id,folder,hero_image_id,content',
118 if (is_array(
$page) && (
int)(
$page[
'id'] ?? 0) > 0) {
122 $folders =
$db->select(
123 dbxContentLng::ddFolder(
$lng),
133 foreach (is_array($folders) ? $folders : array() as $folder) {
134 if (is_array($folder) && (
int)($folder[
'id'] ?? 0) > 0) {
135 $folderCache[
$lng][(int)$folder[
'id']] = $folder;
140 $containsMedia =
static function(
string $html,
int $mediaId): bool {
142 return preg_match(
'/data-cms-media-id=["\']?' .
$mediaId .
'(?:["\'\s>]|$)/i',
$html) === 1
143 || preg_match(
'/(?:dbx_mid|media_id)=' .
$mediaId .
'(?:[^0-9]|$)/i',
$html) === 1;
146 $rows =
$db->select(
'dbxMediaUsage',
'',
'*',
'id',
'ASC',
'', 0, 0, 0);
148 foreach (is_array(
$rows) ?
$rows : array() as $row) {
149 if (!is_array($row))
continue;
150 $id = (int)($row[
'id'] ?? 0);
151 if ($id <= 0)
continue;
152 if ((
int)($row[
'active'] ?? 0) !== 1) {
153 $db->delete(
'dbxMediaUsage', $id, 1, 0);
157 $mediaId = (int)($row[
'media_id'] ?? 0);
158 $contentId = (int)($row[
'content_id'] ?? 0);
159 $folderId = (int)($row[
'folder_id'] ?? 0);
160 $slot = strtolower(trim((
string)($row[
'slot'] ??
'')));
163 if ($slot ===
'shop') {
165 } elseif ($contentId > 0) {
167 $page = $pageCache[
$lng][$contentId] ??
null;
168 if (!is_array(
$page))
continue;
169 if ($folderId > 0 && (
int)(
$page[
'folder'] ?? 0) !== $folderId)
continue;
170 if ($slot ===
'hero' && (
int)(
$page[
'hero_image_id'] ?? 0) !==
$mediaId)
continue;
171 if ($slot ===
'inline' && !$containsMedia((
string)(
$page[
'content'] ??
''),
$mediaId))
continue;
179 } elseif ($folderId > 0) {
181 $folder = $folderCache[
$lng][$folderId] ??
null;
182 if (!is_array($folder))
continue;
183 if ($slot ===
'hero' && (
int)($folder[
'hero_image_id'] ?? 0) !==
$mediaId)
continue;
198 $key =
$lng .
':' . $contentId .
':' . $folderId .
':' . $slot .
':' .
$mediaId;
199 if (isset($seen[$key])) {
200 $db->delete(
'dbxMediaUsage', $id, 1, 0);
204 if ((
string)($row[
'content_lng'] ??
'') !==
$lng) {
207 array(
'content_lng' =>
$lng),
218 $_SESSION[
'dbx'][
'cache'][
'dd'][
'dbx'][
'dbxMediaUsage'] = $previousCache;
220 unset(
$_SESSION[
'dbx'][
'cache'][
'dd'][
'dbx'][
'dbxMediaUsage']);
if(!defined( 'IMG_WEBP')) define( 'IMG_WEBP'
foreach($help->topics() as $topic=> $meta) $languages
if($cinematic===''||!str_contains($cinematic, 'data-dbx-cinema')) $page