Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthieu Napoli <matthieu@mnapoli.fr>2014-10-07 02:51:17 +0400
committerMatthieu Napoli <matthieu@mnapoli.fr>2014-10-07 07:40:37 +0400
commit4c5bad32d87e7489efaec528c458bc153b2df5d2 (patch)
treecfa36d5d06d0c4fb461e35f0ff91f9fbc9b3bc5c /plugins
parentb82d43a29980676c4b279f09c5d14ab137588627 (diff)
bug #5300 Prevent email reports from being sent twice for the same period
Diffstat (limited to 'plugins')
-rw-r--r--plugins/MobileMessaging/MobileMessaging.php3
-rw-r--r--plugins/ScheduledReports/API.php9
-rw-r--r--plugins/ScheduledReports/ScheduledReports.php31
-rw-r--r--plugins/ScheduledReports/javascripts/pdf.js1
4 files changed, 40 insertions, 4 deletions
diff --git a/plugins/MobileMessaging/MobileMessaging.php b/plugins/MobileMessaging/MobileMessaging.php
index 884ff9b63a..ed57c259f9 100644
--- a/plugins/MobileMessaging/MobileMessaging.php
+++ b/plugins/MobileMessaging/MobileMessaging.php
@@ -9,6 +9,7 @@
namespace Piwik\Plugins\MobileMessaging;
use Piwik\Option;
+use Piwik\Period;
use Piwik\Piwik;
use Piwik\Plugins\API\API as APIPlugins;
use Piwik\Plugins\MobileMessaging\API as APIMobileMessaging;
@@ -177,7 +178,7 @@ class MobileMessaging extends \Piwik\Plugin
}
public function sendReport($reportType, $report, $contents, $filename, $prettyDate, $reportSubject, $reportTitle,
- $additionalFiles)
+ $additionalFiles, Period $period = null, $force)
{
if (self::manageEvent($reportType)) {
$parameters = $report['parameters'];
diff --git a/plugins/ScheduledReports/API.php b/plugins/ScheduledReports/API.php
index a42b5bb209..c7b0d73532 100644
--- a/plugins/ScheduledReports/API.php
+++ b/plugins/ScheduledReports/API.php
@@ -466,7 +466,7 @@ class API extends \Piwik\Plugin\API
}
}
- public function sendReport($idReport, $period = false, $date = false)
+ public function sendReport($idReport, $period = false, $date = false, $force = false)
{
Piwik::checkUserIsNotAnonymous();
@@ -527,6 +527,9 @@ class API extends \Piwik\Plugin\API
* @param string $reportTitle The scheduled report's given title (given by a Piwik user).
* @param array $additionalFiles The list of additional files that should be
* sent with this report.
+ * @param \Piwik\Period $period The period for which the report has been generated.
+ * @param boolean $force A report can only be sent once per period. Setting this to true
+ * will force to send the report even if it has already been sent.
*/
Piwik::postEvent(
self::SEND_REPORT_EVENT,
@@ -538,7 +541,9 @@ class API extends \Piwik\Plugin\API
$prettyDate,
$reportSubject,
$reportTitle,
- $additionalFiles
+ $additionalFiles,
+ \Piwik\Period\Factory::build($report['period'], $date),
+ $force
)
);
diff --git a/plugins/ScheduledReports/ScheduledReports.php b/plugins/ScheduledReports/ScheduledReports.php
index e59e9140ab..e54ad8233f 100644
--- a/plugins/ScheduledReports/ScheduledReports.php
+++ b/plugins/ScheduledReports/ScheduledReports.php
@@ -11,6 +11,8 @@ namespace Piwik\Plugins\ScheduledReports;
use Exception;
use Piwik\Db;
use Piwik\Mail;
+use Piwik\Option;
+use Piwik\Period;
use Piwik\Piwik;
use Piwik\Plugins\MobileMessaging\MobileMessaging;
use Piwik\Plugins\UsersManager\API as APIUsersManager;
@@ -63,6 +65,8 @@ class ScheduledReports extends \Piwik\Plugin
ReportRenderer::CSV_FORMAT => 'plugins/Morpheus/images/export.png',
);
+ const OPTION_KEY_LAST_SENT_DATERANGE = 'report_last_sent_daterange_';
+
/**
* @see Piwik\Plugin::getListHooksRegistered
*/
@@ -256,9 +260,14 @@ class ScheduledReports extends \Piwik\Plugin
}
public function sendReport($reportType, $report, $contents, $filename, $prettyDate, $reportSubject, $reportTitle,
- $additionalFiles)
+ $additionalFiles, Period $period = null, $force)
{
if (self::manageEvent($reportType)) {
+ // Safeguard against sending the same report twice to the same email (unless $force is true)
+ if (!$force && $this->reportAlreadySent($report, $period)) {
+ return;
+ }
+
$periods = self::getPeriodToFrequencyAsAdjective();
$message = Piwik::translate('ScheduledReports_EmailHello');
$subject = Piwik::translate('General_Report') . ' ' . $reportTitle . " - " . $prettyDate;
@@ -363,6 +372,10 @@ class ScheduledReports extends \Piwik\Plugin
}
}
+ if (! $force) {
+ $this->markReportAsSent($report, $period);
+ }
+
foreach ($emails as $email) {
if (empty($email)) {
continue;
@@ -618,4 +631,20 @@ class ScheduledReports extends \Piwik\Plugin
}
}
}
+
+ private function reportAlreadySent($report, Period $period)
+ {
+ $key = self::OPTION_KEY_LAST_SENT_DATERANGE . $report['idreport'];
+
+ $previousDate = Option::get($key);
+
+ return $previousDate === $period->getRangeString();
+ }
+
+ private function markReportAsSent($report, Period $period)
+ {
+ $key = self::OPTION_KEY_LAST_SENT_DATERANGE . $report['idreport'];
+
+ Option::set($key, $period->getRangeString());
+ }
}
diff --git a/plugins/ScheduledReports/javascripts/pdf.js b/plugins/ScheduledReports/javascripts/pdf.js
index 59b16c9d08..da23deb4fd 100644
--- a/plugins/ScheduledReports/javascripts/pdf.js
+++ b/plugins/ScheduledReports/javascripts/pdf.js
@@ -142,6 +142,7 @@ function initManagePdf() {
var idReport = $(this).attr('idreport');
var parameters = getReportAjaxRequest(idReport, 'ScheduledReports.sendReport');
parameters.idReport = idReport;
+ parameters.force = true;
var ajaxHandler = new ajaxHelper();
ajaxHandler.addParams(parameters, 'POST');