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:
authorJulien Moumné <julien@moumne.com>2013-09-29 20:13:46 +0400
committerJulien Moumné <julien@moumne.com>2013-09-29 20:13:46 +0400
commitc36718671a30b52355d53038383476c126e12651 (patch)
tree4a287adc5e2067df4e193fe4506c7e6b024eeb32
parent2071fc412022fd8dd391776d0abeb4cdedd13eaa (diff)
fixes #4163
-rw-r--r--lang/en.json2
-rw-r--r--plugins/PDFReports/PDFReports.php6
-rw-r--r--plugins/SegmentEditor/API.php42
3 files changed, 41 insertions, 9 deletions
diff --git a/lang/en.json b/lang/en.json
index 7763c2ff76..10e45ba7b9 100644
--- a/lang/en.json
+++ b/lang/en.json
@@ -2166,7 +2166,7 @@
"CancelAndReturnToReports": "Cancel and %sreturn to the list of reports%s",
"DescriptionOnFirstPage": "The report description will be displayed on the first page of the report.",
"Segment_Help": "You can select an existing custom segment to apply to data in this email report. You may create and edit custom segments in your dashboard %s(click here to open)%s, then click on the \"%s\" box, then \"%s\".",
- "Segment_Deletion_Error": "This segment cannot be deleted, because it is used to generate the email report(s) %s. To delete this segment, you can first edit these reports so they don't use this segment.",
+ "Segment_Deletion_Error": "This segment cannot be deleted or made invisible to other users because it is used to generate email report(s) %s. Please retry after removing this segment from this report(s).",
"WeeklyScheduleHelp": "Weekly schedule: report will be sent on Monday of each week.",
"MonthlyScheduleHelp": "Monthly schedule: report will be sent the first day of each month.",
"ReportHour": "Send report at",
diff --git a/plugins/PDFReports/PDFReports.php b/plugins/PDFReports/PDFReports.php
index 295adbab79..861add91ca 100644
--- a/plugins/PDFReports/PDFReports.php
+++ b/plugins/PDFReports/PDFReports.php
@@ -94,7 +94,7 @@ class PDFReports extends \Piwik\Plugin
'template_reportParametersPDFReports' => 'template_reportParametersPDFReports',
'UsersManager.deleteUser' => 'deleteUserReport',
'SitesManager.deleteSite' => 'deleteSiteReport',
- APISegmentEditor::DELETE_SEGMENT_EVENT => 'segmentDeletion',
+ APISegmentEditor::DEACTIVATE_SEGMENT_EVENT => 'segmentDeactivation',
);
}
@@ -450,9 +450,9 @@ class PDFReports extends \Piwik\Plugin
}
}
- public function segmentDeletion(&$idSegment)
+ public function segmentDeactivation(&$idSegment)
{
- $reportsUsingSegment = API::getInstance()->getReports(false, false, false, true, $idSegment);
+ $reportsUsingSegment = API::getInstance()->getReports(false, false, false, false, $idSegment);
if (count($reportsUsingSegment) > 0) {
diff --git a/plugins/SegmentEditor/API.php b/plugins/SegmentEditor/API.php
index 7c96fc25b6..4f68bfd6f4 100644
--- a/plugins/SegmentEditor/API.php
+++ b/plugins/SegmentEditor/API.php
@@ -24,7 +24,7 @@ use Piwik\Db;
*/
class API
{
- const DELETE_SEGMENT_EVENT = 'SegmentEditor.delete';
+ const DEACTIVATE_SEGMENT_EVENT = 'SegmentEditor.deactivate';
static private $instance = null;
@@ -135,10 +135,10 @@ class API
{
$this->checkUserIsNotAnonymous();
- // allow plugins using the segment to throw an exception or propagate the deletion
- Piwik_PostEvent(self::DELETE_SEGMENT_EVENT, array(&$idSegment));
+ $this->sendSegmentDeactivationEvent($idSegment);
+
+ $this->getSegmentOrFail($idSegment);
- $segment = $this->getSegmentOrFail($idSegment);
$db = Db::get();
$db->delete(Common::prefixTable('segment'), 'idsegment = ' . $idSegment);
return true;
@@ -167,6 +167,10 @@ class API
$enabledAllUsers = $this->checkEnabledAllUsers($enabledAllUsers);
$autoArchive = $this->checkAutoArchive($autoArchive, $idSite);
+ if($this->segmentVisibilityIsReduced($idSite, $enabledAllUsers, $segment)) {
+ $this->sendSegmentDeactivationEvent($idSegment);
+ }
+
$bind = array(
'name' => $name,
'definition' => $definition,
@@ -240,7 +244,11 @@ class API
return false;
}
try {
- Piwik::checkUserIsSuperUserOrTheUser($segment['login']);
+
+ if(!$segment['enable_all_users']) {
+ Piwik::checkUserIsSuperUserOrTheUser($segment['login']);
+ }
+
} catch (Exception $e) {
throw new Exception("You can only edit the custom segments you have created yourself. This segment was created and 'shared with you' by the Super User. " .
"To modify this segment, you can first create a new one by clicking on 'Add new segment'. Then you can customize the segment's definition.");
@@ -294,4 +302,28 @@ class API
return $segments;
}
+
+ /**
+ * When deleting or making a segment invisible, allow plugins to throw an exception or propagate the action
+ *
+ * @param $idSegment
+ */
+ private function sendSegmentDeactivationEvent($idSegment)
+ {
+ Piwik_PostEvent(self::DEACTIVATE_SEGMENT_EVENT, array(&$idSegment));
+ }
+
+ /**
+ * @param $idSiteNewValue
+ * @param $enableAllUserNewValue
+ * @param $segment
+ * @return bool
+ */
+ private function segmentVisibilityIsReduced($idSiteNewValue, $enableAllUserNewValue, $segment)
+ {
+ $allUserVisibilityIsDropped = $segment['enable_all_users'] && !$enableAllUserNewValue;
+ $allWebsiteVisibilityIsDropped = !isset($segment['idSite']) && $idSiteNewValue;
+
+ return $allUserVisibilityIsDropped || $allWebsiteVisibilityIsDropped;
+ }
}