asd
This commit is contained in:
@@ -431,14 +431,7 @@ class ApiKernel
|
||||
$stmt->execute();
|
||||
$newId = (int)$this->pdo->lastInsertId();
|
||||
|
||||
$cleanup = $this->pdo->prepare(
|
||||
"DELETE FROM `$table` WHERE `id` IN (
|
||||
SELECT `id` FROM (
|
||||
SELECT `id` FROM `$table` WHERE `content_id` = :cid ORDER BY `id` DESC LIMIT 10, 1000000
|
||||
) t
|
||||
)"
|
||||
);
|
||||
$cleanup->execute([':cid' => $contentId]);
|
||||
$this->applyContentVersionRetention($customerId, $contentId);
|
||||
return $newId;
|
||||
} catch (Throwable $e) {
|
||||
// Versioning darf nicht das Speichern blockieren.
|
||||
@@ -446,6 +439,35 @@ class ApiKernel
|
||||
}
|
||||
}
|
||||
|
||||
private function applyContentVersionRetention(int $customerId, int $contentId): void
|
||||
{
|
||||
$limit = $this->getContentVersionRetentionLimit($customerId);
|
||||
if ($limit <= 0) return;
|
||||
$table = $this->contentVersionsTable();
|
||||
if (!$this->tableExists($table)) return;
|
||||
try {
|
||||
$versionCols = $this->resolveContentVersionColumns($table);
|
||||
$isActiveCol = $versionCols['is_active'];
|
||||
$activeFilter = $isActiveCol ? " AND (`$isActiveCol` IS NULL OR `$isActiveCol` = 0)" : '';
|
||||
$keepSql = "SELECT `id` FROM `$table` WHERE `content_id` = :cid ORDER BY `version_no` DESC, `id` DESC LIMIT :lim";
|
||||
$deleteSql = "DELETE FROM `$table` WHERE `content_id` = :cid$activeFilter AND `id` NOT IN (SELECT `id` FROM ($keepSql) AS keep_ids)";
|
||||
$stmt = $this->pdo->prepare($deleteSql);
|
||||
$stmt->bindValue(':cid', $contentId, PDO::PARAM_INT);
|
||||
$stmt->bindValue(':lim', $limit, PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
} catch (Throwable $e) {
|
||||
// Retention darf nicht das Speichern blockieren.
|
||||
}
|
||||
}
|
||||
|
||||
private function getContentVersionRetentionLimit(int $customerId): int
|
||||
{
|
||||
if ($customerId <= 0) return 0;
|
||||
$settings = $this->getCustomerSettings($customerId);
|
||||
$limit = (int)($settings['versions_retention'] ?? 0);
|
||||
return max(0, $limit);
|
||||
}
|
||||
|
||||
private function activateContentVersion(int $customerId, int $contentId, int $versionId): bool
|
||||
{
|
||||
$table = $this->contentVersionsTable();
|
||||
@@ -3711,13 +3733,14 @@ class ApiKernel
|
||||
$hasSenderToken = array_key_exists('sender_token', $this->in);
|
||||
$hasExternalToken = array_key_exists('external_api_token', $this->in);
|
||||
$hasEditorDefault = array_key_exists('editor_default', $this->in);
|
||||
$hasVersionsRetention = array_key_exists('versions_retention', $this->in);
|
||||
$hasListSort = array_key_exists('list_sort', $this->in);
|
||||
$hasBridgeTables = array_key_exists('bridge_tables', $this->in);
|
||||
$rotateBridge = !empty($this->in['rotate_bridge_token']);
|
||||
$rotateSender = !empty($this->in['rotate_sender_token']);
|
||||
$rotateExternal = !empty($this->in['rotate_external_token']);
|
||||
$onlyListSort = $hasListSort && !$hasBridgeUrl && !$hasBridgeToken && !$hasSenderToken && !$hasExternalToken
|
||||
&& !$hasEditorDefault && !$hasBridgeTables && !$rotateBridge && !$rotateSender && !$rotateExternal;
|
||||
&& !$hasEditorDefault && !$hasBridgeTables && !$hasVersionsRetention && !$rotateBridge && !$rotateSender && !$rotateExternal;
|
||||
|
||||
if (!$onlyListSort) {
|
||||
$this->ensureRole($user, ['owner', 'admin']);
|
||||
@@ -3730,6 +3753,7 @@ class ApiKernel
|
||||
$senderToken = $hasSenderToken ? trim((string)($this->in['sender_token'] ?? '')) : (string)($settings['sender_token'] ?? '');
|
||||
$externalToken = $hasExternalToken ? trim((string)($this->in['external_api_token'] ?? '')) : (string)($settings['external_api_token'] ?? '');
|
||||
$editorDefault = $hasEditorDefault ? strtolower(trim((string)($this->in['editor_default'] ?? ''))) : strtolower((string)($settings['editor_default'] ?? ''));
|
||||
$versionsRetention = $hasVersionsRetention ? (int)($this->in['versions_retention'] ?? 0) : (int)($settings['versions_retention'] ?? 0);
|
||||
$listSort = $hasListSort ? strtolower(trim((string)($this->in['list_sort'] ?? ''))) : '';
|
||||
$bridgeTables = $hasBridgeTables ? $this->normalizeBridgeTables($this->in['bridge_tables'] ?? []) : ($settings['bridge_tables'] ?? []);
|
||||
|
||||
@@ -3749,6 +3773,9 @@ class ApiKernel
|
||||
if ($editorDefault !== '' && !in_array($editorDefault, ['grapesjs', 'craftjs'], true)) {
|
||||
$this->fail('Ungültiger Editor-Typ', null, 422);
|
||||
}
|
||||
if ($versionsRetention < 0) {
|
||||
$this->fail('Ungültiger Aufbewahrungswert', null, 422);
|
||||
}
|
||||
|
||||
$settings = $this->saveCustomerSettings($customerId, [
|
||||
'bridge_url' => $bridgeUrl,
|
||||
@@ -3757,6 +3784,7 @@ class ApiKernel
|
||||
'external_api_token' => $externalToken,
|
||||
'editor_default' => $editorDefault ?: null,
|
||||
'bridge_tables' => $bridgeTables,
|
||||
'versions_retention' => $versionsRetention,
|
||||
]);
|
||||
} else {
|
||||
$settings = $customerId ? $this->ensureSettingsTokens($customerId, $settings) : $settings;
|
||||
@@ -4318,7 +4346,7 @@ class ApiKernel
|
||||
{
|
||||
if ($customerId <= 0) return [];
|
||||
$this->ensureCustomerSettingsTableExists();
|
||||
$allowed = ['bridge_url', 'bridge_token', 'sender_token', 'external_api_token', 'editor_default', 'bridge_tables', 'bridge_setup'];
|
||||
$allowed = ['bridge_url', 'bridge_token', 'sender_token', 'external_api_token', 'editor_default', 'bridge_tables', 'bridge_setup', 'versions_retention'];
|
||||
$fields = array_intersect_key($data, array_flip($allowed));
|
||||
if (!$fields) return $this->getCustomerSettings($customerId);
|
||||
if (array_key_exists('bridge_tables', $fields)) {
|
||||
@@ -4384,6 +4412,11 @@ class ApiKernel
|
||||
if (empty($row['editor_default'])) {
|
||||
$row['editor_default'] = 'grapesjs';
|
||||
}
|
||||
if (!isset($row['versions_retention']) || $row['versions_retention'] === '') {
|
||||
$row['versions_retention'] = 0;
|
||||
} else {
|
||||
$row['versions_retention'] = max(0, (int)$row['versions_retention']);
|
||||
}
|
||||
return $row;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user