Skip to content

Commit

Permalink
Merge pull request #55 from glowingblue/gb-dev/safer-join-query
Browse files Browse the repository at this point in the history
Specify wich table to select data from in join query
  • Loading branch information
clarkwinkelmann authored Oct 7, 2022
2 parents a93c592 + f8dbe4d commit 0d31436
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/Jobs/SendNotificationWhenDiscussionIsReTagged.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ public function handle(NotificationSyncer $notifications)
return;
}

$notify = User::where('users.id', '!=', $this->actor->id)
// The `select(...)` part is not mandatory here, but makes the query safer. See #55.
$notify = User::select('users.*')
->where('users.id', '!=', $this->actor->id)
->join('tag_user', 'tag_user.user_id', '=', 'users.id')
->whereIn('tag_user.tag_id', $tagIds->all())
->whereIn('tag_user.subscription', ['follow', 'lurk'])
Expand Down
4 changes: 3 additions & 1 deletion src/Jobs/SendNotificationWhenDiscussionIsStarted.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ public function handle(NotificationSyncer $notifications)
return;
}

$notify = User::where('users.id', '!=', $this->discussion->user_id)
// The `select(...)` part is not mandatory here, but makes the query safer. See #55.
$notify = User::select('users.*')
->where('users.id', '!=', $this->discussion->user_id)
->join('tag_user', 'tag_user.user_id', '=', 'users.id')
->whereIn('tag_user.tag_id', $tagIds->all())
->whereIn('tag_user.subscription', ['follow', 'lurk'])
Expand Down
2 changes: 2 additions & 0 deletions src/Jobs/SendNotificationWhenReplyIsPosted.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public function handle(NotificationSyncer $notifications)
}

$notify = $this->post->discussion->readers()
// The `select(...)` part is not mandatory here, but makes the query safer. See #55.
->select('users.*')
->where('users.id', '!=', $this->post->user_id)
->join('tag_user', 'tag_user.user_id', '=', 'users.id')
->whereIn('tag_user.tag_id', $tagIds->all())
Expand Down

0 comments on commit 0d31436

Please sign in to comment.