adasd
This commit is contained in:
11
schema.sql
11
schema.sql
@@ -139,6 +139,17 @@ CREATE TABLE IF NOT EXISTS `emailtemplate_sender_identities` (
|
||||
CONSTRAINT `fk_sender_customer` FOREIGN KEY (`customer_id`) REFERENCES `emailtemplate_customers` (`id`) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||
|
||||
-- Tabelle: emailtemplate_template_usage
|
||||
CREATE TABLE IF NOT EXISTS `emailtemplate_template_usage` (
|
||||
`template_id` int(10) unsigned NOT NULL,
|
||||
`customer_id` int(10) unsigned NOT NULL,
|
||||
`render_count` int(10) unsigned NOT NULL DEFAULT 0,
|
||||
`last_rendered_at` timestamp NULL DEFAULT NULL,
|
||||
PRIMARY KEY (`template_id`),
|
||||
KEY `idx_usage_customer` (`customer_id`),
|
||||
CONSTRAINT `fk_usage_template` FOREIGN KEY (`template_id`) REFERENCES `emailtemplate_templates` (`id`) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||
|
||||
-- Tabelle: emailtemplate_customer_users
|
||||
CREATE TABLE IF NOT EXISTS `emailtemplate_customer_users` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
|
||||
@@ -681,6 +681,11 @@ class ApiKernel
|
||||
$this->fail('Send failed', null, 500);
|
||||
}
|
||||
|
||||
$customerId = (int)($auth['customer_id'] ?? 0);
|
||||
if ($customerId > 0) {
|
||||
$this->incrementTemplateUsage($customerId, $templateId);
|
||||
}
|
||||
|
||||
$this->respond([
|
||||
'ok' => true,
|
||||
'template_id' => $templateId,
|
||||
@@ -820,6 +825,12 @@ class ApiKernel
|
||||
case 'account.senders.delete':
|
||||
$this->handleAccountSenderDelete();
|
||||
break;
|
||||
case 'dashboard.metrics':
|
||||
$this->handleDashboardMetrics();
|
||||
break;
|
||||
case 'dashboard.reset_usage':
|
||||
$this->handleDashboardResetUsage();
|
||||
break;
|
||||
case 'downloads.bridge':
|
||||
$this->handleDownloadFile('bridge');
|
||||
break;
|
||||
@@ -1584,6 +1595,36 @@ class ApiKernel
|
||||
$this->respond(['ok' => true, 'deleted' => true]);
|
||||
}
|
||||
|
||||
private function handleDashboardMetrics(): void
|
||||
{
|
||||
$user = $this->authService->requireAuth();
|
||||
$this->ensureRole($user, ['owner', 'admin']);
|
||||
$customerId = (int)($user['customer_id'] ?? 0);
|
||||
if ($customerId <= 0) $this->fail('Customer context missing', null, 500);
|
||||
$counts = $this->fetchResourceCounts($customerId);
|
||||
$usage = $this->listTemplateUsage($customerId);
|
||||
$this->respond([
|
||||
'ok' => true,
|
||||
'counts' => $counts,
|
||||
'usage' => $usage,
|
||||
]);
|
||||
}
|
||||
|
||||
private function handleDashboardResetUsage(): void
|
||||
{
|
||||
$user = $this->authService->requireAuth();
|
||||
$this->ensureRole($user, ['owner', 'admin']);
|
||||
$customerId = (int)($user['customer_id'] ?? 0);
|
||||
if ($customerId <= 0) $this->fail('Customer context missing', null, 500);
|
||||
$raw = $this->in['template_id'] ?? $this->in['templates'] ?? null;
|
||||
$ids = $this->extractIdList($raw);
|
||||
if (!$ids) {
|
||||
$this->fail('template_id required', null, 422);
|
||||
}
|
||||
$this->resetTemplateUsage($customerId, $ids);
|
||||
$this->respond(['ok' => true]);
|
||||
}
|
||||
|
||||
private function handleDownloadFile(string $type): void
|
||||
{
|
||||
$user = $this->authService->requireAuth();
|
||||
@@ -1637,15 +1678,20 @@ class ApiKernel
|
||||
if ($bridgeUrl === '' || $bridgeToken === '') {
|
||||
$this->fail('Bridge nicht konfiguriert', null, 422);
|
||||
}
|
||||
$settings = $this->getCustomerSettings($customerId);
|
||||
try {
|
||||
$schema = $this->fetchPlaceholderSchema($bridgeUrl, $bridgeToken, 0);
|
||||
} catch (Throwable $e) {
|
||||
$this->fail('Bridge request failed', $e->getMessage(), 502);
|
||||
return;
|
||||
}
|
||||
$tables = $schema['tables'] ?? [];
|
||||
if (!empty($settings['bridge_tables'])) {
|
||||
$tables = $this->filterSchemaTables($tables, $settings['bridge_tables']);
|
||||
}
|
||||
$this->respond([
|
||||
'ok' => true,
|
||||
'tables' => $schema['tables'] ?? [],
|
||||
'tables' => $tables,
|
||||
'fetched' => $schema['fetched'] ?? date(DATE_ATOM),
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user