mirror of
https://github.com/flarum/core.git
synced 2025-08-13 11:54:32 +02:00
Compare commits
10 Commits
dk/likes/l
...
dk/2022032
Author | SHA1 | Date | |
---|---|---|---|
|
88b5918e3a | ||
|
d0119e7634 | ||
|
726c8f3a9a | ||
|
8fe1d1cabc | ||
|
d0b4e74b1f | ||
|
65c861ab7b | ||
|
cb9fe6930f | ||
|
3343fde5f2 | ||
|
907b1f10aa | ||
|
ae7d31ec16 |
@@ -55,23 +55,23 @@ class TagFilterGambit extends AbstractRegexGambit implements FilterInterface
|
||||
{
|
||||
$slugs = explode(',', trim($rawSlugs, '"'));
|
||||
|
||||
$query->where(function (Builder $query) use ($slugs, $negate) {
|
||||
foreach ($slugs as $slug) {
|
||||
if ($slug === 'untagged') {
|
||||
$query->whereIn('discussions.id', function (Builder $query) {
|
||||
$query->select('discussion_id')
|
||||
->from('discussion_tag');
|
||||
}, 'or', ! $negate);
|
||||
} else {
|
||||
$id = $this->tags->getIdForSlug($slug);
|
||||
|
||||
$query->whereIn('discussions.id', function (Builder $query) use ($id) {
|
||||
$query->select('discussion_id')
|
||||
->from('discussion_tag')
|
||||
->where('tag_id', $id);
|
||||
}, 'or', $negate);
|
||||
$query
|
||||
->distinct()
|
||||
->leftJoin('discussion_tag', 'discussions.id', '=', 'discussion_tag.discussion_id')
|
||||
->where(function (Builder $query) use ($slugs, $negate) {
|
||||
foreach ($slugs as $slug) {
|
||||
if ($slug === 'untagged' && ! $negate) {
|
||||
$query->orWhereNull('discussion_tag.tag_id');
|
||||
} elseif ($slug === 'untagged' && $negate) {
|
||||
$query->orWhereNotNull('discussion_tag.tag_id');
|
||||
} elseif ($id = $this->tags->getIdForSlug($slug)) {
|
||||
$query->orWhere(
|
||||
'discussion_tag.tag_id',
|
||||
$negate ? '!=' : '=',
|
||||
$id
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@@ -16,7 +16,9 @@ use Flarum\Foundation\EventGeneratorTrait;
|
||||
use Flarum\Notification\Notification;
|
||||
use Flarum\Post\Event\Deleted;
|
||||
use Flarum\User\User;
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Query\Expression;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
@@ -91,7 +93,19 @@ class Post extends AbstractModel
|
||||
// discussion.
|
||||
static::creating(function (self $post) {
|
||||
$post->type = $post::$type;
|
||||
$post->number = ++$post->discussion->post_number_index;
|
||||
|
||||
/** @var ConnectionInterface $db */
|
||||
$db = static::getConnectionResolver();
|
||||
$post->number = new Expression('('.$db
|
||||
->table('posts', 'pn')
|
||||
->whereRaw($db->getTablePrefix().'pn.discussion_id = '.intval($post->discussion_id))
|
||||
->select($db->raw('max('.$db->getTablePrefix().'pn.number) + 1'))
|
||||
->toSql()
|
||||
.')');
|
||||
});
|
||||
|
||||
static::created(function (self $post) {
|
||||
$post->refresh();
|
||||
$post->discussion->save();
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user