mirror of
https://github.com/flarum/core.git
synced 2025-10-18 10:16:09 +02:00
Convert the rest of the API to new action architecture
Also make some tweaks: - Merge SerializeAction::$include and SerializeAction::$includeAvailable into a keyed boolean array - Set defaults for SerializeAction::$limit and $limitMax - Rename SerializeAction::$sortAvailable to $sortFields
This commit is contained in:
@@ -22,14 +22,16 @@ class EditPostCommandHandler
|
||||
|
||||
$post->assertCan($user, 'edit');
|
||||
|
||||
if (isset($command->content)) {
|
||||
$post->revise($command->content, $user);
|
||||
if (isset($command->data['content'])) {
|
||||
$post->revise($command->data['content'], $user);
|
||||
}
|
||||
|
||||
if ($command->isHidden === true) {
|
||||
$post->hide($user);
|
||||
} elseif ($command->isHidden === false) {
|
||||
$post->restore($user);
|
||||
if (isset($command->data['isHidden'])) {
|
||||
if ($command->data['isHidden']) {
|
||||
$post->hide($user);
|
||||
} else {
|
||||
$post->restore($user);
|
||||
}
|
||||
}
|
||||
|
||||
event(new PostWillBeSaved($post, $command));
|
||||
|
@@ -22,23 +22,28 @@ class EditUserCommandHandler
|
||||
|
||||
$userToEdit->assertCan($user, 'edit');
|
||||
|
||||
if (isset($command->username)) {
|
||||
$userToEdit->rename($command->username);
|
||||
if (isset($command->data['username'])) {
|
||||
$userToEdit->rename($command->data['username']);
|
||||
}
|
||||
if (isset($command->email)) {
|
||||
$userToEdit->changeEmail($command->email);
|
||||
|
||||
if (isset($command->data['email'])) {
|
||||
$userToEdit->changeEmail($command->data['email']);
|
||||
}
|
||||
if (isset($command->password)) {
|
||||
$userToEdit->changePassword($command->password);
|
||||
|
||||
if (isset($command->data['password'])) {
|
||||
$userToEdit->changePassword($command->data['password']);
|
||||
}
|
||||
if (isset($command->bio)) {
|
||||
$userToEdit->changeBio($command->bio);
|
||||
|
||||
if (isset($command->data['bio'])) {
|
||||
$userToEdit->changeBio($command->data['bio']);
|
||||
}
|
||||
if (! empty($command->readTime)) {
|
||||
|
||||
if (! empty($command->data['readTime'])) {
|
||||
$userToEdit->markAllAsRead();
|
||||
}
|
||||
if (! empty($command->preferences)) {
|
||||
foreach ($command->preferences as $k => $v) {
|
||||
|
||||
if (! empty($command->data['preferences'])) {
|
||||
foreach ($command->data['preferences'] as $k => $v) {
|
||||
$userToEdit->setPreference($k, $v);
|
||||
}
|
||||
}
|
||||
|
@@ -34,7 +34,7 @@ class PostReplyCommandHandler
|
||||
// opportunity to alter the post entity based on data in the command.
|
||||
$post = CommentPost::reply(
|
||||
$command->discussionId,
|
||||
$command->content,
|
||||
array_get($command->data, 'content'),
|
||||
$user->id
|
||||
);
|
||||
|
||||
|
@@ -20,9 +20,9 @@ class RegisterUserCommandHandler
|
||||
// Before persistance, though, fire an event to give plugins an
|
||||
// opportunity to alter the post entity based on data in the command.
|
||||
$user = User::register(
|
||||
$command->username,
|
||||
$command->email,
|
||||
$command->password
|
||||
array_get($command->data, 'username'),
|
||||
array_get($command->data, 'email'),
|
||||
array_get($command->data, 'password')
|
||||
);
|
||||
|
||||
event(new UserWillBeSaved($user, $command));
|
||||
|
@@ -41,7 +41,7 @@ class StartDiscussionCommandHandler
|
||||
// will trigger a domain event that is slightly semantically incorrect
|
||||
// in this situation (PostWasPosted), we may need to reconsider someday.
|
||||
$post = $this->bus->dispatch(
|
||||
new PostReplyCommand($discussion->id, array_get($command->data, 'content'), $command->user)
|
||||
new PostReplyCommand($discussion->id, $command->user, $command->data)
|
||||
);
|
||||
|
||||
return $post->discussion;
|
||||
|
Reference in New Issue
Block a user