PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / trunk
Matomo Analytics – Powerful, Privacy-First Insights for WordPress vtrunk
5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / core / ArchiveProcessor / Parameters.php
matomo / app / core / ArchiveProcessor Last commit date
ArchivingStatus.php 5 months ago Loader.php 4 months ago LoaderLock.php 1 year ago Parameters.php 1 month ago PluginsArchiver.php 1 year ago PluginsArchiverException.php 2 years ago Record.php 3 months ago RecordBuilder.php 1 month ago Rules.php 3 months ago
Parameters.php
280 lines
1 <?php
2
3 /**
4 * Matomo - free/libre analytics platform
5 *
6 * @link https://matomo.org
7 * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
8 */
9 namespace Piwik\ArchiveProcessor;
10
11 use Piwik\Date;
12 use Piwik\Log;
13 use Piwik\Period;
14 use Piwik\Piwik;
15 use Piwik\Segment;
16 use Piwik\Site;
17 /**
18 * Contains the analytics parameters for the reports that are currently being archived. The analytics
19 * parameters include the **website** the reports describe, the **period** of time the reports describe
20 * and the **segment** used to limit the visit set.
21 */
22 class Parameters
23 {
24 /**
25 * @var Site
26 */
27 private $site = null;
28 /**
29 * @var Period
30 */
31 private $period = null;
32 /**
33 * @var Segment
34 */
35 private $segment = null;
36 /**
37 * @var string Plugin name which triggered this archive processor
38 */
39 private $requestedPlugin = \false;
40 private $onlyArchiveRequestedPlugin = \false;
41 /**
42 * @var string
43 */
44 private $archiveOnlyReport = null;
45 /**
46 * @var bool
47 */
48 private $isArchiveOnlyReportHandled = \false;
49 /**
50 * @var string[]|null
51 */
52 private $foundRequestedReports;
53 /**
54 * @ignore
55 */
56 public function __construct(Site $site, Period $period, Segment $segment)
57 {
58 $this->site = $site;
59 $this->period = $period;
60 $this->segment = $segment;
61 }
62 /**
63 * If we want to archive only a single report, we can request that via this method.
64 * It is up to each plugin's archiver to respect the setting.
65 *
66 * @param string|string[] $archiveOnlyReport
67 * @api
68 */
69 public function setArchiveOnlyReport($archiveOnlyReport)
70 {
71 $this->archiveOnlyReport = $archiveOnlyReport;
72 }
73 /**
74 * Gets the report we want to archive specifically, or null if none was specified.
75 *
76 * @return string|null
77 * @api
78 */
79 public function getArchiveOnlyReport()
80 {
81 return $this->archiveOnlyReport;
82 }
83 /**
84 * @ignore
85 */
86 public function setRequestedPlugin($plugin)
87 {
88 $this->requestedPlugin = $plugin;
89 }
90 /**
91 * @ignore
92 */
93 public function onlyArchiveRequestedPlugin()
94 {
95 $this->onlyArchiveRequestedPlugin = \true;
96 }
97 /**
98 * @ignore
99 */
100 public function shouldOnlyArchiveRequestedPlugin()
101 {
102 return $this->onlyArchiveRequestedPlugin;
103 }
104 /**
105 * @ignore
106 */
107 public function getRequestedPlugin()
108 {
109 return $this->requestedPlugin;
110 }
111 /**
112 * Returns the period we are computing statistics for.
113 *
114 * @return Period
115 * @api
116 */
117 public function getPeriod()
118 {
119 return $this->period;
120 }
121 /**
122 * Returns the array of Period which make up this archive.
123 *
124 * @return \Piwik\Period[]
125 * @ignore
126 */
127 public function getSubPeriods()
128 {
129 if ($this->getPeriod()->getLabel() == 'day') {
130 return array($this->getPeriod());
131 }
132 return $this->getPeriod()->getSubperiods();
133 }
134 /**
135 * @return array
136 * @ignore
137 */
138 public function getIdSites()
139 {
140 $idSite = $this->getSite()->getId();
141 $idSites = array($idSite);
142 Piwik::postEvent('ArchiveProcessor.Parameters.getIdSites', array(&$idSites, $this->getPeriod()));
143 return $idSites;
144 }
145 /**
146 * Returns the site we are computing statistics for.
147 *
148 * @return Site
149 * @api
150 */
151 public function getSite()
152 {
153 return $this->site;
154 }
155 /**
156 * The Segment used to limit the set of visits that are being aggregated.
157 *
158 * @return Segment
159 * @api
160 */
161 public function getSegment()
162 {
163 return $this->segment;
164 }
165 /**
166 * Returns the end day of the period in the site's timezone.
167 *
168 * @return Date
169 */
170 public function getDateEnd()
171 {
172 return $this->getPeriod()->getDateEnd()->setTimezone($this->getSite()->getTimezone());
173 }
174 /**
175 * Returns the start day of the period in the site's timezone.
176 *
177 * @return Date
178 */
179 public function getDateStart()
180 {
181 return $this->getPeriod()->getDateStart()->setTimezone($this->getSite()->getTimezone());
182 }
183 /**
184 * Returns the start day of the period in the site's timezone (includes the time of day).
185 *
186 * @return Date
187 */
188 public function getDateTimeStart()
189 {
190 return $this->getPeriod()->getDateTimeStart()->setTimezone($this->getSite()->getTimezone());
191 }
192 /**
193 * Returns the end day of the period in the site's timezone (includes the time of day).
194 *
195 * @return Date
196 */
197 public function getDateTimeEnd()
198 {
199 return $this->getPeriod()->getDateTimeEnd()->setTimezone($this->getSite()->getTimezone());
200 }
201 /**
202 * @return bool
203 */
204 public function isSingleSiteDayArchive()
205 {
206 return $this->isDayArchive() && $this->isSingleSite();
207 }
208 /**
209 * @return bool
210 */
211 public function isDayArchive()
212 {
213 $period = $this->getPeriod();
214 $secondsInPeriod = $period->getDateEnd()->getTimestampUTC() - $period->getDateStart()->getTimestampUTC();
215 $oneDay = $secondsInPeriod < Date::NUM_SECONDS_IN_DAY;
216 return $oneDay;
217 }
218 public function isSingleSite()
219 {
220 return count($this->getIdSites()) == 1;
221 }
222 public function logStatusDebug()
223 {
224 $temporary = 'definitive archive';
225 Log::debug("%s archive, idSite = %d (%s), segment '%s', plugin = '%s', report = '%s', UTC datetime [%s -> %s]", $this->getPeriod()->getLabel(), $this->getSite()->getId(), $temporary, $this->getSegment()->getString(), $this->getRequestedPlugin(), $this->getArchiveOnlyReport(), $this->getDateStart()->getDateStartUTC(), $this->getDateEnd()->getDateEndUTC());
226 }
227 public function __toString()
228 {
229 $requestedReports = $this->getArchiveOnlyReport();
230 if (is_array($requestedReports)) {
231 $requestedReports = implode(', ', $requestedReports);
232 }
233 return "[idSite = {$this->getSite()->getId()}, period = {$this->getPeriod()->getLabel()} {$this->getPeriod()->getRangeString()}, segment = {$this->getSegment()->getString()}, plugin = {$this->getRequestedPlugin()}, report = {$requestedReports}]";
234 }
235 /**
236 * Returns whether the setArchiveOnlyReport() was handled by an Archiver.
237 *
238 * @return bool
239 */
240 public function isPartialArchive()
241 {
242 if (!$this->getRequestedPlugin()) {
243 // sanity check, partial archives are only for single reports
244 return \false;
245 }
246 if (!empty($this->getArchiveOnlyReport())) {
247 return \true;
248 }
249 return $this->isArchiveOnlyReportHandled;
250 }
251 /**
252 * If a plugin's archiver handles the setArchiveOnlyReport() setting, it should call this method
253 * so it is known that the archive only contains the requested report. This should be called
254 * in an Archiver's __construct method.
255 *
256 * @param bool $isArchiveOnlyReportHandled
257 * @deprecated use `setArchiveOnlyReport` instead
258 */
259 public function setIsPartialArchive($isArchiveOnlyReportHandled)
260 {
261 $this->isArchiveOnlyReportHandled = $isArchiveOnlyReportHandled;
262 }
263 public function getArchiveOnlyReportAsArray()
264 {
265 $requestedReport = $this->getArchiveOnlyReport();
266 if (empty($requestedReport)) {
267 return [];
268 }
269 return is_array($requestedReport) ? $requestedReport : [$requestedReport];
270 }
271 public function setFoundRequestedReports(array $foundRecords)
272 {
273 $this->foundRequestedReports = $foundRecords;
274 }
275 public function getFoundRequestedReports()
276 {
277 return $this->foundRequestedReports ?: [];
278 }
279 }
280