This commit is contained in:
2026-01-22 00:12:51 +01:00
parent 6c06b850eb
commit 62bf263b8e
2 changed files with 38 additions and 4 deletions

View File

@@ -172,7 +172,14 @@
    B.fetchSections = () => B.fetchResource('sections');
    B.fetchBlocks = () => B.fetchResource('blocks');
    B.getApiItem = (kind, id) => fetchData(kind, 'get', { id: id }); 
    B.getApiItem = (kind, id) => {
        const normalized = String(kind || '').toLowerCase();
        const legacyKinds = ['templates', 'sections', 'blocks', 'snippets', 'content', 'sections_config', 'content_versions'];
        if (B.USE_DYNAMIC_SECTIONS && !legacyKinds.includes(normalized)) {
            return fetchData('content', 'get', { id: id, section_slug: normalized, active_only: 1 });
       }
        return fetchData(normalized || kind, 'get', { id: id });
    };
    B.clearApiCache = () => {
        B.ApiItemCache = {}; // Cache leeren

View File

@@ -779,6 +779,7 @@ class ApiKernel
$itemsTable = $this->contentItemsTable();
$sectionsTable = $this->contentSectionsTable();
$versionsTable = $this->contentVersionsTable();
if (!$this->tableExists($itemsTable) || !$this->tableExists($sectionsTable)) {
$this->fail('Content tables not available', null, 500);
}
@@ -787,6 +788,10 @@ class ApiKernel
$jsonCol = $itemCols['json'];
$craftCol = $itemCols['craft'];
$editorCol = $itemCols['editor'];
$onlyActive = (int)$this->val($this->in, ['active_only', 'only_active', 'active'], 0) === 1;
$versionCols = $onlyActive && $this->tableExists($versionsTable)
? $this->resolveContentVersionColumns($versionsTable)
: null;
$section = $fixedSection ?: $this->resolveSectionFromInput($customerId);
$params = [':cid' => $customerId, ':id' => $id];
@@ -796,9 +801,20 @@ class ApiKernel
$params[':sid'] = (int)$section['id'];
}
$sql = "SELECT i.*, s.`name` AS section_name, s.`slug` AS section_slug, s.`position` AS section_position, s.`is_template` AS section_is_template
$select = "i.*, s.`name` AS section_name, s.`slug` AS section_slug, s.`position` AS section_position, s.`is_template` AS section_is_template";
$join = '';
if ($onlyActive && $versionCols) {
$join = "LEFT JOIN `$versionsTable` v ON v.`content_id` = i.`id` AND v.`is_active` = 1";
if (!empty($versionCols['html'])) $select .= ", v.`{$versionCols['html']}` AS version_html";
if (!empty($versionCols['json'])) $select .= ", v.`{$versionCols['json']}` AS version_json";
if (!empty($versionCols['craft'])) $select .= ", v.`{$versionCols['craft']}` AS version_craft";
if (!empty($versionCols['editor'])) $select .= ", v.`{$versionCols['editor']}` AS version_editor";
$select .= ", v.`id` AS active_version_id, v.`version_no` AS active_version_no, v.`is_active` AS version_is_active, v.`was_active` AS version_was_active";
}
$sql = "SELECT $select
FROM `$itemsTable` i
JOIN `$sectionsTable` s ON s.`id` = i.`section_id`
$join
$where
LIMIT 1";
$stmt = $this->pdo->prepare($sql);
@@ -809,6 +825,10 @@ class ApiKernel
$html = $htmlCol ? (string)($row[$htmlCol] ?? '') : '';
$json = $jsonCol ? ($row[$jsonCol] ?? null) : null;
if ($onlyActive && $versionCols) {
if (array_key_exists('version_html', $row)) $html = (string)($row['version_html'] ?? $html);
if (array_key_exists('version_json', $row)) $json = $row['version_json'] ?? $json;
}
$gjsComponents = [];
if ($json !== null) {
$decoded = json_decode((string)$json, true);
@@ -825,6 +845,13 @@ class ApiKernel
$item['section_position'] = $row['section_position'] ?? null;
$item['section_is_template'] = (int)($row['section_is_template'] ?? 0);
$editorType = $editorCol ? ($row[$editorCol] ?? null) : null;
$craftJson = $craftCol ? ($row[$craftCol] ?? null) : null;
if ($onlyActive && $versionCols) {
if (array_key_exists('version_editor', $row)) $editorType = $row['version_editor'] ?? $editorType;
if (array_key_exists('version_craft', $row)) $craftJson = $row['version_craft'] ?? $craftJson;
}
$this->respond([
'ok' => true,
'kind' => 'content',
@@ -834,8 +861,8 @@ class ApiKernel
'html' => $html,
'content' => $json,
'gjs_components' => $gjsComponents,
'editor_type' => $editorCol ? ($row[$editorCol] ?? null) : null,
'craft_json' => $craftCol ? ($row[$craftCol] ?? null) : null,
'editor_type' => $editorType,
'craft_json' => $craftJson,
]);
}