Skip to content

Commit

Permalink
Avoid tracking visit to maintenance, unpublished and not routable pages
Browse files Browse the repository at this point in the history
  • Loading branch information
giuscris committed Nov 3, 2024
1 parent ee1be69 commit 834bcfc
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions formwork/src/Controllers/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@ public function __construct(

public function load(RouteParams $routeParams, Statistics $statistics): Response
{
$trackable = $this->config->get('system.statistics.enabled');

if ($this->site->get('maintenance.enabled') && !$this->app->panel()?->isLoggedIn()) {
if ($this->site->get('maintenance.page') !== null) {
$route = $this->site->get('maintenance.page')->route();
$trackable = false;

if (($maintenancePage = $this->site->get('maintenance.page')) instanceof Page) {
$route = $maintenancePage->route();
} else {
$status = ResponseStatus::ServiceUnavailable;
return new Response($this->view('errors.maintenance', ['status' => $status->code(), 'message' => $status->message()]), $status);
Expand Down Expand Up @@ -70,11 +74,10 @@ public function load(RouteParams $routeParams, Statistics $statistics): Response
}
}

if ($this->config->get('system.statistics.enabled')) {
$statistics->trackVisit();
}

if ($page->isPublished() && $page->routable()) {
if ($trackable) {
$statistics->trackVisit();
}
return $this->getPageResponse($page);
}
} else {
Expand Down

0 comments on commit 834bcfc

Please sign in to comment.