Skip to content

Commit 833778f

Browse files
committed
better codestyle
1 parent be14262 commit 833778f

File tree

1 file changed

+40
-30
lines changed

1 file changed

+40
-30
lines changed

files_wbb/lib/action/ChangeAuthorAction.class.php

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use wbb\data\post\Post;
1212
use wbb\data\post\PostAction;
1313
use wbb\data\post\PostEditor;
14+
use wbb\data\thread\Thread;
1415
use wbb\data\thread\ThreadAction;
1516
use wcf\data\user\User;
1617
use wcf\http\Helper;
@@ -62,36 +63,8 @@ public function handle(ServerRequestInterface $request): ResponseInterface
6263
throw new IllegalLinkException();
6364
}
6465

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);
9568

9669
return new JsonResponse([]);
9770
} else {
@@ -120,4 +93,41 @@ private function getForm(Post $post): Psr15DialogForm
12093

12194
return $form;
12295
}
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+
}
123133
}

0 commit comments

Comments
 (0)