From b52a53003c5e9b55f0a81a7e905c5afdbc09510c Mon Sep 17 00:00:00 2001 From: Lars Gebhardt-Kusche Date: Tue, 20 Jan 2026 02:35:11 +0100 Subject: [PATCH] ydasdas --- src/ApiKernel.php | 63 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 20 deletions(-) diff --git a/src/ApiKernel.php b/src/ApiKernel.php index 21f030f..366c63f 100644 --- a/src/ApiKernel.php +++ b/src/ApiKernel.php @@ -354,6 +354,7 @@ class ApiKernel return [ 'category' => $this->firstExisting($cols, ['category', 'cat']), 'html' => $this->firstExisting($cols, ['html', 'html_content', 'body', 'markup', 'content']), + 'css' => $this->firstExisting($cols, ['css', 'css_content']), 'json' => $this->firstExisting($cols, ['json_content']), 'editor' => $this->firstExisting($cols, ['editor_type', 'editor']), 'craft' => $this->firstExisting($cols, ['craft_json', 'craft_content', 'craft_data']), @@ -361,6 +362,19 @@ class ApiKernel ]; } + private function resolveContentVersionColumns(string $table): array + { + $cols = $this->tableColumns($table); + return [ + 'json' => $this->firstExisting($cols, ['json_content']), + 'html' => $this->firstExisting($cols, ['html', 'html_content']), + 'css' => $this->firstExisting($cols, ['css', 'css_content']), + 'editor' => $this->firstExisting($cols, ['editor_type', 'editor']), + 'craft' => $this->firstExisting($cols, ['craft_json', 'craft_content', 'craft_data']), + 'settings' => $this->firstExisting($cols, ['settings_json', 'settings']), + ]; + } + private function useUnifiedContent(): bool { return $this->tableExists($this->contentItemsTable()) && $this->tableExists($this->contentSectionsTable()); @@ -375,12 +389,14 @@ class ApiKernel $jsonCol = $itemCols['json'] ?? null; $htmlCol = $itemCols['html'] ?? null; + $cssCol = $itemCols['css'] ?? null; $editorCol = $itemCols['editor'] ?? null; $craftCol = $itemCols['craft'] ?? null; $settingsCol = $itemCols['settings'] ?? null; $json = $jsonCol ? ($current[$jsonCol] ?? null) : null; $html = $htmlCol ? ($current[$htmlCol] ?? null) : null; + $css = $cssCol ? ($current[$cssCol] ?? null) : null; $editorType = $editorCol ? ($current[$editorCol] ?? null) : null; $craftJson = $craftCol ? ($current[$craftCol] ?? null) : null; $settings = $settingsCol ? ($current[$settingsCol] ?? null) : null; @@ -390,21 +406,26 @@ class ApiKernel $stmt->execute([':cid' => $contentId]); $nextVersion = (int)($stmt->fetchColumn() ?: 0) + 1; - $stmt = $this->pdo->prepare( - "INSERT INTO `$table` (`customer_id`,`content_id`,`section_id`,`version_no`,`editor_type`,`json_content`,`html`,`craft_json`,`settings_json`) - VALUES (:cust,:content,:section,:ver,:editor,:json,:html,:craft,:settings)" - ); - $stmt->execute([ - ':cust' => $customerId, - ':content' => $contentId, - ':section' => $sectionId, - ':ver' => $nextVersion, - ':editor' => $editorType, - ':json' => $json, - ':html' => $html, - ':craft' => $craftJson, - ':settings' => $settings, - ]); + $versionCols = $this->resolveContentVersionColumns($table); + $data = [ + 'customer_id' => $customerId, + 'content_id' => $contentId, + 'section_id' => $sectionId, + 'version_no' => $nextVersion, + ]; + if ($versionCols['editor']) $data[$versionCols['editor']] = $editorType; + if ($versionCols['json']) $data[$versionCols['json']] = $json; + if ($versionCols['html']) $data[$versionCols['html']] = $html; + if ($versionCols['css']) $data[$versionCols['css']] = $css; + if ($versionCols['craft']) $data[$versionCols['craft']] = $craftJson; + if ($versionCols['settings']) $data[$versionCols['settings']] = $settings; + + $columns = array_keys($data); + $insertCols = implode(',', array_map(fn($c) => "`$c`", $columns)); + $placeholders = implode(',', array_map(fn($c) => ":$c", $columns)); + $stmt = $this->pdo->prepare("INSERT INTO `$table` ($insertCols) VALUES ($placeholders)"); + foreach ($data as $k => $v) $stmt->bindValue(":$k", $v); + $stmt->execute(); $cleanup = $this->pdo->prepare( "DELETE FROM `$table` WHERE `id` IN ( @@ -1048,12 +1069,14 @@ class ApiKernel if (!$version) $this->fail('Not found', ['id' => $versionId], 404); $itemCols = $this->resolveContentItemColumns($itemsTable); + $versionCols = $this->resolveContentVersionColumns($versionsTable); $data = []; - if (!empty($itemCols['json'])) $data[$itemCols['json']] = $version['json_content'] ?? null; - if (!empty($itemCols['html'])) $data[$itemCols['html']] = $version['html'] ?? null; - if (!empty($itemCols['craft'])) $data[$itemCols['craft']] = $version['craft_json'] ?? null; - if (!empty($itemCols['settings'])) $data[$itemCols['settings']] = $version['settings_json'] ?? null; - if (!empty($itemCols['editor'])) $data[$itemCols['editor']] = $version['editor_type'] ?? null; + if (!empty($itemCols['json']) && $versionCols['json']) $data[$itemCols['json']] = $version[$versionCols['json']] ?? null; + if (!empty($itemCols['html']) && $versionCols['html']) $data[$itemCols['html']] = $version[$versionCols['html']] ?? null; + if (!empty($itemCols['css']) && $versionCols['css']) $data[$itemCols['css']] = $version[$versionCols['css']] ?? null; + if (!empty($itemCols['craft']) && $versionCols['craft']) $data[$itemCols['craft']] = $version[$versionCols['craft']] ?? null; + if (!empty($itemCols['settings']) && $versionCols['settings']) $data[$itemCols['settings']] = $version[$versionCols['settings']] ?? null; + if (!empty($itemCols['editor']) && $versionCols['editor']) $data[$itemCols['editor']] = $version[$versionCols['editor']] ?? null; if ($data) { $set = implode(',', array_map(static fn($c) => "`$c` = :$c", array_keys($data)));