PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 5.0.3
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v5.0.3
5.13.0 5.12.1 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 2 years ago Loader.php 2 years ago LoaderLock.php 2 years ago Parameters.php 2 years ago PluginsArchiver.php 2 years ago PluginsArchiverException.php 2 years ago Record.php 2 years ago RecordBuilder.php 2 years ago Rules.php 2 years ago
Parameters.php
279 lines
1 <?php
2
3 /**
4 * Matomo - free/libre analytics platform
5 *
6 * @link https://matomo.org
7 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
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 * Contains the analytics parameters for the reports that are currently being archived. The analytics
20 * parameters include the **website** the reports describe, the **period** of time the reports describe
21 * and the **segment** used to limit the visit set.
22 */
23 class Parameters
24 {
25 /**
26 * @var Site
27 */
28 private $site = null;
29 /**
30 * @var Period
31 */
32 private $period = null;
33 /**
34 * @var Segment
35 */
36 private $segment = null;
37 /**
38 * @var string Plugin name which triggered this archive processor
39 */
40 private $requestedPlugin = false;
41 private $onlyArchiveRequestedPlugin = false;
42 /**
43 * @var string
44 */
45 private $archiveOnlyReport = null;
46 /**
47 * @var bool
48 */
49 private $isArchiveOnlyReportHandled;
50 /**
51 * @var string[]|null
52 */
53 private $foundRequestedReports;
54 /**
55 * Constructor.
56 *
57 * @ignore
58 */
59 public function __construct(Site $site, Period $period, Segment $segment)
60 {
61 $this->site = $site;
62 $this->period = $period;
63 $this->segment = $segment;
64 }
65 /**
66 * If we want to archive only a single report, we can request that via this method.
67 * It is up to each plugin's archiver to respect the setting.
68 *
69 * @param string|string[] $archiveOnlyReport
70 * @api
71 */
72 public function setArchiveOnlyReport($archiveOnlyReport)
73 {
74 $this->archiveOnlyReport = $archiveOnlyReport;
75 }
76 /**
77 * Gets the report we want to archive specifically, or null if none was specified.
78 *
79 * @return string|null
80 * @api
81 */
82 public function getArchiveOnlyReport()
83 {
84 return $this->archiveOnlyReport;
85 }
86 /**
87 * @ignore
88 */
89 public function setRequestedPlugin($plugin)
90 {
91 $this->requestedPlugin = $plugin;
92 }
93 /**
94 * @ignore
95 */
96 public function onlyArchiveRequestedPlugin()
97 {
98 $this->onlyArchiveRequestedPlugin = true;
99 }
100 /**
101 * @ignore
102 */
103 public function shouldOnlyArchiveRequestedPlugin()
104 {
105 return $this->onlyArchiveRequestedPlugin;
106 }
107 /**
108 * @ignore
109 */
110 public function getRequestedPlugin()
111 {
112 return $this->requestedPlugin;
113 }
114 /**
115 * Returns the period we are computing statistics for.
116 *
117 * @return Period
118 * @api
119 */
120 public function getPeriod()
121 {
122 return $this->period;
123 }
124 /**
125 * Returns the array of Period which make up this archive.
126 *
127 * @return \Piwik\Period[]
128 * @ignore
129 */
130 public function getSubPeriods()
131 {
132 if ($this->getPeriod()->getLabel() == 'day') {
133 return array($this->getPeriod());
134 }
135 return $this->getPeriod()->getSubperiods();
136 }
137 /**
138 * @return array
139 * @ignore
140 */
141 public function getIdSites()
142 {
143 $idSite = $this->getSite()->getId();
144 $idSites = array($idSite);
145 Piwik::postEvent('ArchiveProcessor.Parameters.getIdSites', array(&$idSites, $this->getPeriod()));
146 return $idSites;
147 }
148 /**
149 * Returns the site we are computing statistics for.
150 *
151 * @return Site
152 * @api
153 */
154 public function getSite()
155 {
156 return $this->site;
157 }
158 /**
159 * The Segment used to limit the set of visits that are being aggregated.
160 *
161 * @return Segment
162 * @api
163 */
164 public function getSegment()
165 {
166 return $this->segment;
167 }
168 /**
169 * Returns the end day of the period in the site's timezone.
170 *
171 * @return Date
172 */
173 public function getDateEnd()
174 {
175 return $this->getPeriod()->getDateEnd()->setTimezone($this->getSite()->getTimezone());
176 }
177 /**
178 * Returns the start day of the period in the site's timezone.
179 *
180 * @return Date
181 */
182 public function getDateStart()
183 {
184 return $this->getPeriod()->getDateStart()->setTimezone($this->getSite()->getTimezone());
185 }
186 /**
187 * Returns the start day of the period in the site's timezone (includes the time of day).
188 *
189 * @return Date
190 */
191 public function getDateTimeStart()
192 {
193 return $this->getPeriod()->getDateTimeStart()->setTimezone($this->getSite()->getTimezone());
194 }
195 /**
196 * Returns the end day of the period in the site's timezone (includes the time of day).
197 *
198 * @return Date
199 */
200 public function getDateTimeEnd()
201 {
202 return $this->getPeriod()->getDateTimeEnd()->setTimezone($this->getSite()->getTimezone());
203 }
204 /**
205 * @return bool
206 */
207 public function isSingleSiteDayArchive()
208 {
209 return $this->isDayArchive() && $this->isSingleSite();
210 }
211 /**
212 * @return bool
213 */
214 public function isDayArchive()
215 {
216 $period = $this->getPeriod();
217 $secondsInPeriod = $period->getDateEnd()->getTimestampUTC() - $period->getDateStart()->getTimestampUTC();
218 $oneDay = $secondsInPeriod < Date::NUM_SECONDS_IN_DAY;
219 return $oneDay;
220 }
221 public function isSingleSite()
222 {
223 return count($this->getIdSites()) == 1;
224 }
225 public function logStatusDebug()
226 {
227 $temporary = 'definitive archive';
228 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());
229 }
230 public function __toString()
231 {
232 $requestedReports = $this->getArchiveOnlyReport();
233 if (is_array($requestedReports)) {
234 $requestedReports = implode(', ', $requestedReports);
235 }
236 return "[idSite = {$this->getSite()->getId()}, period = {$this->getPeriod()->getLabel()} {$this->getPeriod()->getRangeString()}, segment = {$this->getSegment()->getString()}, plugin = {$this->getRequestedPlugin()}, report = {$requestedReports}]";
237 }
238 /**
239 * Returns whether the setArchiveOnlyReport() was handled by an Archiver.
240 *
241 * @return bool
242 */
243 public function isPartialArchive()
244 {
245 if (!$this->getRequestedPlugin()) {
246 // sanity check, partial archives are only for single reports
247 return false;
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 */
258 public function setIsPartialArchive($isArchiveOnlyReportHandled)
259 {
260 $this->isArchiveOnlyReportHandled = $isArchiveOnlyReportHandled;
261 }
262 public function getArchiveOnlyReportAsArray()
263 {
264 $requestedReport = $this->getArchiveOnlyReport();
265 if (empty($requestedReport)) {
266 return [];
267 }
268 return is_array($requestedReport) ? $requestedReport : [$requestedReport];
269 }
270 public function setFoundRequestedReports(array $foundRecords)
271 {
272 $this->foundRequestedReports = $foundRecords;
273 }
274 public function getFoundRequestedReports()
275 {
276 return $this->foundRequestedReports ?: [];
277 }
278 }
279