Move.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * This file is part of the ForkBB <https://github.com/forkbb>.
  4. *
  5. * @copyright (c) Visman <mio.visman@yandex.ru, https://github.com/MioVisman>
  6. * @license The MIT License (MIT)
  7. */
  8. declare(strict_types=1);
  9. namespace ForkBB\Models\Topic;
  10. use ForkBB\Models\Action;
  11. use ForkBB\Models\Forum\Forum;
  12. use ForkBB\Models\Topic\Topic;
  13. class Move extends Action
  14. {
  15. /**
  16. * Перенос тем
  17. */
  18. public function move(bool $redirect, Forum $toForum, Topic ...$topics): void
  19. {
  20. $forums = [
  21. $toForum->id => $toForum,
  22. ];
  23. foreach ($topics as $topic) {
  24. if ($topic->parent === $toForum) {
  25. continue;
  26. }
  27. if ($redirect) {
  28. $rTopic = $this->c->topics->create();
  29. $rTopic->poster = $topic->poster;
  30. $rTopic->poster_id = $topic->poster_id;
  31. $rTopic->subject = $topic->subject;
  32. $rTopic->posted = $topic->posted;
  33. // $rTopic->first_post_id = $topic->first_post_id;
  34. $rTopic->last_post = $topic->last_post;
  35. // $rTopic->last_post_id = $topic->last_post_id;
  36. // $rTopic->last_poster = $topic->last_poster;
  37. // $rTopic->last_poster_id = $topic->last_poster_id;
  38. $rTopic->moved_to = $topic->id;
  39. $rTopic->forum_id = $topic->forum_id;
  40. $this->c->topics->insert($rTopic);
  41. }
  42. $forums[$topic->forum_id] = $topic->parent;
  43. $topic->forum_id = $toForum->id;
  44. $this->c->topics->update($topic);
  45. }
  46. foreach ($forums as $forum) {
  47. $this->c->forums->update($forum->calcStat());
  48. }
  49. }
  50. }