testversand
This commit is contained in:
@@ -643,11 +643,6 @@ export async function loadList(section) {
|
|||||||
toast('Testversand: Ungültige ID', false);
|
toast('Testversand: Ungültige ID', false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const activeCheck = await apiAction('content.get', { method: 'GET', data: { id, section_id: section.id, active_only: 1 } }).catch(() => ({}));
|
|
||||||
if (!activeCheck?.active_version_id && !activeCheck?.item?.active_version_id) {
|
|
||||||
toast('Testversand nur mit aktiver Version möglich.', false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (window.AdminTestSend && typeof window.AdminTestSend.open === 'function') {
|
if (window.AdminTestSend && typeof window.AdminTestSend.open === 'function') {
|
||||||
window.AdminTestSend.open({ id, name: nm, section });
|
window.AdminTestSend.open({ id, name: nm, section });
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -2258,11 +2258,38 @@ class ApiKernel
|
|||||||
if ($customerId <= 0) $this->fail('Customer context missing', null, 500);
|
if ($customerId <= 0) $this->fail('Customer context missing', null, 500);
|
||||||
$section = $this->ensureEmailtemplateSection($customerId);
|
$section = $this->ensureEmailtemplateSection($customerId);
|
||||||
$itemsTable = $this->contentItemsTable();
|
$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 = $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();
|
$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 {
|
} else {
|
||||||
$t = $this->tableMap['templates'];
|
$t = $this->tableMap['templates'];
|
||||||
[$idCol, $allCols] = $this->resolveIdCol('templates');
|
[$idCol, $allCols] = $this->resolveIdCol('templates');
|
||||||
@@ -2279,7 +2306,13 @@ class ApiKernel
|
|||||||
if (!$row) {
|
if (!$row) {
|
||||||
$this->fail('Template not found', ['id' => $templateId], 404);
|
$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>';
|
$html = '<p>(Dieses Template enthält noch keine HTML-Inhalte.)</p>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user