This commit is contained in:
2026-01-21 23:46:19 +01:00
parent 012ec95ba1
commit 274d8b1703

View File

@@ -445,23 +445,37 @@ class ApiKernel
} }
} }
private function activateContentVersion(int $customerId, int $contentId, int $versionId): void private function activateContentVersion(int $customerId, int $contentId, int $versionId): bool
{ {
$table = $this->contentVersionsTable(); $table = $this->contentVersionsTable();
if (!$this->tableExists($table)) return; if (!$this->tableExists($table)) return false;
$this->pdo->prepare("UPDATE `$table` SET `is_active` = 0 WHERE `customer_id` = :cid AND `content_id` = :content") $versionCols = $this->resolveContentVersionColumns($table);
$isActiveCol = $versionCols['is_active'];
$wasActiveCol = $versionCols['was_active'];
if (!$isActiveCol) return false;
$this->pdo->prepare("UPDATE `$table` SET `$isActiveCol` = 0 WHERE `customer_id` = :cid AND `content_id` = :content")
->execute([':cid' => $customerId, ':content' => $contentId]); ->execute([':cid' => $customerId, ':content' => $contentId]);
$this->pdo->prepare(
"UPDATE `$table` SET `is_active` = 1, `was_active` = 1 WHERE `customer_id` = :cid AND `content_id` = :content AND `id` = :id LIMIT 1" $set = "`$isActiveCol` = 1";
)->execute([':cid' => $customerId, ':content' => $contentId, ':id' => $versionId]); if ($wasActiveCol) $set .= ", `$wasActiveCol` = 1";
$stmt = $this->pdo->prepare(
"UPDATE `$table` SET $set WHERE `customer_id` = :cid AND `content_id` = :content AND `id` = :id LIMIT 1"
);
$stmt->execute([':cid' => $customerId, ':content' => $contentId, ':id' => $versionId]);
return $stmt->rowCount() > 0;
} }
private function deactivateContentVersion(int $customerId, int $contentId): void private function deactivateContentVersion(int $customerId, int $contentId): bool
{ {
$table = $this->contentVersionsTable(); $table = $this->contentVersionsTable();
if (!$this->tableExists($table)) return; if (!$this->tableExists($table)) return false;
$this->pdo->prepare("UPDATE `$table` SET `is_active` = 0 WHERE `customer_id` = :cid AND `content_id` = :content") $versionCols = $this->resolveContentVersionColumns($table);
->execute([':cid' => $customerId, ':content' => $contentId]); $isActiveCol = $versionCols['is_active'];
if (!$isActiveCol) return false;
$stmt = $this->pdo->prepare("UPDATE `$table` SET `$isActiveCol` = 0 WHERE `customer_id` = :cid AND `content_id` = :content");
$stmt->execute([':cid' => $customerId, ':content' => $contentId]);
return $stmt->rowCount() > 0;
} }
private function isLegacyContentKind(string $kind): bool private function isLegacyContentKind(string $kind): bool
@@ -1213,7 +1227,8 @@ class ApiKernel
$row = $stmt->fetch(); $row = $stmt->fetch();
if (!$row) $this->fail('Not found', ['id' => $versionId], 404); if (!$row) $this->fail('Not found', ['id' => $versionId], 404);
$this->activateContentVersion($customerId, (int)$row['content_id'], $versionId); $ok = $this->activateContentVersion($customerId, (int)$row['content_id'], $versionId);
if (!$ok) $this->fail('Activation failed', ['id' => $versionId], 500);
$this->respond(['ok' => true, 'activated' => true, 'id' => $versionId]); $this->respond(['ok' => true, 'activated' => true, 'id' => $versionId]);
} }
@@ -1225,7 +1240,8 @@ class ApiKernel
$contentId = (int)$this->val($this->in, ['content_id', 'content'], 0); $contentId = (int)$this->val($this->in, ['content_id', 'content'], 0);
if ($contentId <= 0) $this->fail('content_id required', null, 422); if ($contentId <= 0) $this->fail('content_id required', null, 422);
$this->deactivateContentVersion($customerId, $contentId); $ok = $this->deactivateContentVersion($customerId, $contentId);
if (!$ok) $this->fail('Deactivation failed', ['content_id' => $contentId], 500);
$this->respond(['ok' => true, 'deactivated' => true, 'content_id' => $contentId]); $this->respond(['ok' => true, 'deactivated' => true, 'content_id' => $contentId]);
} }