Warnung deaktivierung Template
This commit is contained in:
@@ -2204,6 +2204,104 @@ class ApiKernel
|
||||
]);
|
||||
}
|
||||
|
||||
private function handleTemplateReferences(): void
|
||||
{
|
||||
$auth = $this->requireAuth();
|
||||
$customerId = (int)($auth['customer_id'] ?? 0);
|
||||
if ($customerId <= 0) {
|
||||
$this->fail('Customer context missing', null, 500);
|
||||
}
|
||||
|
||||
$templateId = (int)$this->val($this->in, ['template_id', 'id', 'template'], 0);
|
||||
if ($templateId <= 0) {
|
||||
$this->fail('template_id required', null, 422);
|
||||
}
|
||||
|
||||
$references = $this->findTemplateReferences($customerId, $templateId);
|
||||
|
||||
$this->respond([
|
||||
'ok' => true,
|
||||
'template_id' => $templateId,
|
||||
'count' => count($references),
|
||||
'references' => $references,
|
||||
]);
|
||||
}
|
||||
|
||||
private function findTemplateReferences(int $customerId, int $templateId): array
|
||||
{
|
||||
$out = [];
|
||||
$matches = function (?string $html) use ($templateId): bool {
|
||||
if (!$html) return false;
|
||||
$id = preg_quote((string)$templateId, '/');
|
||||
$typePattern = '/data-ref-type\s*=\s*(["\"])template\1/i';
|
||||
$idPattern = '/data-ref-id\s*=\s*(["\"])' . $id . '\1/i';
|
||||
return (bool)(preg_match($typePattern, $html) && preg_match($idPattern, $html));
|
||||
};
|
||||
|
||||
if ($this->useUnifiedContent()) {
|
||||
$section = $this->ensureEmailtemplateSection($customerId);
|
||||
if (!$section) return [];
|
||||
|
||||
$itemsTable = $this->contentItemsTable();
|
||||
if (!$this->tableExists($itemsTable)) return [];
|
||||
$itemCols = $this->resolveContentItemColumns($itemsTable);
|
||||
$htmlCol = $itemCols['html'];
|
||||
|
||||
$versionsTable = $this->contentVersionsTable();
|
||||
$versionCols = ($this->tableExists($versionsTable)) ? $this->resolveContentVersionColumns($versionsTable) : null;
|
||||
$versionHtmlCol = $versionCols['html'] ?? null;
|
||||
$versionActiveCol = $versionCols['is_active'] ?? null;
|
||||
|
||||
$select = "i.`id` AS id, i.`name` AS name";
|
||||
if ($htmlCol) $select .= ", i.`$htmlCol` AS item_html";
|
||||
$join = '';
|
||||
if ($versionHtmlCol && $versionActiveCol) {
|
||||
$select .= ", v.`$versionHtmlCol` AS version_html";
|
||||
$join = "LEFT JOIN `$versionsTable` v ON v.`content_id` = i.`id` AND v.`$versionActiveCol` = 1";
|
||||
}
|
||||
$sql = "SELECT $select FROM `$itemsTable` i $join WHERE i.`customer_id` = :cid AND i.`section_id` = :sid AND i.`id` <> :id";
|
||||
$stmt = $this->pdo->prepare($sql);
|
||||
$stmt->execute([':cid' => $customerId, ':sid' => (int)$section['id'], ':id' => $templateId]);
|
||||
$rows = $stmt->fetchAll() ?: [];
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$html = (string)($row['version_html'] ?? $row['item_html'] ?? '');
|
||||
if ($matches($html)) {
|
||||
$out[] = [
|
||||
'id' => (int)($row['id'] ?? 0),
|
||||
'name' => (string)($row['name'] ?? ''),
|
||||
];
|
||||
}
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
$table = $this->tableMap['templates'] ?? null;
|
||||
if (!$table || !$this->tableExists($table)) return [];
|
||||
|
||||
[$idCol, $allCols] = $this->resolveIdCol('templates');
|
||||
$htmlCol = $this->firstExisting($allCols, ['html', 'body', 'markup', 'content']);
|
||||
if (!$htmlCol) return [];
|
||||
$nameCol = $this->conf['columns']['templates']['name'] ?? ($this->firstExisting($allCols, ['name']) ?: $idCol);
|
||||
|
||||
[$tw, $tp] = $this->tenantWhere(['customer_id' => $customerId]);
|
||||
$sql = "SELECT `$idCol` AS id, `$nameCol` AS name, `$htmlCol` AS html FROM `$table` WHERE `$idCol` <> :id" . $tw;
|
||||
$stmt = $this->pdo->prepare($sql);
|
||||
$stmt->bindValue(':id', $templateId, PDO::PARAM_INT);
|
||||
foreach ($tp as $k => $v) $stmt->bindValue($k, $v);
|
||||
$stmt->execute();
|
||||
$rows = $stmt->fetchAll() ?: [];
|
||||
foreach ($rows as $row) {
|
||||
if ($matches((string)($row['html'] ?? ''))) {
|
||||
$out[] = [
|
||||
'id' => (int)($row['id'] ?? 0),
|
||||
'name' => (string)($row['name'] ?? ''),
|
||||
];
|
||||
}
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
private function handleExternalRender(): void
|
||||
{
|
||||
$token = trim((string)($this->in['token'] ?? ''));
|
||||
@@ -2536,6 +2634,9 @@ class ApiKernel
|
||||
case 'templates.test_send':
|
||||
$this->handleTemplateTestSend();
|
||||
break;
|
||||
case 'templates.references':
|
||||
$this->handleTemplateReferences();
|
||||
break;
|
||||
case 'sections_config.reorder':
|
||||
$this->handleSectionsConfigReorder();
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user