Skip to content

Commit

Permalink
move discussions to tag
Browse files Browse the repository at this point in the history
  • Loading branch information
imorland committed Nov 17, 2023
1 parent f9507a9 commit d00d239
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion src/Command/MarkUserAsSpammerHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,10 @@ public function handle(MarkUserAsSpammer $command): void

$this->reportToStopForumSpam($user);

$this->handleDiscussions($user, $actor);

$this->handleUser($user, $actor);
$this->handlePosts($user, $actor);
$this->handleDiscussions($user, $actor);

$this->events->dispatch(
new MarkedUserAsSpammer($user, $actor)
Expand Down Expand Up @@ -198,6 +199,8 @@ protected function handleDiscussions(User $user, User $actor): void
{
if ($this->deleteDiscussions) {
$user->discussions()->delete();
} elseif ($this->moveDiscussionsToQuarantine) {
$this->moveUserDiscussionsToQuarantine($user, $actor);
} else {
$user->discussions()->where('hidden_at', null)->chunk(50, function ($discussions) use ($actor) {
foreach ($discussions as $discussion) {
Expand All @@ -211,6 +214,44 @@ protected function handleDiscussions(User $user, User $actor): void
}
}

protected function moveUserDiscussionsToQuarantine(User $user, User $actor): void
{
if (! $this->moveDiscussionsToQuarantine) {
return;
}

$discussions = $user->discussions;
$quarantineTagsString = (string) $this->settings->get(self::settings_prefix.'moveDiscussionsToTags');

$tags = json_decode($quarantineTagsString);

if (! $tags) {
return;
}

$data = [];

foreach ($tags as $tag) {
$data[] = [
'type' => 'tags',
'id' => $tag,
];
}

foreach ($discussions as $discussion) {

$this->bus->dispatch(
new EditDiscussion($discussion->id, $actor, [
'relationships' => [
'tags' => [
'data' => $data,
],
],
])
);
}
}

protected function reportToStopForumSpam(User $user): void
{
if (! $this->reportToSfs) {
Expand Down

0 comments on commit d00d239

Please sign in to comment.