sadasd
This commit is contained in:
@@ -1 +1 @@
|
||||
1.2.10
|
||||
1.2.11
|
||||
@@ -2217,7 +2217,11 @@ class ApiKernel
|
||||
$this->fail('template_id required', null, 422);
|
||||
}
|
||||
|
||||
$references = $this->findTemplateReferences($customerId, $templateId);
|
||||
$debug = [];
|
||||
$references = $this->findTemplateReferences($customerId, $templateId, $debug);
|
||||
if (!empty($debug)) {
|
||||
$this->writeDebugLog('templates_references_debug', $debug);
|
||||
}
|
||||
|
||||
$this->respond([
|
||||
'ok' => true,
|
||||
@@ -2227,10 +2231,19 @@ class ApiKernel
|
||||
]);
|
||||
}
|
||||
|
||||
private function findTemplateReferences(int $customerId, int $templateId): array
|
||||
private function findTemplateReferences(int $customerId, int $templateId, array &$debug = []): array
|
||||
{
|
||||
$out = [];
|
||||
$seen = [];
|
||||
$debug = [
|
||||
'time' => date(DATE_ATOM),
|
||||
'customer_id' => $customerId,
|
||||
'template_id' => $templateId,
|
||||
'use_unified' => $this->useUnifiedContent(),
|
||||
'scanned_rows' => 0,
|
||||
'matched_rows' => [],
|
||||
'template_items_matches' => [],
|
||||
];
|
||||
$matches = function (?string $html, array $libKinds = []) use ($templateId): bool {
|
||||
if (!$html) return false;
|
||||
$id = preg_quote((string)$templateId, '/');
|
||||
@@ -2259,6 +2272,10 @@ class ApiKernel
|
||||
$section = $this->ensureEmailtemplateSection($customerId);
|
||||
if (!$section) return [];
|
||||
$libKinds = [strtolower((string)($section['slug'] ?? 'emailtemplate'))];
|
||||
$debug['section'] = [
|
||||
'id' => (int)($section['id'] ?? 0),
|
||||
'slug' => (string)($section['slug'] ?? ''),
|
||||
];
|
||||
|
||||
$itemsTable = $this->contentItemsTable();
|
||||
if (!$this->tableExists($itemsTable)) return [];
|
||||
@@ -2275,6 +2292,14 @@ class ApiKernel
|
||||
$versionCraftCol = $versionCols['craft'] ?? null;
|
||||
$versionActiveCol = $versionCols['is_active'] ?? null;
|
||||
$versionSettingsCol = $versionCols['settings'] ?? null;
|
||||
$debug['tables'] = [
|
||||
'items' => $itemsTable,
|
||||
'versions' => $versionsTable,
|
||||
];
|
||||
$debug['columns'] = [
|
||||
'item' => $itemCols,
|
||||
'version' => $versionCols,
|
||||
];
|
||||
|
||||
$select = "i.`id` AS id, i.`name` AS name";
|
||||
if ($htmlCol) $select .= ", i.`$htmlCol` AS item_html";
|
||||
@@ -2304,6 +2329,7 @@ class ApiKernel
|
||||
$rows = $stmt->fetchAll() ?: [];
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$debug['scanned_rows']++;
|
||||
$blobs = [
|
||||
(string)($row['version_html'] ?? ''),
|
||||
(string)($row['item_html'] ?? ''),
|
||||
@@ -2315,8 +2341,22 @@ class ApiKernel
|
||||
(string)($row['item_settings'] ?? ''),
|
||||
];
|
||||
$found = false;
|
||||
foreach ($blobs as $blob) {
|
||||
if ($matches($blob, $libKinds)) { $found = true; break; }
|
||||
$where = [];
|
||||
$blobKeys = [
|
||||
'version_html',
|
||||
'item_html',
|
||||
'version_json',
|
||||
'item_json',
|
||||
'version_craft',
|
||||
'item_craft',
|
||||
'version_settings',
|
||||
'item_settings',
|
||||
];
|
||||
foreach ($blobs as $idx => $blob) {
|
||||
if ($matches($blob, $libKinds)) {
|
||||
$found = true;
|
||||
$where[] = $blobKeys[$idx] ?? (string)$idx;
|
||||
}
|
||||
}
|
||||
if ($found) {
|
||||
$id = (int)($row['id'] ?? 0);
|
||||
@@ -2326,6 +2366,13 @@ class ApiKernel
|
||||
'id' => $id,
|
||||
'name' => (string)($row['name'] ?? ''),
|
||||
];
|
||||
if (count($debug['matched_rows']) < 50) {
|
||||
$debug['matched_rows'][] = [
|
||||
'id' => $id,
|
||||
'name' => (string)($row['name'] ?? ''),
|
||||
'where' => $where,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2360,8 +2407,13 @@ class ApiKernel
|
||||
(string)($row['settings'] ?? ''),
|
||||
];
|
||||
$found = false;
|
||||
foreach ($blobs as $blob) {
|
||||
if ($matches($blob, $libKinds)) { $found = true; break; }
|
||||
$where = [];
|
||||
$blobKeys = ['html', 'json', 'craft', 'settings'];
|
||||
foreach ($blobs as $idx => $blob) {
|
||||
if ($matches($blob, $libKinds)) {
|
||||
$found = true;
|
||||
$where[] = $blobKeys[$idx] ?? (string)$idx;
|
||||
}
|
||||
}
|
||||
if ($found) {
|
||||
$id = (int)($row['id'] ?? 0);
|
||||
@@ -2371,6 +2423,13 @@ class ApiKernel
|
||||
'id' => $id,
|
||||
'name' => (string)($row['name'] ?? ''),
|
||||
];
|
||||
if (count($debug['matched_rows']) < 50) {
|
||||
$debug['matched_rows'][] = [
|
||||
'id' => $id,
|
||||
'name' => (string)($row['name'] ?? ''),
|
||||
'where' => $where,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2384,6 +2443,7 @@ class ApiKernel
|
||||
$stmt->execute([':cid' => $customerId, ':rid' => $templateId]);
|
||||
$ids = array_filter(array_map('intval', array_column($stmt->fetchAll() ?: [], 'template_id')));
|
||||
if ($ids) {
|
||||
$debug['template_items_matches'] = $ids;
|
||||
if ($this->useUnifiedContent()) {
|
||||
$section = $this->ensureEmailtemplateSection($customerId);
|
||||
if ($section) {
|
||||
|
||||
Reference in New Issue
Block a user