From 2b77bb4d609dd0ec377a9edc32536f22dd4dabb2 Mon Sep 17 00:00:00 2001 From: diosmosis Date: Thu, 9 Aug 2018 04:24:16 -0700 Subject: Add notification when report w/ segment has no data, but segment is unprocessed (#12823) * When a report has no data, check if it is for an unprocessed segment and display an explanatory notification. * Remove transient notifications on reporting page change, allow datatable views to add notifications, use to display unprocessed segment message. * Update changelog. * Internationalize unprocessed segment message. * Parse notification divs in dashboardWidget.js when setting widget content. * Tweak message. * Change PR to use different approach: throw exception when no archives found and segment is used, then detect exception in new event. * Update changelog + document new event. * Unfinished review changes * more review fixes * Do not show notification w/ custom segments. * apply pr review * Apply review. * undo escaping since it was not needed & get test to pass * Different strategy + new test. * Fix tests. * Update two expected screenshots. --- .../SegmentEditor/UnprocessedSegmentException.php | 98 ++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 plugins/SegmentEditor/UnprocessedSegmentException.php (limited to 'plugins/SegmentEditor/UnprocessedSegmentException.php') diff --git a/plugins/SegmentEditor/UnprocessedSegmentException.php b/plugins/SegmentEditor/UnprocessedSegmentException.php new file mode 100644 index 0000000000..c0ddc338e2 --- /dev/null +++ b/plugins/SegmentEditor/UnprocessedSegmentException.php @@ -0,0 +1,98 @@ +segment = $segment; + $this->storedSegment = $storedSegment; + $this->isSegmentToPreprocess = $isSegmentToPreprocess; + } + + /** + * @return Segment + */ + public function getSegment() + { + return $this->segment; + } + + /** + * @return array|null + */ + public function getStoredSegment() + { + return $this->storedSegment; + } + + private static function getErrorMessage(Segment $segment, $isSegmentToPreprocess, array $storedSegment = null) + { + if (empty($storedSegment)) { + // the segment was not created through the segment editor + return Piwik::translate('SegmentEditor_CustomUnprocessedSegmentApiError1') + . ' ' . Piwik::translate('SegmentEditor_CustomUnprocessedSegmentApiError2') + . ' ' . Piwik::translate('SegmentEditor_CustomUnprocessedSegmentApiError3') + . ' ' . Piwik::translate('SegmentEditor_CustomUnprocessedSegmentApiError4') + . ' ' . Piwik::translate('SegmentEditor_CustomUnprocessedSegmentApiError5') + . ' ' . Piwik::translate('SegmentEditor_CustomUnprocessedSegmentApiError6') + . ' ' . Piwik::translate('SegmentEditor_UnprocessedSegmentInVisitorLog3'); + } + + $segmentName = !empty($storedSegment['name']) ? $storedSegment['name'] : $segment->getString(); + + if (!$isSegmentToPreprocess) { + // the segment was created in the segment editor, but set to be processed in real time + return Piwik::translate('SegmentEditor_UnprocessedSegmentApiError1', [$segmentName, Piwik::translate('SegmentEditor_AutoArchiveRealTime')]) + . ' ' . Piwik::translate('SegmentEditor_UnprocessedSegmentApiError2', [Piwik::translate('SegmentEditor_AutoArchivePreProcessed')]) + . ' ' . Piwik::translate('SegmentEditor_UnprocessedSegmentApiError3'); + } + + // the segment is set to be processed during cron archiving, but has not been processed yet + return Piwik::translate('SegmentEditor_UnprocessedSegmentNoData1', ['(' . $segmentName . ')']) + . ' ' . Piwik::translate('SegmentEditor_UnprocessedSegmentNoData2') + . ' ' . Piwik::translate('SegmentEditor_CustomUnprocessedSegmentApiError5') + . ' ' . Piwik::translate('SegmentEditor_CustomUnprocessedSegmentApiError6') + . ' ' . Piwik::translate('SegmentEditor_UnprocessedSegmentInVisitorLog3'); + } + + /** + * @return bool + */ + public function isSegmentToPreprocess() + { + return $this->isSegmentToPreprocess; + } +} \ No newline at end of file -- cgit v1.2.3