inclide craft

This commit is contained in:
2026-01-19 00:10:26 +01:00
parent 8a23398853
commit 05fd31065d
12 changed files with 624 additions and 55 deletions

View File

@@ -453,20 +453,62 @@ class ApiKernel
$topHtml = ($htmlCol && isset($row[$htmlCol])) ? (string)$row[$htmlCol] : null;
$jsonCol = $this->firstExisting($allCols, ['json_content']);
$topContent = ($jsonCol && isset($row[$jsonCol])) ? $row[$jsonCol] : null;
$editorCol = $this->firstExisting($allCols, ['editor_type', 'editor']);
$craftCol = $this->firstExisting($allCols, ['craft_json', 'craft_content', 'craft_data']);
$editorType = $editorCol && isset($row[$editorCol]) ? strtolower((string)$row[$editorCol]) : '';
$pendingUpdate = [];
$gjsComponents = [];
if ($editorCol && $editorType === '') {
$settings = $this->getCustomerSettings((int)($auth['customer_id'] ?? 0));
$editorType = strtolower((string)($settings['editor_default'] ?? 'grapesjs'));
if (!in_array($editorType, ['grapesjs', 'craftjs'], true)) {
$editorType = 'grapesjs';
}
$pendingUpdate[$editorCol] = $editorType;
$rowOut[$editorCol] = $editorType;
}
if ($topContent !== null) {
$decodedContent = json_decode($topContent, true);
if (is_array($decodedContent)) {
$gjsComponents = $decodedContent;
}
}
if (empty($gjsComponents) && $topHtml !== null) {
$gjsComponents = $this->parseHtmlToGjsComponents($topHtml);
}
if ($editorType === 'grapesjs' && $jsonCol && empty($topContent) && $topHtml !== null) {
$pendingUpdate[$jsonCol] = $this->encodeJson($gjsComponents);
$topContent = $pendingUpdate[$jsonCol];
$rowOut[$jsonCol] = $pendingUpdate[$jsonCol];
}
if ($editorType === 'craftjs' && $craftCol) {
$craftPayload = isset($row[$craftCol]) ? (string)$row[$craftCol] : '';
if ($craftPayload === '') {
$pendingUpdate[$craftCol] = $this->encodeJson(['html' => (string)($topHtml ?? '')]);
$rowOut[$craftCol] = $pendingUpdate[$craftCol];
}
}
if ($pendingUpdate) {
$pendingUpdate[$idCol] = $row[$idCol] ?? $id;
[$tw, $tp] = $this->tenantWhere($auth);
$set = [];
foreach (array_keys($pendingUpdate) as $c) {
if ($c === $idCol) continue;
$set[] = "`$c` = :$c";
}
$sql = "UPDATE `$t` SET " . implode(',', $set) . " WHERE `$idCol` = :$idCol" . $tw . " LIMIT 1";
$stmt = $this->pdo->prepare($sql);
foreach ($pendingUpdate as $k => $v) $stmt->bindValue(":$k", $v);
foreach ($tp as $k => $v) $stmt->bindValue($k, $v);
$stmt->execute();
}
$usage = $this->calculateUsage($kind, (int)$rowOut['id'], $auth);
$this->respond([
@@ -478,6 +520,8 @@ class ApiKernel
'html' => $topHtml,
'content' => $topContent,
'gjs_components' => $gjsComponents,
'editor_type' => $editorType ?: null,
'craft_json' => $craftCol && isset($rowOut[$craftCol]) ? $rowOut[$craftCol] : null,
'usage' => $usage,
]);
}
@@ -510,9 +554,13 @@ class ApiKernel
: ['content_json', 'json', 'content', 'structure_json'];
$json = $this->val($this->in, $jsonKeys, null);
$settings = $this->val($this->in, ['settings_json', 'settings'], null);
$editorType = strtolower(trim((string)$this->val($this->in, ['editor_type', 'editor'], '')));
$craftJson = $this->val($this->in, ['craft_json', 'craft_content', 'craft_data'], null);
$templateId = $this->val($this->in, ['template_id', 'tpl_id'], null);
$sectionId = $this->val($this->in, ['section_id', 'sec_id'], null);
$blockId = $this->val($this->in, ['block_id', 'blk_id'], null);
$editorType = strtolower(trim((string)$this->val($this->in, ['editor_type', 'editor'], '')));
$craftJson = $this->val($this->in, ['craft_json', 'craft_content', 'craft_data'], null);
$data = [$nameCol => $name];
if ($kind === 'templates') {
@@ -541,6 +589,10 @@ class ApiKernel
$htmlDbCol = $this->firstExisting($allCols, ($kind === 'snippets' ? ['content'] : ['html', 'body', 'markup']));
$jsonDbCol = $this->firstExisting($allCols, ['json_content']);
$editorDbCol = $this->firstExisting($allCols, ['editor_type', 'editor']);
$craftDbCol = $this->firstExisting($allCols, ['craft_json', 'craft_content', 'craft_data']);
$editorDbCol = $this->firstExisting($allCols, ['editor_type', 'editor']);
$craftDbCol = $this->firstExisting($allCols, ['craft_json', 'craft_content', 'craft_data']);
// --- LOGIK mit ERWEITERTER PRÜFUNG START ---
@@ -570,6 +622,19 @@ class ApiKernel
}
// --- LOGIK mit ERWEITERTER PRÜFUNG ENDE ---
if ($editorDbCol) {
if ($editorType === '' && in_array($kind, ['templates', 'snippets'], true)) {
$settings = $this->getCustomerSettings((int)($auth['customer_id'] ?? 0));
$editorType = strtolower((string)($settings['editor_default'] ?? 'grapesjs'));
}
if ($editorType !== '' && in_array($editorType, ['grapesjs', 'craftjs'], true)) {
$data[$editorDbCol] = $editorType;
}
}
if ($craftDbCol && $craftJson !== null) {
$data[$craftDbCol] = is_string($craftJson) ? $craftJson : $this->encodeJson($craftJson);
}
$c = $this->firstExisting($allCols, ['settings_json', 'settings']);
if ($c && $settings !== null) $data[$c] = is_string($settings) ? $settings : $this->encodeJson($settings);
@@ -684,6 +749,13 @@ class ApiKernel
$data[$htmlDbCol] = (string)$html;
}
// --- LOGIK mit ERWEITERTER PRÜFUNG ENDE ---
if ($editorDbCol && $editorType !== '' && in_array($editorType, ['grapesjs', 'craftjs'], true)) {
$data[$editorDbCol] = $editorType;
}
if ($craftDbCol && $craftJson !== null) {
$data[$craftDbCol] = is_string($craftJson) ? $craftJson : $this->encodeJson($craftJson);
}
$c = $this->firstExisting($allCols, ['settings_json', 'settings']);
if ($settings !== null && $c) $data[$c] = is_string($settings) ? $settings : $this->encodeJson($settings);
@@ -1696,6 +1768,7 @@ class ApiKernel
$bridgeToken = trim((string)($this->in['bridge_token'] ?? ''));
$senderToken = trim((string)($this->in['sender_token'] ?? ''));
$externalToken = trim((string)($this->in['external_api_token'] ?? ''));
$editorDefault = strtolower(trim((string)($this->in['editor_default'] ?? '')));
$rotateBridge = !empty($this->in['rotate_bridge_token']);
$rotateSender = !empty($this->in['rotate_sender_token']);
$rotateExternal = !empty($this->in['rotate_external_token']);
@@ -1710,11 +1783,16 @@ class ApiKernel
if ($rotateSender || $senderToken === '') $senderToken = $this->generateToken();
if ($rotateExternal || $externalToken === '') $externalToken = $this->generateToken();
if ($editorDefault !== '' && !in_array($editorDefault, ['grapesjs', 'craftjs'], true)) {
$this->fail('Ungültiger Editor-Typ', null, 422);
}
$settings = $this->saveCustomerSettings($customerId, [
'bridge_url' => $bridgeUrl,
'bridge_token' => $bridgeToken,
'sender_token' => $senderToken,
'external_api_token' => $externalToken,
'editor_default' => $editorDefault ?: null,
'bridge_tables' => $bridgeTables,
]);
@@ -2240,7 +2318,7 @@ class ApiKernel
{
if ($customerId <= 0) return [];
$this->ensureCustomerSettingsTableExists();
$allowed = ['bridge_url', 'bridge_token', 'sender_token', 'external_api_token', 'bridge_tables', 'bridge_setup'];
$allowed = ['bridge_url', 'bridge_token', 'sender_token', 'external_api_token', 'editor_default', 'bridge_tables', 'bridge_setup'];
$fields = array_intersect_key($data, array_flip($allowed));
if (!$fields) return $this->getCustomerSettings($customerId);
if (array_key_exists('bridge_tables', $fields)) {
@@ -2303,6 +2381,9 @@ class ApiKernel
} else {
$row['bridge_setup'] = $this->defaultBridgeSetup();
}
if (empty($row['editor_default'])) {
$row['editor_default'] = 'grapesjs';
}
return $row;
}
@@ -2577,6 +2658,7 @@ CREATE TABLE IF NOT EXISTS `$table` (
`bridge_token` varchar(255) DEFAULT NULL,
`sender_token` varchar(255) DEFAULT NULL,
`external_api_token` varchar(255) DEFAULT NULL,
`editor_default` varchar(32) DEFAULT NULL,
`bridge_tables` text DEFAULT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
@@ -2615,6 +2697,9 @@ SQL;
if (!in_array('bridge_setup', $columns, true)) {
$missing[] = 'ADD COLUMN `bridge_setup` longtext DEFAULT NULL';
}
if (!in_array('editor_default', $columns, true)) {
$missing[] = 'ADD COLUMN `editor_default` varchar(32) DEFAULT NULL';
}
if (!$missing) {
return;