From 744c66cb7098e434b1bfb06ec99794d4e99382c3 Mon Sep 17 00:00:00 2001 From: mattab Date: Mon, 19 Sep 2016 13:48:54 +1200 Subject: Fix depraction test: use assertDeprecatedMethodIsRemovedInPiwik3 --- tests/PHPUnit/Unit/DeprecatedMethodsTest.php | 72 ++++++++++++++-------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/tests/PHPUnit/Unit/DeprecatedMethodsTest.php b/tests/PHPUnit/Unit/DeprecatedMethodsTest.php index ff2dd4bcbd..deade3b50c 100644 --- a/tests/PHPUnit/Unit/DeprecatedMethodsTest.php +++ b/tests/PHPUnit/Unit/DeprecatedMethodsTest.php @@ -23,53 +23,52 @@ class DeprecatedMethodsTest extends \PHPUnit_Framework_TestCase { public function test_deprecations() { - $validTill = '2016-09-01'; - $this->assertDeprecatedMethodIsRemoved('Piwik\SettingsServer', 'isApache', $validTill); + $this->assertDeprecatedMethodIsRemovedInPiwik3('Piwik\SettingsServer', 'isApache'); $validTill = '2015-03-10'; - $this->assertDeprecatedMethodIsRemoved('\Piwik\Period', 'factory', $validTill); - $this->assertDeprecatedMethodIsRemoved('\Piwik\Config', 'getConfigSuperUserForBackwardCompatibility', $validTill); - $this->assertDeprecatedMethodIsRemoved('\Piwik\Menu\MenuAdmin', 'addEntry', $validTill); - $this->assertDeprecatedMethodIsRemoved('\Piwik\Menu\MenuAdmin', 'removeEntry', $validTill); - $this->assertDeprecatedMethodIsRemoved('\Piwik\Menu\MenuTop', 'addEntry', $validTill); - $this->assertDeprecatedMethodIsRemoved('\Piwik\Menu\MenuTop', 'removeEntry', $validTill); + $this->assertDeprecatedMethodIsRemovedBeforeDate('\Piwik\Period', 'factory', $validTill); + $this->assertDeprecatedMethodIsRemovedBeforeDate('\Piwik\Config', 'getConfigSuperUserForBackwardCompatibility', $validTill); + $this->assertDeprecatedMethodIsRemovedBeforeDate('\Piwik\Menu\MenuAdmin', 'addEntry', $validTill); + $this->assertDeprecatedMethodIsRemovedBeforeDate('\Piwik\Menu\MenuAdmin', 'removeEntry', $validTill); + $this->assertDeprecatedMethodIsRemovedBeforeDate('\Piwik\Menu\MenuTop', 'addEntry', $validTill); + $this->assertDeprecatedMethodIsRemovedBeforeDate('\Piwik\Menu\MenuTop', 'removeEntry', $validTill); $validTill = '2015-03-10'; - $this->assertDeprecatedMethodIsRemoved('Piwik\IP', 'sanitizeIp', $validTill); - $this->assertDeprecatedMethodIsRemoved('Piwik\IP', 'sanitizeIpRange', $validTill); - $this->assertDeprecatedMethodIsRemoved('Piwik\IP', 'P2N', $validTill); - $this->assertDeprecatedMethodIsRemoved('Piwik\IP', 'N2P', $validTill); - $this->assertDeprecatedMethodIsRemoved('Piwik\IP', 'prettyPrint', $validTill); - $this->assertDeprecatedMethodIsRemoved('Piwik\IP', 'isIPv4', $validTill); - $this->assertDeprecatedMethodIsRemoved('Piwik\IP', 'long2ip', $validTill); - $this->assertDeprecatedMethodIsRemoved('Piwik\IP', 'isIPv6', $validTill); - $this->assertDeprecatedMethodIsRemoved('Piwik\IP', 'isMappedIPv4', $validTill); - $this->assertDeprecatedMethodIsRemoved('Piwik\IP', 'getIPv4FromMappedIPv6', $validTill); - $this->assertDeprecatedMethodIsRemoved('Piwik\IP', 'getIpsForRange', $validTill); - $this->assertDeprecatedMethodIsRemoved('Piwik\IP', 'isIpInRange', $validTill); - $this->assertDeprecatedMethodIsRemoved('Piwik\IP', 'getHostByAddr', $validTill); - $this->assertDeprecatedMethodIsRemoved('Piwik\SettingsPiwik', 'rewriteTmpPathWithInstanceId', $validTill); + $this->assertDeprecatedMethodIsRemovedBeforeDate('Piwik\IP', 'sanitizeIp', $validTill); + $this->assertDeprecatedMethodIsRemovedBeforeDate('Piwik\IP', 'sanitizeIpRange', $validTill); + $this->assertDeprecatedMethodIsRemovedBeforeDate('Piwik\IP', 'P2N', $validTill); + $this->assertDeprecatedMethodIsRemovedBeforeDate('Piwik\IP', 'N2P', $validTill); + $this->assertDeprecatedMethodIsRemovedBeforeDate('Piwik\IP', 'prettyPrint', $validTill); + $this->assertDeprecatedMethodIsRemovedBeforeDate('Piwik\IP', 'isIPv4', $validTill); + $this->assertDeprecatedMethodIsRemovedBeforeDate('Piwik\IP', 'long2ip', $validTill); + $this->assertDeprecatedMethodIsRemovedBeforeDate('Piwik\IP', 'isIPv6', $validTill); + $this->assertDeprecatedMethodIsRemovedBeforeDate('Piwik\IP', 'isMappedIPv4', $validTill); + $this->assertDeprecatedMethodIsRemovedBeforeDate('Piwik\IP', 'getIPv4FromMappedIPv6', $validTill); + $this->assertDeprecatedMethodIsRemovedBeforeDate('Piwik\IP', 'getIpsForRange', $validTill); + $this->assertDeprecatedMethodIsRemovedBeforeDate('Piwik\IP', 'isIpInRange', $validTill); + $this->assertDeprecatedMethodIsRemovedBeforeDate('Piwik\IP', 'getHostByAddr', $validTill); + $this->assertDeprecatedMethodIsRemovedBeforeDate('Piwik\SettingsPiwik', 'rewriteTmpPathWithInstanceId', $validTill); $validTill = '2015-05-01'; - $this->assertDeprecatedMethodIsRemoved('Piwik\Plugins\UserSettings\API', 'getBrowserVersion', $validTill); - $this->assertDeprecatedMethodIsRemoved('Piwik\Plugins\UserSettings\API', 'getBrowser', $validTill); - $this->assertDeprecatedMethodIsRemoved('Piwik\Plugins\UserSettings\API', 'getOS', $validTill); - $this->assertDeprecatedMethodIsRemoved('Piwik\Plugins\UserSettings\API', 'getOSFamily', $validTill); - $this->assertDeprecatedMethodIsRemoved('Piwik\Plugins\UserSettings\API', 'getBrowserType', $validTill); - $this->assertDeprecatedMethodIsRemoved('Piwik\Plugins\UserSettings\API', 'getMobileVsDesktop', $validTill); - $this->assertDeprecatedMethodIsRemoved('Piwik\Plugins\UserSettings\API', 'getResolution', $validTill); - $this->assertDeprecatedMethodIsRemoved('Piwik\Plugins\UserSettings\API', 'getConfiguration', $validTill); - $this->assertDeprecatedMethodIsRemoved('Piwik\Plugins\UserSettings\API', 'getPlugin', $validTill); - $this->assertDeprecatedMethodIsRemoved('Piwik\Plugins\UserSettings\API', 'getLanguage', $validTill); - $this->assertDeprecatedMethodIsRemoved('Piwik\Plugins\UserSettings\API', 'getLanguageCode', $validTill); - $this->assertDeprecatedMethodIsRemoved('Piwik\Plugins\UserSettings\UserSettings', 'renameDeprecatedModuleAndAction', $validTill); + $this->assertDeprecatedMethodIsRemovedBeforeDate('Piwik\Plugins\UserSettings\API', 'getBrowserVersion', $validTill); + $this->assertDeprecatedMethodIsRemovedBeforeDate('Piwik\Plugins\UserSettings\API', 'getBrowser', $validTill); + $this->assertDeprecatedMethodIsRemovedBeforeDate('Piwik\Plugins\UserSettings\API', 'getOS', $validTill); + $this->assertDeprecatedMethodIsRemovedBeforeDate('Piwik\Plugins\UserSettings\API', 'getOSFamily', $validTill); + $this->assertDeprecatedMethodIsRemovedBeforeDate('Piwik\Plugins\UserSettings\API', 'getBrowserType', $validTill); + $this->assertDeprecatedMethodIsRemovedBeforeDate('Piwik\Plugins\UserSettings\API', 'getMobileVsDesktop', $validTill); + $this->assertDeprecatedMethodIsRemovedBeforeDate('Piwik\Plugins\UserSettings\API', 'getResolution', $validTill); + $this->assertDeprecatedMethodIsRemovedBeforeDate('Piwik\Plugins\UserSettings\API', 'getConfiguration', $validTill); + $this->assertDeprecatedMethodIsRemovedBeforeDate('Piwik\Plugins\UserSettings\API', 'getPlugin', $validTill); + $this->assertDeprecatedMethodIsRemovedBeforeDate('Piwik\Plugins\UserSettings\API', 'getLanguage', $validTill); + $this->assertDeprecatedMethodIsRemovedBeforeDate('Piwik\Plugins\UserSettings\API', 'getLanguageCode', $validTill); + $this->assertDeprecatedMethodIsRemovedBeforeDate('Piwik\Plugins\UserSettings\UserSettings', 'renameDeprecatedModuleAndAction', $validTill); // please be aware if re-adding a plugin called userSettings, and someone updates eg from Piwik 2.13 to that version, // the plugin will be possibly removed in an Update during 2.14.0 $this->assertDeprecatedClassIsRemoved('Piwik\Plugins\UserSettings\UserSettings', $validTill); $validTill = '2015-06-01'; - $this->assertDeprecatedMethodIsRemoved('Piwik\Archive', 'getBlob', $validTill); + $this->assertDeprecatedMethodIsRemovedBeforeDate('Piwik\Archive', 'getBlob', $validTill); $this->assertDeprecatedMethodIsRemovedInPiwik3('\Piwik\Menu\MenuAbstract', 'add'); $this->assertDeprecatedMethodIsRemovedInPiwik3('\Piwik\Archive', 'getDataTableFromArchive'); @@ -82,7 +81,8 @@ class DeprecatedMethodsTest extends \PHPUnit_Framework_TestCase $this->assertDeprecatedMethodIsRemovedInPiwik3('Piwik\Plugins\UserLanguage\UserLanguage', 'renameUserSettingsModuleAndAction'); } - private function assertDeprecatedMethodIsRemoved($className, $method, $removalDate) + + private function assertDeprecatedMethodIsRemovedBeforeDate($className, $method, $removalDate) { $now = Date::now(); $removalDate = Date::factory($removalDate); -- cgit v1.2.3 From 9515909a5c0c1187cb9feb6adb60ddb8d30c8045 Mon Sep 17 00:00:00 2001 From: Stefan Giehl Date: Tue, 20 Sep 2016 05:26:28 +0200 Subject: Fix Scheduled Reports sent one hour late in daylight saving timezones (#10443) * convert hour to send report to/from UTC, to ensure it isn't affected by daylight savings * adds update script to change existing scheduled reports to use utc time * code improvement * adds missing param --- core/Updates/2.16.3-b3.php | 41 ++++++++++++++++++++++ plugins/ScheduledReports/Controller.php | 6 +++- plugins/ScheduledReports/Tasks.php | 4 +-- plugins/ScheduledReports/javascripts/pdf.js | 15 ++++++-- plugins/ScheduledReports/lang/en.json | 1 + .../stylesheets/scheduledreports.less | 3 +- plugins/ScheduledReports/templates/_addReport.twig | 15 +++++++- plugins/ScheduledReports/templates/index.twig | 1 + .../ScheduledReports/tests/Integration/ApiTest.php | 17 ++++----- 9 files changed, 87 insertions(+), 16 deletions(-) create mode 100644 core/Updates/2.16.3-b3.php diff --git a/core/Updates/2.16.3-b3.php b/core/Updates/2.16.3-b3.php new file mode 100644 index 0000000000..a1175c9f4d --- /dev/null +++ b/core/Updates/2.16.3-b3.php @@ -0,0 +1,41 @@ +getReports(); + foreach ($allReports as $report) { + $report['hour'] = $this->adjustTimezoneBySite($report['hour'], $report['idsite']); + $model->updateReport($report['idreport'], $report); + } + } + + protected function adjustTimezoneBySite($hour, $idSite) + { + $timezone = Site::getTimezoneFor($idSite); + $dateTimeZone = new \DateTimeZone($timezone); + $timeZoneDifference = -ceil($dateTimeZone->getOffset(new \DateTime()) / 3600); + return (24 + $hour + $timeZoneDifference) % 24; + } +} diff --git a/plugins/ScheduledReports/Controller.php b/plugins/ScheduledReports/Controller.php index 3192a3cfc4..7316f6283d 100644 --- a/plugins/ScheduledReports/Controller.php +++ b/plugins/ScheduledReports/Controller.php @@ -26,7 +26,11 @@ class Controller extends \Piwik\Plugin\Controller $view = new View('@ScheduledReports/index'); $this->setGeneralVariablesView($view); - $view->countWebsites = count(APISitesManager::getInstance()->getSitesIdWithAtLeastViewAccess()); + $siteTimezone = $this->site->getTimezone(); + $dateTimeZone = new \DateTimeZone($siteTimezone); + + $view->timeZoneDifference = $dateTimeZone->getOffset(new \DateTime()) / 3600; + $view->countWebsites = count(APISitesManager::getInstance()->getSitesIdWithAtLeastViewAccess()); // get report types $reportTypes = API::getReportTypes(); diff --git a/plugins/ScheduledReports/Tasks.php b/plugins/ScheduledReports/Tasks.php index be61e0d793..44a13e1b57 100644 --- a/plugins/ScheduledReports/Tasks.php +++ b/plugins/ScheduledReports/Tasks.php @@ -18,11 +18,9 @@ class Tasks extends \Piwik\Plugin\Tasks foreach (API::getInstance()->getReports() as $report) { if (!$report['deleted'] && $report['period'] != Schedule::PERIOD_NEVER) { - $timezone = Site::getTimezoneFor($report['idsite']); - $schedule = Schedule::getScheduledTimeForPeriod($report['period']); $schedule->setHour($report['hour']); - $schedule->setTimezone($timezone); + $schedule->setTimezone('UTC'); // saved hour is UTC always $this->custom(API::getInstance(), 'sendReport', $report['idreport'], $schedule); } diff --git a/plugins/ScheduledReports/javascripts/pdf.js b/plugins/ScheduledReports/javascripts/pdf.js index 2b86809517..5ddff3654f 100644 --- a/plugins/ScheduledReports/javascripts/pdf.js +++ b/plugins/ScheduledReports/javascripts/pdf.js @@ -9,6 +9,10 @@ var getReportParametersFunctions = Object(); var updateReportParametersFunctions = Object(); var resetReportParametersFunctions = Object(); +function adjustHourToTimezone(hour, difference) { + return (24 + parseInt(hour) + difference) % 24; +} + function formSetEditReport(idReport) { var report = { 'type': ReportPlugin.defaultReportType, @@ -29,11 +33,16 @@ function formSetEditReport(idReport) { toggleReportType(report.type); + var hour = adjustHourToTimezone(report.hour, timeZoneDifference); + $('#report_description').html(report.description); $('#report_segment').find('option[value=' + report.idsegment + ']').prop('selected', 'selected'); $('#report_type').find('option[value=' + report.type + ']').prop('selected', 'selected'); $('#report_period').find('option[value=' + report.period + ']').prop('selected', 'selected'); - $('#report_hour').val(report.hour); + $('#report_hour').val(hour).bind('change', function() { + $('#hour_utc').text(adjustHourToTimezone($(this).val(), -timeZoneDifference)); + }); + $('#hour_utc').text(report.hour); $('[name=report_format].' + report.type + ' option[value=' + report.format + ']').prop('selected', 'selected'); $('select[name=report_type]').change( toggleDisplayOptionsByFormat ); @@ -122,10 +131,12 @@ function initManagePdf() { apiParameters.parameters = getReportParametersFunctions[apiParameters.reportType](); + var hour = adjustHourToTimezone($('#report_hour').val(), -timeZoneDifference); + var ajaxHandler = new ajaxHelper(); ajaxHandler.addParams(apiParameters, 'POST'); ajaxHandler.addParams({period: $('#report_period').find('option:selected').val()}, 'GET'); - ajaxHandler.addParams({hour: $('#report_hour').val()}, 'GET'); + ajaxHandler.addParams({hour: hour}, 'GET'); ajaxHandler.redirectOnSuccess(); ajaxHandler.setLoadingElement(); if (idReport) { diff --git a/plugins/ScheduledReports/lang/en.json b/plugins/ScheduledReports/lang/en.json index a1ef702c9a..60f0254a0d 100644 --- a/plugins/ScheduledReports/lang/en.json +++ b/plugins/ScheduledReports/lang/en.json @@ -29,6 +29,7 @@ "PluginDescription": "Create custom reports and schedule them to be emailed daily, weekly or monthly to one or several people. Several report formats are supported (html, pdf, csv, images).", "ReportFormat": "Report Format", "ReportHour": "Send report at %s o'clock", + "ReportHourWithUTC": "Send report at %1$s o'clock (%2$s o'clock UTC)", "ReportIncludeNWebsites": "The report will include main metrics for all websites that have at least one visit (from the %s websites currently available).", "ReportSent": "Report sent", "ReportsIncluded": "Statistics included", diff --git a/plugins/ScheduledReports/stylesheets/scheduledreports.less b/plugins/ScheduledReports/stylesheets/scheduledreports.less index 871b89da3c..27d2d1557d 100644 --- a/plugins/ScheduledReports/stylesheets/scheduledreports.less +++ b/plugins/ScheduledReports/stylesheets/scheduledreports.less @@ -7,5 +7,6 @@ #report_hour { height: 0.9em; padding: 0 0 0 5px; - width: 35px; + width: 45px; + background-position: 25px center; } diff --git a/plugins/ScheduledReports/templates/_addReport.twig b/plugins/ScheduledReports/templates/_addReport.twig index 24f97ad19f..7ed8a0c588 100644 --- a/plugins/ScheduledReports/templates/_addReport.twig +++ b/plugins/ScheduledReports/templates/_addReport.twig @@ -59,7 +59,20 @@
{{ 'ScheduledReports_MonthlyScheduleHelp'|translate }}
- {{ 'ScheduledReports_ReportHour'|translate('')|raw }} + + {% set hourInput %} + + {% endset %} + + {% if timeZoneDifference != 0 %} + {{ 'ScheduledReports_ReportHourWithUTC'|translate(hourInput, '')|raw }} + {% else %} + {{ 'ScheduledReports_ReportHour'|translate(hourInput)|raw }} + {% endif %} diff --git a/plugins/ScheduledReports/templates/index.twig b/plugins/ScheduledReports/templates/index.twig index 542fab8e70..b98ee70fc5 100644 --- a/plugins/ScheduledReports/templates/index.twig +++ b/plugins/ScheduledReports/templates/index.twig @@ -32,6 +32,7 @@ - - diff --git a/plugins/Morpheus/templates/javascriptCode.twig b/plugins/Morpheus/templates/javascriptCode.twig new file mode 100644 index 0000000000..c18d850d34 --- /dev/null +++ b/plugins/Morpheus/templates/javascriptCode.twig @@ -0,0 +1,18 @@ + + +{% if not loadAsync %}