WebOrbiton
v2.0.0.1

Publisium

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