From 3b9ba5cac21d2ca55bc91779dba51303bd994a00 Mon Sep 17 00:00:00 2001 From: Pavel Dohnal Date: Mon, 13 Jan 2020 13:41:36 +0100 Subject: [PATCH] Fix stats redirect When an unauthenticated user comes to any page they are redirected to login screen. After they authenticate they are redirected to the original page. But the # part of the url is ignored. So we have to use regular query params from the email and redirect user to the canonical URL later. [MAILPOET-2554] --- lib/AdminPages/Pages/Newsletters.php | 9 +++++++++ lib/Cron/Workers/StatsNotifications/Worker.php | 2 +- .../Cron/Workers/StatsNotifications/WorkerTest.php | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/AdminPages/Pages/Newsletters.php b/lib/AdminPages/Pages/Newsletters.php index b78ca74f30..c3a464555e 100644 --- a/lib/AdminPages/Pages/Newsletters.php +++ b/lib/AdminPages/Pages/Newsletters.php @@ -75,6 +75,15 @@ class Newsletters { public function render() { global $wp_roles; // phpcs:ignore Squiz.NamingConventions.ValidVariableName.NotCamelCaps + if (isset($_GET['stats'])) { + $this->wp->wpSafeRedirect( + $this->wp->getSiteUrl(null, + '/wp-admin/admin.php?page=mailpoet-newsletters#/stats/' . $_GET['stats'] + ) + ); + exit; + } + $data = []; $data['items_per_page'] = $this->listingPageLimit->getLimitPerPage('newsletters'); diff --git a/lib/Cron/Workers/StatsNotifications/Worker.php b/lib/Cron/Workers/StatsNotifications/Worker.php index 876e7d14e3..36823fc1ba 100644 --- a/lib/Cron/Workers/StatsNotifications/Worker.php +++ b/lib/Cron/Workers/StatsNotifications/Worker.php @@ -139,7 +139,7 @@ class Worker { ), 'topLinkClicks' => 0, 'linkSettings' => WPFunctions::get()->getSiteUrl(null, '/wp-admin/admin.php?page=mailpoet-settings#basics'), - 'linkStats' => WPFunctions::get()->getSiteUrl(null, '/wp-admin/admin.php?page=mailpoet-newsletters#/stats/' . $newsletter->getId()), + 'linkStats' => WPFunctions::get()->getSiteUrl(null, '/wp-admin/admin.php?page=mailpoet-newsletters&stats=' . $newsletter->getId()), 'clicked' => $clicked, 'opened' => $opened, 'subscribersLimitReached' => $this->subscribersFeature->check(), diff --git a/tests/integration/Cron/Workers/StatsNotifications/WorkerTest.php b/tests/integration/Cron/Workers/StatsNotifications/WorkerTest.php index 822933d9f3..686534495f 100644 --- a/tests/integration/Cron/Workers/StatsNotifications/WorkerTest.php +++ b/tests/integration/Cron/Workers/StatsNotifications/WorkerTest.php @@ -209,7 +209,7 @@ class WorkerTest extends \MailPoetTest { $this->anything(), $this->callback(function($context){ return strpos($context['linkSettings'], 'mailpoet-settings') - && strpos($context['linkStats'], 'mailpoet-newsletters#/stats'); + && strpos($context['linkStats'], 'mailpoet-newsletters&stats'); })); $this->statsNotifications->process();