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:
authorKate Butler <kate@innocraft.com>2019-06-24 07:50:47 +0300
committerThomas Steur <tsteur@users.noreply.github.com>2019-06-24 07:50:46 +0300
commit0dbeb8c40e86a529a668de6e3cd1cd5deff59299 (patch)
treef3a9a81bade205c03cfe4f3aa60940205f8023fe /plugins/ScheduledReports
parente4899e41a84b0833043254fb74e0bd9ec26fc081 (diff)
Only send scheduled report to unique email addresses (#14561)
Diffstat (limited to 'plugins/ScheduledReports')
-rw-r--r--plugins/ScheduledReports/ScheduledReports.php3
-rw-r--r--plugins/ScheduledReports/tests/Integration/ApiTest.php29
2 files changed, 31 insertions, 1 deletions
diff --git a/plugins/ScheduledReports/ScheduledReports.php b/plugins/ScheduledReports/ScheduledReports.php
index 575d771814..079e6ac0a2 100644
--- a/plugins/ScheduledReports/ScheduledReports.php
+++ b/plugins/ScheduledReports/ScheduledReports.php
@@ -342,6 +342,7 @@ class ScheduledReports extends \Piwik\Plugin
$emails[] = $user['email'];
}
}
+ $emails = array_unique($emails);
if (! $force) {
$this->markReportAsSent($report, $period);
@@ -571,7 +572,7 @@ class ScheduledReports extends \Piwik\Plugin
throw new Exception(Piwik::translate('UsersManager_ExceptionInvalidEmail') . ' (' . $email . ')');
}
}
- $additionalEmails = array_values(array_filter($additionalEmails));
+ $additionalEmails = array_values(array_unique(array_filter($additionalEmails)));
return $additionalEmails;
}
diff --git a/plugins/ScheduledReports/tests/Integration/ApiTest.php b/plugins/ScheduledReports/tests/Integration/ApiTest.php
index e445d99270..f7914dce34 100644
--- a/plugins/ScheduledReports/tests/Integration/ApiTest.php
+++ b/plugins/ScheduledReports/tests/Integration/ApiTest.php
@@ -717,6 +717,35 @@ class ApiTest extends IntegrationTestCase
);
}
+ public function test_addReport_onlySavesUniqueEmailAddresses()
+ {
+ $data = array(
+ 'idsite' => $this->idSite,
+ 'description' => 'test description"',
+ 'type' => 'email',
+ 'period' => Schedule::PERIOD_DAY,
+ 'period_param' => 'month',
+ 'hour' => '4',
+ 'format' => 'pdf',
+ 'reports' => array('UserCountry_getCountry'),
+ 'parameters' => array(
+ 'displayFormat' => '1',
+ 'emailMe' => true,
+ 'additionalEmails' => array('test@test.com', 'test@test.com', 't2@test.com', 'test@test.com'),
+ 'evolutionGraph' => true
+ )
+ );
+
+ self::addReport($data);
+
+ // Testing getReports without parameters
+ $tmp = APIScheduledReports::getInstance()->getReports();
+ $report = reset($tmp);
+ $additionalEmails = $report['parameters']['additionalEmails'];
+ $expectedEmails = array('test@test.com', 't2@test.com');
+ $this->assertReportsEqual($expectedEmails, $additionalEmails);
+ }
+
private function assertReportsEqual($report, $data)
{
foreach ($data as $key => $value) {