ydasdas
This commit is contained in:
@@ -354,6 +354,7 @@ class ApiKernel
|
|||||||
return [
|
return [
|
||||||
'category' => $this->firstExisting($cols, ['category', 'cat']),
|
'category' => $this->firstExisting($cols, ['category', 'cat']),
|
||||||
'html' => $this->firstExisting($cols, ['html', 'html_content', 'body', 'markup', 'content']),
|
'html' => $this->firstExisting($cols, ['html', 'html_content', 'body', 'markup', 'content']),
|
||||||
|
'css' => $this->firstExisting($cols, ['css', 'css_content']),
|
||||||
'json' => $this->firstExisting($cols, ['json_content']),
|
'json' => $this->firstExisting($cols, ['json_content']),
|
||||||
'editor' => $this->firstExisting($cols, ['editor_type', 'editor']),
|
'editor' => $this->firstExisting($cols, ['editor_type', 'editor']),
|
||||||
'craft' => $this->firstExisting($cols, ['craft_json', 'craft_content', 'craft_data']),
|
'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
|
private function useUnifiedContent(): bool
|
||||||
{
|
{
|
||||||
return $this->tableExists($this->contentItemsTable()) && $this->tableExists($this->contentSectionsTable());
|
return $this->tableExists($this->contentItemsTable()) && $this->tableExists($this->contentSectionsTable());
|
||||||
@@ -375,12 +389,14 @@ class ApiKernel
|
|||||||
|
|
||||||
$jsonCol = $itemCols['json'] ?? null;
|
$jsonCol = $itemCols['json'] ?? null;
|
||||||
$htmlCol = $itemCols['html'] ?? null;
|
$htmlCol = $itemCols['html'] ?? null;
|
||||||
|
$cssCol = $itemCols['css'] ?? null;
|
||||||
$editorCol = $itemCols['editor'] ?? null;
|
$editorCol = $itemCols['editor'] ?? null;
|
||||||
$craftCol = $itemCols['craft'] ?? null;
|
$craftCol = $itemCols['craft'] ?? null;
|
||||||
$settingsCol = $itemCols['settings'] ?? null;
|
$settingsCol = $itemCols['settings'] ?? null;
|
||||||
|
|
||||||
$json = $jsonCol ? ($current[$jsonCol] ?? null) : null;
|
$json = $jsonCol ? ($current[$jsonCol] ?? null) : null;
|
||||||
$html = $htmlCol ? ($current[$htmlCol] ?? null) : null;
|
$html = $htmlCol ? ($current[$htmlCol] ?? null) : null;
|
||||||
|
$css = $cssCol ? ($current[$cssCol] ?? null) : null;
|
||||||
$editorType = $editorCol ? ($current[$editorCol] ?? null) : null;
|
$editorType = $editorCol ? ($current[$editorCol] ?? null) : null;
|
||||||
$craftJson = $craftCol ? ($current[$craftCol] ?? null) : null;
|
$craftJson = $craftCol ? ($current[$craftCol] ?? null) : null;
|
||||||
$settings = $settingsCol ? ($current[$settingsCol] ?? null) : null;
|
$settings = $settingsCol ? ($current[$settingsCol] ?? null) : null;
|
||||||
@@ -390,21 +406,26 @@ class ApiKernel
|
|||||||
$stmt->execute([':cid' => $contentId]);
|
$stmt->execute([':cid' => $contentId]);
|
||||||
$nextVersion = (int)($stmt->fetchColumn() ?: 0) + 1;
|
$nextVersion = (int)($stmt->fetchColumn() ?: 0) + 1;
|
||||||
|
|
||||||
$stmt = $this->pdo->prepare(
|
$versionCols = $this->resolveContentVersionColumns($table);
|
||||||
"INSERT INTO `$table` (`customer_id`,`content_id`,`section_id`,`version_no`,`editor_type`,`json_content`,`html`,`craft_json`,`settings_json`)
|
$data = [
|
||||||
VALUES (:cust,:content,:section,:ver,:editor,:json,:html,:craft,:settings)"
|
'customer_id' => $customerId,
|
||||||
);
|
'content_id' => $contentId,
|
||||||
$stmt->execute([
|
'section_id' => $sectionId,
|
||||||
':cust' => $customerId,
|
'version_no' => $nextVersion,
|
||||||
':content' => $contentId,
|
];
|
||||||
':section' => $sectionId,
|
if ($versionCols['editor']) $data[$versionCols['editor']] = $editorType;
|
||||||
':ver' => $nextVersion,
|
if ($versionCols['json']) $data[$versionCols['json']] = $json;
|
||||||
':editor' => $editorType,
|
if ($versionCols['html']) $data[$versionCols['html']] = $html;
|
||||||
':json' => $json,
|
if ($versionCols['css']) $data[$versionCols['css']] = $css;
|
||||||
':html' => $html,
|
if ($versionCols['craft']) $data[$versionCols['craft']] = $craftJson;
|
||||||
':craft' => $craftJson,
|
if ($versionCols['settings']) $data[$versionCols['settings']] = $settings;
|
||||||
':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(
|
$cleanup = $this->pdo->prepare(
|
||||||
"DELETE FROM `$table` WHERE `id` IN (
|
"DELETE FROM `$table` WHERE `id` IN (
|
||||||
@@ -1048,12 +1069,14 @@ class ApiKernel
|
|||||||
if (!$version) $this->fail('Not found', ['id' => $versionId], 404);
|
if (!$version) $this->fail('Not found', ['id' => $versionId], 404);
|
||||||
|
|
||||||
$itemCols = $this->resolveContentItemColumns($itemsTable);
|
$itemCols = $this->resolveContentItemColumns($itemsTable);
|
||||||
|
$versionCols = $this->resolveContentVersionColumns($versionsTable);
|
||||||
$data = [];
|
$data = [];
|
||||||
if (!empty($itemCols['json'])) $data[$itemCols['json']] = $version['json_content'] ?? null;
|
if (!empty($itemCols['json']) && $versionCols['json']) $data[$itemCols['json']] = $version[$versionCols['json']] ?? null;
|
||||||
if (!empty($itemCols['html'])) $data[$itemCols['html']] = $version['html'] ?? null;
|
if (!empty($itemCols['html']) && $versionCols['html']) $data[$itemCols['html']] = $version[$versionCols['html']] ?? null;
|
||||||
if (!empty($itemCols['craft'])) $data[$itemCols['craft']] = $version['craft_json'] ?? null;
|
if (!empty($itemCols['css']) && $versionCols['css']) $data[$itemCols['css']] = $version[$versionCols['css']] ?? null;
|
||||||
if (!empty($itemCols['settings'])) $data[$itemCols['settings']] = $version['settings_json'] ?? null;
|
if (!empty($itemCols['craft']) && $versionCols['craft']) $data[$itemCols['craft']] = $version[$versionCols['craft']] ?? null;
|
||||||
if (!empty($itemCols['editor'])) $data[$itemCols['editor']] = $version['editor_type'] ?? 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) {
|
if ($data) {
|
||||||
$set = implode(',', array_map(static fn($c) => "`$c` = :$c", array_keys($data)));
|
$set = implode(',', array_map(static fn($c) => "`$c` = :$c", array_keys($data)));
|
||||||
|
|||||||
Reference in New Issue
Block a user