diff --git a/core/DataTable/Renderer/Rss.php b/core/DataTable/Renderer/Rss.php index fd18b4437147fcfc9e1caa8b557c2ebaf6e1e224..3d821150fc4eaaa9f8047990aa9555746d15191e 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 8b6d7924a71282a7ae795ec8a63d6664fe737452..b027bef0b7eadcd781f960da8235cab036a2ba37 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(); + } }