mirror of
https://github.com/shlinkio/shlink.git
synced 2024-12-18 21:23:37 -06:00
Merge pull request #1462 from acelaya-forks/feature/search-with-all-tags
Fixed error when filtering short URLs by ALL tags and search term
This commit is contained in:
commit
3d43bdbb49
@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to [Semantic Versioning](https://semver.org).
|
||||
|
||||
## [Unreleased]
|
||||
## [3.1.2] - 2022-06-04
|
||||
### Added
|
||||
* *Nothing*
|
||||
|
||||
@ -19,6 +19,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this
|
||||
|
||||
### Fixed
|
||||
* [#1448](https://github.com/shlinkio/shlink/issues/1448) Fixed HTML entities not being properly parsed when auto-resolving page titles.
|
||||
* [#1458](https://github.com/shlinkio/shlink/issues/1458) Fixed 500 error when filtering short URLs by ALL tags and search term.
|
||||
|
||||
|
||||
## [3.1.1] - 2022-05-09
|
||||
|
@ -102,15 +102,22 @@ class ShortUrlRepository extends EntitySpecificationRepository implements ShortU
|
||||
$qb->leftJoin('s.tags', 't');
|
||||
}
|
||||
|
||||
// Apply search conditions
|
||||
// Apply general search conditions
|
||||
$conditions = [
|
||||
$qb->expr()->like('s.longUrl', ':searchPattern'),
|
||||
$qb->expr()->like('s.shortCode', ':searchPattern'),
|
||||
$qb->expr()->like('s.title', ':searchPattern'),
|
||||
$qb->expr()->like('d.authority', ':searchPattern'),
|
||||
];
|
||||
|
||||
// Apply tag conditions, only when not filtering by all provided tags
|
||||
$tagsMode = $filtering->tagsMode() ?? ShortUrlsParams::TAGS_MODE_ANY;
|
||||
if (empty($tags) || $tagsMode === ShortUrlsParams::TAGS_MODE_ANY) {
|
||||
$conditions[] = $qb->expr()->like('t.name', ':searchPattern');
|
||||
}
|
||||
|
||||
$qb->leftJoin('s.domain', 'd')
|
||||
->andWhere($qb->expr()->orX(
|
||||
$qb->expr()->like('s.longUrl', ':searchPattern'),
|
||||
$qb->expr()->like('s.shortCode', ':searchPattern'),
|
||||
$qb->expr()->like('s.title', ':searchPattern'),
|
||||
$qb->expr()->like('t.name', ':searchPattern'),
|
||||
$qb->expr()->like('d.authority', ':searchPattern'),
|
||||
))
|
||||
->andWhere($qb->expr()->orX(...$conditions))
|
||||
->setParameter('searchPattern', '%' . $searchTerm . '%');
|
||||
}
|
||||
|
||||
|
@ -128,6 +128,12 @@ class ShortUrlRepositoryTest extends DatabaseTestCase
|
||||
self::assertEquals(1, $this->repo->countList(new ShortUrlsCountFiltering('foo', ['bar'])));
|
||||
self::assertSame($foo, $result[0]);
|
||||
|
||||
// Assert searched text also applies to tags
|
||||
$result = $this->repo->findList(new ShortUrlsListFiltering(null, null, Ordering::emptyInstance(), 'bar'));
|
||||
self::assertCount(2, $result);
|
||||
self::assertEquals(2, $this->repo->countList(new ShortUrlsCountFiltering('bar')));
|
||||
self::assertContains($foo, $result);
|
||||
|
||||
$result = $this->repo->findList(new ShortUrlsListFiltering(null, null, Ordering::emptyInstance()));
|
||||
self::assertCount(3, $result);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user