v1.0.0.0
StocketBase
- <?php
-
- declare(strict_types=1);
-
- if (count(get_included_files()) === 1) {
- http_response_code(403);
- exit;
- }
-
- if (!Auth::hasRoleAtLeast(Auth::ROLE_STORE_OWNER)) {
- return;
- }
-
- $db = Database::site();
-
- $categoryId = (int) ($_POST['category_id'] ?? 0);
-
- if ($categoryId <= 0) {
- return;
- }
-
- $clearProducts = $db->prepare('UPDATE products SET category_id = NULL WHERE category_id = :id');
- $clearProducts->execute(['id' => $categoryId]);
-
- $clearChildren = $db->prepare('UPDATE categories SET parent_id = NULL WHERE parent_id = :id');
- $clearChildren->execute(['id' => $categoryId]);
-
- $deleteCategory = $db->prepare('DELETE FROM categories WHERE id = :id');
- $deleteCategory->execute(['id' => $categoryId]);
-