|
11 | 11 | use wbb\data\post\Post; |
12 | 12 | use wbb\data\post\PostAction; |
13 | 13 | use wbb\data\post\PostEditor; |
| 14 | +use wbb\data\thread\Thread; |
14 | 15 | use wbb\data\thread\ThreadAction; |
15 | 16 | use wcf\data\user\User; |
16 | 17 | use wcf\http\Helper; |
@@ -62,36 +63,8 @@ public function handle(ServerRequestInterface $request): ResponseInterface |
62 | 63 | throw new IllegalLinkException(); |
63 | 64 | } |
64 | 65 |
|
65 | | - $action = new PostAction([$post], 'update', [ |
66 | | - 'data' => [ |
67 | | - 'userID' => $user->userID, |
68 | | - 'username' => $user->username, |
69 | | - ], |
70 | | - ]); |
71 | | - $action->executeAction(); |
72 | | - |
73 | | - $threadData = []; |
74 | | - if ($post->isFirstPost()) { |
75 | | - $threadData = [ |
76 | | - 'userID' => $user->userID, |
77 | | - 'username' => $user->username, |
78 | | - ]; |
79 | | - } |
80 | | - if ($thread->lastPostID == $post->postID) { |
81 | | - $threadData['lastPosterID'] = $user->userID; |
82 | | - $threadData['lastPoster'] = $user->username; |
83 | | - } |
84 | | - if ($threadData !== []) { |
85 | | - $action = new ThreadAction([$thread], 'update', [ |
86 | | - 'data' => $threadData, |
87 | | - ]); |
88 | | - $action->executeAction(); |
89 | | - } |
90 | | - |
91 | | - if ($oldUser->userID) { |
92 | | - PostEditor::updatePostCounter([$oldUser->userID => -1]); |
93 | | - } |
94 | | - PostEditor::updatePostCounter([$user->userID => 1]); |
| 66 | + $this->changePostOwner($post, $user); |
| 67 | + $this->changeThreadOwner($post, $thread, $user, $oldUser); |
95 | 68 |
|
96 | 69 | return new JsonResponse([]); |
97 | 70 | } else { |
@@ -120,4 +93,41 @@ private function getForm(Post $post): Psr15DialogForm |
120 | 93 |
|
121 | 94 | return $form; |
122 | 95 | } |
| 96 | + |
| 97 | + private function changePostOwner(Post $post, User $user): void |
| 98 | + { |
| 99 | + $action = new PostAction([$post], 'update', [ |
| 100 | + 'data' => [ |
| 101 | + 'userID' => $user->userID, |
| 102 | + 'username' => $user->username, |
| 103 | + ], |
| 104 | + ]); |
| 105 | + $action->executeAction(); |
| 106 | + } |
| 107 | + |
| 108 | + private function changeThreadOwner(Post $post, Thread $thread, User $user, User $oldUser): void |
| 109 | + { |
| 110 | + $threadData = []; |
| 111 | + if ($post->isFirstPost()) { |
| 112 | + $threadData = [ |
| 113 | + 'userID' => $user->userID, |
| 114 | + 'username' => $user->username, |
| 115 | + ]; |
| 116 | + } |
| 117 | + if ($thread->lastPostID == $post->postID) { |
| 118 | + $threadData['lastPosterID'] = $user->userID; |
| 119 | + $threadData['lastPoster'] = $user->username; |
| 120 | + } |
| 121 | + if ($threadData !== []) { |
| 122 | + $action = new ThreadAction([$thread], 'update', [ |
| 123 | + 'data' => $threadData, |
| 124 | + ]); |
| 125 | + $action->executeAction(); |
| 126 | + } |
| 127 | + |
| 128 | + if ($oldUser->userID) { |
| 129 | + PostEditor::updatePostCounter([$oldUser->userID => -1]); |
| 130 | + } |
| 131 | + PostEditor::updatePostCounter([$user->userID => 1]); |
| 132 | + } |
123 | 133 | } |
0 commit comments