WebOrbiton
v1.0.0.1

StocketBase

30 lines · 711 B
  1. <?php
  2. ​
  3. declare(strict_types=1);
  4. ​
  5. if (count(get_included_files()) === 1) {
  6. http_response_code(403);
  7. exit;
  8. }
  9. ​
  10. if (!Auth::hasRoleAtLeast(Auth::ROLE_STORE_OWNER)) {
  11. return;
  12. }
  13. ​
  14. $db = Database::site();
  15. ​
  16. $categoryId = (int) ($_POST['category_id'] ?? 0);
  17. ​
  18. if ($categoryId <= 0) {
  19. return;
  20. }
  21. ​
  22. $clearProducts = $db->prepare('UPDATE products SET category_id = NULL WHERE category_id = :id');
  23. $clearProducts->execute(['id' => $categoryId]);
  24. ​
  25. $clearChildren = $db->prepare('UPDATE categories SET parent_id = NULL WHERE parent_id = :id');
  26. $clearChildren->execute(['id' => $categoryId]);
  27. ​
  28. $deleteCategory = $db->prepare('DELETE FROM categories WHERE id = :id');
  29. $deleteCategory->execute(['id' => $categoryId]);
  30. ​