From b290161ef4f3a49de4f38fe3c619270d15c9dbda Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Sat, 29 Aug 2015 23:08:36 +0200 Subject: [PATCH] Make sure query filter works with database prefix, too. Related to flarum/core#269. --- extensions/tags/src/Gambits/TagGambit.php | 6 ++++-- extensions/tags/src/Listeners/AddTagGambit.php | 3 ++- .../tags/src/Listeners/ConfigureDiscussionPermissions.php | 3 ++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/extensions/tags/src/Gambits/TagGambit.php b/extensions/tags/src/Gambits/TagGambit.php index b8b52361a..43454f019 100644 --- a/extensions/tags/src/Gambits/TagGambit.php +++ b/extensions/tags/src/Gambits/TagGambit.php @@ -3,6 +3,7 @@ use Flarum\Tags\TagRepository; use Flarum\Core\Search\Search; use Flarum\Core\Search\RegexGambit; +use Illuminate\Database\Query\Expression; class TagGambit extends RegexGambit { @@ -32,7 +33,7 @@ class TagGambit extends RegexGambit $query->orWhereNotExists(function ($query) { $query->select(app('flarum.db')->raw(1)) ->from('discussions_tags') - ->whereRaw('discussion_id = discussions.id'); + ->where('discussions.id', new Expression('discussion_id')); }); } else { $id = $this->tags->getIdForSlug($slug); @@ -40,7 +41,8 @@ class TagGambit extends RegexGambit $query->orWhereExists(function ($query) use ($id) { $query->select(app('flarum.db')->raw(1)) ->from('discussions_tags') - ->whereRaw('discussion_id = discussions.id AND tag_id = ?', [$id]); + ->where('discussions.id', new Expression('discussion_id')) + ->where('tag_id', $id); }); } } diff --git a/extensions/tags/src/Listeners/AddTagGambit.php b/extensions/tags/src/Listeners/AddTagGambit.php index 2ebd0a4a2..51dd98a44 100755 --- a/extensions/tags/src/Listeners/AddTagGambit.php +++ b/extensions/tags/src/Listeners/AddTagGambit.php @@ -5,6 +5,7 @@ use Flarum\Events\DiscussionSearchWillBePerformed; use Illuminate\Contracts\Events\Dispatcher; use Flarum\Tags\Gambits\TagGambit; use Flarum\Tags\Tag; +use Illuminate\Database\Query\Expression; class AddTagGambit { @@ -33,7 +34,7 @@ class AddTagGambit return $query->select(app('flarum.db')->raw(1)) ->from('discussions_tags') ->whereIn('tag_id', Tag::where('is_hidden', 1)->lists('id')) - ->whereRaw('discussion_id = ' . app('flarum.db')->getQueryGrammar()->wrap('discussions.id')); + ->where('discussions.id', new Expression('discussion_id')); }); } } diff --git a/extensions/tags/src/Listeners/ConfigureDiscussionPermissions.php b/extensions/tags/src/Listeners/ConfigureDiscussionPermissions.php index e2f2a577f..6cf1641a0 100755 --- a/extensions/tags/src/Listeners/ConfigureDiscussionPermissions.php +++ b/extensions/tags/src/Listeners/ConfigureDiscussionPermissions.php @@ -4,6 +4,7 @@ use Flarum\Events\ScopeModelVisibility; use Flarum\Events\ModelAllow; use Flarum\Core\Discussions\Discussion; use Flarum\Tags\Tag; +use Illuminate\Database\Query\Expression; class ConfigureDiscussionPermissions { @@ -21,7 +22,7 @@ class ConfigureDiscussionPermissions return $query->select(app('flarum.db')->raw(1)) ->from('discussions_tags') ->whereIn('tag_id', Tag::getNotVisibleTo($event->actor)) - ->whereRaw('discussion_id = ' . app('flarum.db')->getQueryGrammar()->wrap('discussions.id')); + ->where('discussions.id', new Expression('discussion_id')); }); } }