testversand

This commit is contained in:
2026-02-24 01:55:30 +01:00
parent 8801a8ba32
commit e55c88ac98
2 changed files with 37 additions and 9 deletions

View File

@@ -2258,11 +2258,38 @@ class ApiKernel
if ($customerId <= 0) $this->fail('Customer context missing', null, 500);
$section = $this->ensureEmailtemplateSection($customerId);
$itemsTable = $this->contentItemsTable();
$sql = "SELECT * FROM `$itemsTable` WHERE `customer_id` = :cid AND `section_id` = :sid AND `id` = :id LIMIT 1";
$itemCols = $this->resolveContentItemColumns($itemsTable);
$versionsTable = $this->contentVersionsTable();
$versionCols = $this->tableExists($versionsTable) ? $this->resolveContentVersionColumns($versionsTable) : null;
$versionId = (int)$this->val($this->in, ['version_id', 'content_version_id'], 0);
$selectCols = [];
if (!empty($itemCols['html'])) $selectCols[] = "i.`{$itemCols['html']}` AS item_html";
if (!empty($itemCols['json'])) $selectCols[] = "i.`{$itemCols['json']}` AS item_json";
if ($versionCols && !empty($versionCols['html'])) $selectCols[] = "v.`{$versionCols['html']}` AS version_html";
$join = '';
if ($versionCols) {
if ($versionId > 0) {
$join = "LEFT JOIN `$versionsTable` v ON v.`content_id` = i.`id` AND v.`id` = :vid";
} else {
$join = "LEFT JOIN `$versionsTable` v ON v.`content_id` = i.`id` AND v.`is_active` = 1";
}
}
$sql = "SELECT " . implode(',', $selectCols) . " FROM `$itemsTable` i $join WHERE i.`customer_id` = :cid AND i.`section_id` = :sid AND i.`id` = :id LIMIT 1";
$stmt = $this->pdo->prepare($sql);
$stmt->execute([':cid' => $customerId, ':sid' => (int)$section['id'], ':id' => $templateId]);
$params = [':cid' => $customerId, ':sid' => (int)$section['id'], ':id' => $templateId];
if ($versionId > 0 && $versionCols) {
$params[':vid'] = $versionId;
}
$stmt->execute($params);
$row = $stmt->fetch();
$html = $row ? (string)($row['html'] ?? '') : '';
$html = $row ? (string)($row['version_html'] ?? $row['item_html'] ?? '') : '';
if ($html === '' && $versionCols && $versionId <= 0) {
$sql = "SELECT " . implode(',', $selectCols) . " FROM `$itemsTable` i LEFT JOIN `$versionsTable` v ON v.`content_id` = i.`id` ORDER BY v.`created_at` DESC LIMIT 1";
$stmt = $this->pdo->prepare($sql);
$stmt->execute();
$row = $stmt->fetch();
$html = $row ? (string)($row['version_html'] ?? $row['item_html'] ?? '') : $html;
}
} else {
$t = $this->tableMap['templates'];
[$idCol, $allCols] = $this->resolveIdCol('templates');
@@ -2279,7 +2306,13 @@ class ApiKernel
if (!$row) {
$this->fail('Template not found', ['id' => $templateId], 404);
}
if ($html === '' && !empty($row['json_content'])) {
$jsonContent = '';
if ($row && array_key_exists('json_content', $row)) {
$jsonContent = (string)($row['json_content'] ?? '');
} elseif ($row && array_key_exists('item_json', $row)) {
$jsonContent = (string)($row['item_json'] ?? '');
}
if ($html === '' && $jsonContent !== '') {
$html = '<p>(Dieses Template enthält noch keine HTML-Inhalte.)</p>';
}