This commit is contained in:
2026-01-26 00:18:16 +01:00
parent d03c4a5d10
commit c905eb3fb0
4 changed files with 80 additions and 1 deletions

View File

@@ -1066,6 +1066,8 @@ class ApiKernel
break;
}
}
$requestedVersionId = (int)$this->val($this->in, ['version_id', 'versionId', 'version'], 0);
$updatedExistingVersion = false;
$set = implode(',', array_map(static fn($c) => "`$c` = :$c", array_keys($data)));
$data['id'] = $id;
@@ -1074,7 +1076,45 @@ class ApiKernel
$stmt = $this->pdo->prepare($sql);
foreach ($data as $k => $v) $stmt->bindValue(":$k", $v);
$stmt->execute();
if ($shouldSnapshot) {
if ($shouldSnapshot && $requestedVersionId > 0) {
try {
$versionsTable = $this->contentVersionsTable();
if ($this->tableExists($versionsTable)) {
$vCols = $this->resolveContentVersionColumns($versionsTable);
$stmt = $this->pdo->prepare(
"SELECT `id`,`content_id`,`customer_id`,`section_id`,`is_active`,`was_active` FROM `$versionsTable`
WHERE `id` = :id AND `customer_id` = :cid AND `content_id` = :content LIMIT 1"
);
$stmt->execute([':id' => $requestedVersionId, ':cid' => $customerId, ':content' => $id]);
$versionRow = $stmt->fetch();
if ($versionRow && (int)($versionRow['is_active'] ?? 0) === 0 && (int)($versionRow['was_active'] ?? 0) === 0) {
$vdata = [];
if ($htmlCol && isset($data[$htmlCol]) && !empty($vCols['html'])) $vdata[$vCols['html']] = $data[$htmlCol];
if ($jsonCol && isset($data[$jsonCol]) && !empty($vCols['json'])) $vdata[$vCols['json']] = $data[$jsonCol];
if ($craftCol && isset($data[$craftCol]) && !empty($vCols['craft'])) $vdata[$vCols['craft']] = $data[$craftCol];
if ($settingsCol && isset($data[$settingsCol]) && !empty($vCols['settings'])) $vdata[$vCols['settings']] = $data[$settingsCol];
if ($editorCol && isset($data[$editorCol]) && !empty($vCols['editor'])) $vdata[$vCols['editor']] = $data[$editorCol];
if ($vdata) {
$setVersion = implode(',', array_map(static fn($c) => "`$c` = :$c", array_keys($vdata)));
$vdata['id'] = $requestedVersionId;
$vdata['customer_id'] = $customerId;
$vdata['content_id'] = $id;
$sql = "UPDATE `$versionsTable` SET $setVersion WHERE `id` = :id AND `customer_id` = :customer_id AND `content_id` = :content_id LIMIT 1";
$stmt = $this->pdo->prepare($sql);
foreach ($vdata as $k => $v) $stmt->bindValue(":$k", $v);
$stmt->execute();
$updatedExistingVersion = $stmt->rowCount() > 0;
if ($updatedExistingVersion && $activateVersion) {
$this->activateContentVersion($customerId, (int)$id, (int)$requestedVersionId);
}
}
}
}
} catch (Throwable $e) {
$updatedExistingVersion = false;
}
}
if ($shouldSnapshot && !$updatedExistingVersion) {
try {
$stmt = $this->pdo->prepare("SELECT * FROM `$itemsTable` WHERE `customer_id` = :cid AND `id` = :id LIMIT 1");
$stmt->execute([':cid' => $customerId, ':id' => $id]);