From e4d468671789cf78dfafa35b89b04b8274cbc2d4 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Mon, 2 Aug 2021 20:22:07 +0200 Subject: [PATCH] Ensure visits lists where the page is lower than 1, fall back to page 1 to avoid errors --- CHANGELOG.md | 18 ++++++++++++++++++ module/Core/src/Model/ShortUrlsParams.php | 2 +- module/Core/src/Model/VisitsParams.php | 9 +++++++-- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 59f8b7dc..594680a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,24 @@ 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). +## [2.7.3] - 2021-08-02 +### Added +* *Nothing* + +### Changed +* *Nothing* + +### Deprecated +* *Nothing* + +### Removed +* *Nothing* + +### Fixed +* [#1135](https://github.com/shlinkio/shlink/issues/1135) Fixed error when importing short URLs with no visits from another Shlink instance. +* [#1136](https://github.com/shlinkio/shlink/issues/1136) Fixed error when fetching tag/short-url/orphan visits for a page lower than 1. + + ## [2.7.2] - 2021-07-30 ### Added * *Nothing* diff --git a/module/Core/src/Model/ShortUrlsParams.php b/module/Core/src/Model/ShortUrlsParams.php index b27a6187..4ac69985 100644 --- a/module/Core/src/Model/ShortUrlsParams.php +++ b/module/Core/src/Model/ShortUrlsParams.php @@ -15,11 +15,11 @@ final class ShortUrlsParams public const DEFAULT_ITEMS_PER_PAGE = 10; private int $page; + private ?int $itemsPerPage = null; private ?string $searchTerm; private array $tags; private ShortUrlsOrdering $orderBy; private ?DateRange $dateRange; - private ?int $itemsPerPage = null; private function __construct() { diff --git a/module/Core/src/Model/VisitsParams.php b/module/Core/src/Model/VisitsParams.php index f8498c7a..abaa8fc1 100644 --- a/module/Core/src/Model/VisitsParams.php +++ b/module/Core/src/Model/VisitsParams.php @@ -25,11 +25,16 @@ final class VisitsParams bool $excludeBots = false ) { $this->dateRange = $dateRange ?? new DateRange(); - $this->page = $page; + $this->page = $this->determinePage($page); $this->itemsPerPage = $this->determineItemsPerPage($itemsPerPage); $this->excludeBots = $excludeBots; } + private function determinePage(int $page): int + { + return $page > 0 ? $page : self::FIRST_PAGE; + } + private function determineItemsPerPage(?int $itemsPerPage): int { if ($itemsPerPage !== null && $itemsPerPage < 0) { @@ -43,7 +48,7 @@ final class VisitsParams { return new self( parseDateRangeFromQuery($query, 'startDate', 'endDate'), - (int) ($query['page'] ?? 1), + (int) ($query['page'] ?? self::FIRST_PAGE), isset($query['itemsPerPage']) ? (int) $query['itemsPerPage'] : null, isset($query['excludeBots']), );