Make sure query filter works with database prefix, too.

Related to flarum/core#269.
This commit is contained in:
Franz Liedke 2015-08-29 23:08:36 +02:00
parent 7b24c82f6f
commit b290161ef4
3 changed files with 8 additions and 4 deletions

View File

@ -3,6 +3,7 @@
use Flarum\Tags\TagRepository; use Flarum\Tags\TagRepository;
use Flarum\Core\Search\Search; use Flarum\Core\Search\Search;
use Flarum\Core\Search\RegexGambit; use Flarum\Core\Search\RegexGambit;
use Illuminate\Database\Query\Expression;
class TagGambit extends RegexGambit class TagGambit extends RegexGambit
{ {
@ -32,7 +33,7 @@ class TagGambit extends RegexGambit
$query->orWhereNotExists(function ($query) { $query->orWhereNotExists(function ($query) {
$query->select(app('flarum.db')->raw(1)) $query->select(app('flarum.db')->raw(1))
->from('discussions_tags') ->from('discussions_tags')
->whereRaw('discussion_id = discussions.id'); ->where('discussions.id', new Expression('discussion_id'));
}); });
} else { } else {
$id = $this->tags->getIdForSlug($slug); $id = $this->tags->getIdForSlug($slug);
@ -40,7 +41,8 @@ class TagGambit extends RegexGambit
$query->orWhereExists(function ($query) use ($id) { $query->orWhereExists(function ($query) use ($id) {
$query->select(app('flarum.db')->raw(1)) $query->select(app('flarum.db')->raw(1))
->from('discussions_tags') ->from('discussions_tags')
->whereRaw('discussion_id = discussions.id AND tag_id = ?', [$id]); ->where('discussions.id', new Expression('discussion_id'))
->where('tag_id', $id);
}); });
} }
} }

View File

@ -5,6 +5,7 @@ use Flarum\Events\DiscussionSearchWillBePerformed;
use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Contracts\Events\Dispatcher;
use Flarum\Tags\Gambits\TagGambit; use Flarum\Tags\Gambits\TagGambit;
use Flarum\Tags\Tag; use Flarum\Tags\Tag;
use Illuminate\Database\Query\Expression;
class AddTagGambit class AddTagGambit
{ {
@ -33,7 +34,7 @@ class AddTagGambit
return $query->select(app('flarum.db')->raw(1)) return $query->select(app('flarum.db')->raw(1))
->from('discussions_tags') ->from('discussions_tags')
->whereIn('tag_id', Tag::where('is_hidden', 1)->lists('id')) ->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'));
}); });
} }
} }

View File

@ -4,6 +4,7 @@ use Flarum\Events\ScopeModelVisibility;
use Flarum\Events\ModelAllow; use Flarum\Events\ModelAllow;
use Flarum\Core\Discussions\Discussion; use Flarum\Core\Discussions\Discussion;
use Flarum\Tags\Tag; use Flarum\Tags\Tag;
use Illuminate\Database\Query\Expression;
class ConfigureDiscussionPermissions class ConfigureDiscussionPermissions
{ {
@ -21,7 +22,7 @@ class ConfigureDiscussionPermissions
return $query->select(app('flarum.db')->raw(1)) return $query->select(app('flarum.db')->raw(1))
->from('discussions_tags') ->from('discussions_tags')
->whereIn('tag_id', Tag::getNotVisibleTo($event->actor)) ->whereIn('tag_id', Tag::getNotVisibleTo($event->actor))
->whereRaw('discussion_id = ' . app('flarum.db')->getQueryGrammar()->wrap('discussions.id')); ->where('discussions.id', new Expression('discussion_id'));
}); });
} }
} }