adasd
This commit is contained in:
@@ -1315,6 +1315,38 @@ class ApiKernel
|
||||
$this->respond(['ok' => true, 'deactivated' => true, 'content_id' => $contentId]);
|
||||
}
|
||||
|
||||
private function handleContentVersionsDelete(): void
|
||||
{
|
||||
$auth = $this->requireAuth();
|
||||
$customerId = (int)($auth['customer_id'] ?? 0);
|
||||
if ($customerId <= 0) $this->fail('Customer context missing', null, 500);
|
||||
$versionId = (int)$this->val($this->in, ['id', 'version_id', 'version'], 0);
|
||||
if ($versionId <= 0) $this->fail('version id required', null, 422);
|
||||
$contentId = (int)$this->val($this->in, ['content_id', 'content'], 0);
|
||||
|
||||
$table = $this->contentVersionsTable();
|
||||
if (!$this->tableExists($table)) $this->fail('Versions table not available', null, 500);
|
||||
|
||||
$sql = "SELECT `id`,`content_id`,`customer_id`,`is_active` FROM `$table` WHERE `id` = :id AND `customer_id` = :cid";
|
||||
$params = [':id' => $versionId, ':cid' => $customerId];
|
||||
if ($contentId > 0) {
|
||||
$sql .= " AND `content_id` = :content";
|
||||
$params[':content'] = $contentId;
|
||||
}
|
||||
$sql .= " LIMIT 1";
|
||||
$stmt = $this->pdo->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$row = $stmt->fetch();
|
||||
if (!$row) $this->fail('Not found', ['id' => $versionId], 404);
|
||||
if ((int)($row['is_active'] ?? 0) === 1) {
|
||||
$this->fail('Active versions cannot be deleted', ['id' => $versionId], 422);
|
||||
}
|
||||
|
||||
$stmt = $this->pdo->prepare("DELETE FROM `$table` WHERE `id` = :id AND `customer_id` = :cid LIMIT 1");
|
||||
$stmt->execute([':id' => $versionId, ':cid' => $customerId]);
|
||||
$this->respond(['ok' => true, 'deleted' => true, 'id' => $versionId]);
|
||||
}
|
||||
|
||||
private function handleSectionsConfigList(): void
|
||||
{
|
||||
$auth = $this->requireAuth();
|
||||
@@ -2516,6 +2548,9 @@ class ApiKernel
|
||||
case 'content_versions.deactivate':
|
||||
$this->handleContentVersionsDeactivate();
|
||||
break;
|
||||
case 'content_versions.delete':
|
||||
$this->handleContentVersionsDelete();
|
||||
break;
|
||||
|
||||
/* ---------- CRUD HANDLER ---------- */
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user