From aaed436a073bcb2f86019bbef222e5a1a994e635 Mon Sep 17 00:00:00 2001 From: Matthieu Aubry <mattab@users.noreply.github.com> Date: Tue, 23 Aug 2016 13:17:56 +1200 Subject: [PATCH] Fix fatal error when requesting RSS format (#10407) * Fixes #10399 * add test reproducing issue #10399 * another health check --- core/DataTable/Renderer/Rss.php | 8 ++++-- .../tests/Integration/MultiSitesTest.php | 25 +++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/core/DataTable/Renderer/Rss.php b/core/DataTable/Renderer/Rss.php index fd18b44371..3d821150fc 100644 --- a/core/DataTable/Renderer/Rss.php +++ b/core/DataTable/Renderer/Rss.php @@ -64,9 +64,13 @@ class Rss extends Renderer $pudDate = date('r', $timestamp); - $dateInSiteTimezone = Date::factory($timestamp)->setTimezone($site->getTimezone())->toString('Y-m-d'); + $dateInSiteTimezone = Date::factory($timestamp); + if($site) { + $dateInSiteTimezone = $dateInSiteTimezone->setTimezone($site->getTimezone()); + } + $dateInSiteTimezone = $dateInSiteTimezone->toString('Y-m-d'); $thisPiwikUrl = Common::sanitizeInputValue($piwikUrl . "&date=$dateInSiteTimezone"); - $siteName = $site->getName(); + $siteName = $site ? $site->getName() : ''; $title = $siteName . " on " . $date; $out .= "\t<item> diff --git a/plugins/MultiSites/tests/Integration/MultiSitesTest.php b/plugins/MultiSites/tests/Integration/MultiSitesTest.php index 8b6d7924a7..b027bef0b7 100644 --- a/plugins/MultiSites/tests/Integration/MultiSitesTest.php +++ b/plugins/MultiSites/tests/Integration/MultiSitesTest.php @@ -9,6 +9,7 @@ namespace Piwik\Plugins\MultiSites\tests\Integration; use Piwik\Access; +use Piwik\FrontController; use Piwik\Plugins\MultiSites\API as APIMultiSites; use Piwik\Plugins\SitesManager\API as APISitesManager; use Piwik\Tests\Framework\TestCase\IntegrationTestCase; @@ -49,4 +50,28 @@ class MultiSitesTest extends IntegrationTestCase // safety net $this->assertEquals(0, $dataTable->getFirstRow()->getColumn('nb_visits')); } + + /** + * Testing that getOne does not error out when format=rss, #10407 + * + * @group Plugins + */ + public function testWhenRssFormatGetOneDoesNotError() + { + $_GET = array( + 'method' => 'MultiSites.getOne', + 'idSite' => $this->idSiteAccess, + 'period' => 'month', + 'date' => 'last10', + 'format' => 'rss' + ); + + $output = FrontController::getInstance()->fetchDispatch('API'); + + $this->assertContains('<item>', $output); + $this->assertContains('</rss>', $output); + $this->assertNotContains('error', $output); + + $_GET = array(); + } } -- GitLab