PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 4.13.3
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v4.13.3
5.12.0 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 4 years ago Loader.php 3 years ago LoaderLock.php 4 years ago Parameters.php 4 years ago PluginsArchiver.php 3 years ago PluginsArchiverException.php 5 years ago Rules.php 4 years ago
Parameters.php
327 lines
1 <?php
2 /**
3 * Matomo - free/libre analytics platform
4 *
5 * @link https://matomo.org
6 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
7 *
8 */
9
10 namespace Piwik\ArchiveProcessor;
11
12 use Piwik\Date;
13 use Piwik\Log;
14 use Piwik\Period;
15 use Piwik\Piwik;
16 use Piwik\Segment;
17 use Piwik\Site;
18
19 /**
20 * Contains the analytics parameters for the reports that are currently being archived. The analytics
21 * parameters include the **website** the reports describe, the **period** of time the reports describe
22 * and the **segment** used to limit the visit set.
23 */
24 class Parameters
25 {
26 /**
27 * @var Site
28 */
29 private $site = null;
30
31 /**
32 * @var Period
33 */
34 private $period = null;
35
36 /**
37 * @var Segment
38 */
39 private $segment = null;
40
41 /**
42 * @var string Plugin name which triggered this archive processor
43 */
44 private $requestedPlugin = false;
45
46 private $onlyArchiveRequestedPlugin = false;
47
48 /**
49 * @var bool
50 */
51 private $isRootArchiveRequest = true;
52
53 /**
54 * @var string
55 */
56 private $archiveOnlyReport = null;
57
58 /**
59 * @var bool
60 */
61 private $isArchiveOnlyReportHandled;
62
63 /**
64 * Constructor.
65 *
66 * @ignore
67 */
68 public function __construct(Site $site, Period $period, Segment $segment)
69 {
70 $this->site = $site;
71 $this->period = $period;
72 $this->segment = $segment;
73 }
74
75 /**
76 * If we want to archive only a single report, we can request that via this method.
77 * It is up to each plugin's archiver to respect the setting.
78 *
79 * @param string $archiveOnlyReport
80 * @api
81 */
82 public function setArchiveOnlyReport($archiveOnlyReport)
83 {
84 $this->archiveOnlyReport = $archiveOnlyReport;
85 }
86
87 /**
88 * Gets the report we want to archive specifically, or null if none was specified.
89 *
90 * @return string|null
91 * @api
92 */
93 public function getArchiveOnlyReport()
94 {
95 return $this->archiveOnlyReport;
96 }
97
98 /**
99 * @ignore
100 */
101 public function setRequestedPlugin($plugin)
102 {
103 $this->requestedPlugin = $plugin;
104 }
105
106 /**
107 * @ignore
108 */
109 public function onlyArchiveRequestedPlugin()
110 {
111 $this->onlyArchiveRequestedPlugin = true;
112 }
113
114 /**
115 * @ignore
116 */
117 public function shouldOnlyArchiveRequestedPlugin()
118 {
119 return $this->onlyArchiveRequestedPlugin;
120 }
121
122 /**
123 * @ignore
124 */
125 public function getRequestedPlugin()
126 {
127 return $this->requestedPlugin;
128 }
129
130 /**
131 * Returns the period we are computing statistics for.
132 *
133 * @return Period
134 * @api
135 */
136 public function getPeriod()
137 {
138 return $this->period;
139 }
140
141 /**
142 * Returns the array of Period which make up this archive.
143 *
144 * @return \Piwik\Period[]
145 * @ignore
146 */
147 public function getSubPeriods()
148 {
149 if ($this->getPeriod()->getLabel() == 'day') {
150 return array( $this->getPeriod() );
151 }
152 return $this->getPeriod()->getSubperiods();
153 }
154
155 /**
156 * @return array
157 * @ignore
158 */
159 public function getIdSites()
160 {
161 $idSite = $this->getSite()->getId();
162
163 $idSites = array($idSite);
164
165 Piwik::postEvent('ArchiveProcessor.Parameters.getIdSites', array(&$idSites, $this->getPeriod()));
166
167 return $idSites;
168 }
169
170 /**
171 * Returns the site we are computing statistics for.
172 *
173 * @return Site
174 * @api
175 */
176 public function getSite()
177 {
178 return $this->site;
179 }
180
181 /**
182 * The Segment used to limit the set of visits that are being aggregated.
183 *
184 * @return Segment
185 * @api
186 */
187 public function getSegment()
188 {
189 return $this->segment;
190 }
191
192 /**
193 * Returns the end day of the period in the site's timezone.
194 *
195 * @return Date
196 */
197 public function getDateEnd()
198 {
199 return $this->getPeriod()->getDateEnd()->setTimezone($this->getSite()->getTimezone());
200 }
201
202 /**
203 * Returns the start day of the period in the site's timezone.
204 *
205 * @return Date
206 */
207 public function getDateStart()
208 {
209 return $this->getPeriod()->getDateStart()->setTimezone($this->getSite()->getTimezone());
210 }
211
212 /**
213 * Returns the start day of the period in the site's timezone (includes the time of day).
214 *
215 * @return Date
216 */
217 public function getDateTimeStart()
218 {
219 return $this->getPeriod()->getDateTimeStart()->setTimezone($this->getSite()->getTimezone());
220 }
221
222 /**
223 * Returns the end day of the period in the site's timezone (includes the time of day).
224 *
225 * @return Date
226 */
227 public function getDateTimeEnd()
228 {
229 return $this->getPeriod()->getDateTimeEnd()->setTimezone($this->getSite()->getTimezone());
230 }
231
232 /**
233 * @return bool
234 */
235 public function isSingleSiteDayArchive()
236 {
237 return $this->isDayArchive() && $this->isSingleSite();
238 }
239
240 /**
241 * @return bool
242 */
243 public function isDayArchive()
244 {
245 $period = $this->getPeriod();
246 $secondsInPeriod = $period->getDateEnd()->getTimestampUTC() - $period->getDateStart()->getTimestampUTC();
247 $oneDay = $secondsInPeriod < Date::NUM_SECONDS_IN_DAY;
248
249 return $oneDay;
250 }
251
252 public function isSingleSite()
253 {
254 return count($this->getIdSites()) == 1;
255 }
256
257 public function logStatusDebug()
258 {
259 $temporary = 'definitive archive';
260 Log::debug(
261 "%s archive, idSite = %d (%s), segment '%s', plugin = '%s', report = '%s', UTC datetime [%s -> %s]",
262 $this->getPeriod()->getLabel(),
263 $this->getSite()->getId(),
264 $temporary,
265 $this->getSegment()->getString(),
266 $this->getRequestedPlugin(),
267 $this->getArchiveOnlyReport(),
268 $this->getDateStart()->getDateStartUTC(),
269 $this->getDateEnd()->getDateEndUTC()
270 );
271 }
272
273 /**
274 * Returns `true` if these parameters are part of an initial archiving request.
275 * Returns `false` if these parameters are for an archiving request that was initiated
276 * during archiving.
277 *
278 * @return bool
279 */
280 public function isRootArchiveRequest()
281 {
282 return $this->isRootArchiveRequest;
283 }
284
285 /**
286 * Sets whether these parameters are part of the initial archiving request or if they are
287 * for a request that was initiated during archiving.
288 *
289 * @param $isRootArchiveRequest
290 */
291 public function setIsRootArchiveRequest($isRootArchiveRequest)
292 {
293 $this->isRootArchiveRequest = $isRootArchiveRequest;
294 }
295
296 public function __toString()
297 {
298 return "[idSite = {$this->getSite()->getId()}, period = {$this->getPeriod()->getLabel()} {$this->getPeriod()->getRangeString()}, segment = {$this->getSegment()->getString()}, plugin = {$this->getRequestedPlugin()}, report = {$this->getArchiveOnlyReport()}]";
299 }
300
301 /**
302 * Returns whether the setArchiveOnlyReport() was handled by an Archiver.
303 *
304 * @return bool
305 */
306 public function isPartialArchive()
307 {
308 if (!$this->getRequestedPlugin()) { // sanity check, partial archives are only for single reports
309 return false;
310 }
311
312 return $this->isArchiveOnlyReportHandled;
313 }
314
315 /**
316 * If a plugin's archiver handles the setArchiveOnlyReport() setting, it should call this method
317 * so it is known that the archive only contains the requested report. This should be called
318 * in an Archiver's __construct method.
319 *
320 * @param bool $isArchiveOnlyReportHandled
321 */
322 public function setIsPartialArchive($isArchiveOnlyReportHandled)
323 {
324 $this->isArchiveOnlyReportHandled = $isArchiveOnlyReportHandled;
325 }
326 }
327