From 274d8b1703755ada499baf189b7443fea7371862 Mon Sep 17 00:00:00 2001 From: Lars Gebhardt-Kusche Date: Wed, 21 Jan 2026 23:46:19 +0100 Subject: [PATCH] asdasd --- src/ApiKernel.php | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/src/ApiKernel.php b/src/ApiKernel.php index e1e48d5..c571435 100644 --- a/src/ApiKernel.php +++ b/src/ApiKernel.php @@ -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(); - if (!$this->tableExists($table)) return; - $this->pdo->prepare("UPDATE `$table` SET `is_active` = 0 WHERE `customer_id` = :cid AND `content_id` = :content") + if (!$this->tableExists($table)) return false; + $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]); - $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" - )->execute([':cid' => $customerId, ':content' => $contentId, ':id' => $versionId]); + + $set = "`$isActiveCol` = 1"; + 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(); - if (!$this->tableExists($table)) return; - $this->pdo->prepare("UPDATE `$table` SET `is_active` = 0 WHERE `customer_id` = :cid AND `content_id` = :content") - ->execute([':cid' => $customerId, ':content' => $contentId]); + if (!$this->tableExists($table)) return false; + $versionCols = $this->resolveContentVersionColumns($table); + $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 @@ -1213,7 +1227,8 @@ class ApiKernel $row = $stmt->fetch(); 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]); } @@ -1225,7 +1240,8 @@ class ApiKernel $contentId = (int)$this->val($this->in, ['content_id', 'content'], 0); 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]); }