Fix not-contains tag filter dropping entries where tags is null

This commit is contained in:
Gregor Vostrak
2026-06-25 19:09:54 +02:00
parent 58d7b33366
commit caa36d2875

View File

@@ -210,6 +210,11 @@ class TimeEntryFilter
} }
$includeNone = in_array(self::NONE_VALUE, $tagIds, true); $includeNone = in_array(self::NONE_VALUE, $tagIds, true);
$tagIds = array_values(array_filter($tagIds, fn (string $id): bool => $id !== self::NONE_VALUE)); $tagIds = array_values(array_filter($tagIds, fn (string $id): bool => $id !== self::NONE_VALUE));
// An empty selection (no tag IDs and not filtering for "none") is no constraint, so apply nothing.
// This also prevents the not-contains branch from collapsing into "only entries with null tags".
if (count($tagIds) === 0 && ! $includeNone) {
return $this;
}
$tagCondition = function (Builder $builder) use ($tagIds, $includeNone): void { $tagCondition = function (Builder $builder) use ($tagIds, $includeNone): void {
foreach ($tagIds as $tagId) { foreach ($tagIds as $tagId) {
@@ -223,7 +228,12 @@ class TimeEntryFilter
}; };
if ($tagFilter === self::TAG_FILTER_NOT_CONTAINS) { if ($tagFilter === self::TAG_FILTER_NOT_CONTAINS) {
$this->builder->whereNot($tagCondition); $this->builder->where(function (Builder $builder) use ($tagCondition, $includeNone): void {
$builder->whereNot($tagCondition);
if (! $includeNone) {
$builder->orWhereNull('tags');
}
});
} else { } else {
$this->builder->where($tagCondition); $this->builder->where($tagCondition);
} }