Skip to content

Commit

Permalink
[BUGFIX] Don't enforce join from visitor to pagevisit table if not ne…
Browse files Browse the repository at this point in the history
…eded

While I faced an issue with different filter startdates in url shortener list view when searching for a word vs. empty filter, I stumbled over the old workarround 1279099. To fix my problem in the URL shortener view (and for cleaning up reasons), I removed the workarround in FilterDto::getStartTimeFromTimePeriod().
But I wanted to also fix the problem from the old workarround (look at revision above). So, searching for a single searchterm in lead list (e.g. email) should also show visitor records without pagevisits in relation. That's why we fixed it now for admins only, where we do not need a where clause for pagevisits.site if there is not site set in filter. But for editors we need this clause in every case to ensure, that editors can only see authenticated leads. The where-clause leads to a join to pagevisits table and so no leads can be found without pagevisit records.

In addition I also cleaned up a bit the VisitorRepository by using isser functions.
  • Loading branch information
einpraegsam committed Feb 29, 2024
1 parent dfa58fe commit 66802e9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Classes/Domain/Model/Transfer/FilterDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ public function getEndTimeForFilter(bool $shortmode = false): DateTime
*/
protected function getStartTimeFromTimePeriod(): DateTime
{
if ($this->getTimePeriod() === self::PERIOD_ALL || $this->isOnlySearchtermGiven()) {
if ($this->getTimePeriod() === self::PERIOD_ALL) {
$time = new DateTime();
$time->setTimestamp(0);
} elseif ($this->getTimePeriod() === self::PERIOD_THISYEAR) {
Expand Down
5 changes: 5 additions & 0 deletions Classes/Domain/Repository/AbstractRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use In2code\Lux\Domain\Model\Pagevisit;
use In2code\Lux\Domain\Model\Transfer\FilterDto;
use In2code\Lux\Domain\Model\Visitor;
use In2code\Lux\Utility\BackendUtility;
use In2code\Lux\Utility\StringUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
Expand Down Expand Up @@ -85,6 +86,10 @@ protected function extendLogicalAndWithFilterConstraintsForSite(
array $logicalAnd,
string $tablePrefix = ''
): array {
if (BackendUtility::isAdministrator() && $filter->isSiteSet() === false) {
// Prevent join to pagevisit table if not needed (to avoid empty result problems on specific search)
return $logicalAnd;
}
$field = ($tablePrefix ? $tablePrefix . '.' : '') . 'site';
$logicalAnd[] = $query->in($field, $filter->getSitesForFilter());
return $logicalAnd;
Expand Down
14 changes: 7 additions & 7 deletions Classes/Domain/Repository/VisitorRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ protected function extendLogicalAndWithFilterConstraints(
)
);

if ($filter->getSearchterms() !== []) {
if ($filter->isSearchtermSet()) {
$logicalOr = [];
foreach ($filter->getSearchterms() as $searchterm) {
if (MathUtility::canBeInterpretedAsInteger($searchterm)) {
Expand All @@ -722,16 +722,16 @@ protected function extendLogicalAndWithFilterConstraints(
}
$logicalAnd[] = $query->logicalOr(...$logicalOr);
}
if ($filter->getIdentified() > FilterDto::IDENTIFIED_ALL) {
if ($filter->isIdentifiedSet()) {
$logicalAnd[] = $query->equals('identified', $filter->getIdentified() === FilterDto::IDENTIFIED_IDENTIFIED);
}
if ($filter->getPid() !== '') {
if ($filter->isPidSet()) {
$logicalAnd[] = $query->equals('pagevisits.page.uid', (int)$filter->getPid());
}
if ($filter->getScoring() > 0) {
if ($filter->isScoringSet()) {
$logicalAnd[] = $query->greaterThan('scoring', $filter->getScoring());
}
if ($filter->getCategoryScoring() !== null) {
if ($filter->isCategoryScoringSet()) {
$logicalAnd[] = $query->equals('categoryscorings.category', $filter->getCategoryScoring());
$logicalAnd[] = $query->greaterThan('categoryscorings.scoring', 0);
}
Expand All @@ -745,7 +745,7 @@ protected function extendLogicalAndWithFilterConstraints(
protected function getOrderingsArrayByFilterDto(FilterDto $filter): array
{
$orderings = ['identified' => QueryInterface::ORDER_DESCENDING];
if ($filter->getCategoryScoring() === null) {
if ($filter->isCategoryScoringSet() === false) {
$orderings['scoring'] = QueryInterface::ORDER_DESCENDING;
} else {
$orderings['categoryscorings.scoring'] = QueryInterface::ORDER_DESCENDING;
Expand Down Expand Up @@ -797,7 +797,7 @@ protected function extendWhereClauseWithFilterSearchterms(
protected function extendWhereClauseWithFilterIdentified(FilterDto $filter): string
{
$sql = '';
if ($filter->getIdentified() > FilterDto::IDENTIFIED_ALL) {
if ($filter->isIdentifiedSet()) {
$sql .= ' and v.identified=' . (int)($filter->getIdentified() === FilterDto::IDENTIFIED_IDENTIFIED);
}
return $sql;
Expand Down

0 comments on commit 66802e9

Please sign in to comment.