PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 4.15.2
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v4.15.2
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 / Plugin / Archiver.php
matomo / app / core / Plugin Last commit date
Dimension 3 years ago API.php 3 years ago AggregatedMetric.php 5 years ago ArchivedMetric.php 3 years ago Archiver.php 3 years ago Categories.php 5 years ago ComponentFactory.php 5 years ago ComputedMetric.php 3 years ago ConsoleCommand.php 5 years ago Controller.php 3 years ago ControllerAdmin.php 3 years ago Dependency.php 4 years ago LogTablesProvider.php 5 years ago Manager.php 4 years ago Menu.php 5 years ago MetadataLoader.php 4 years ago Metric.php 3 years ago PluginException.php 5 years ago ProcessedMetric.php 5 years ago ReleaseChannels.php 5 years ago Report.php 2 years ago ReportsProvider.php 3 years ago RequestProcessors.php 5 years ago Segment.php 3 years ago SettingsProvider.php 5 years ago Tasks.php 3 years ago ThemeStyles.php 5 years ago ViewDataTable.php 5 years ago Visualization.php 2 years ago WidgetsProvider.php 5 years ago
Archiver.php
198 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\Plugin;
11
12 use Piwik\ArchiveProcessor;
13 use Piwik\Config as PiwikConfig;
14 use Piwik\ErrorHandler;
15
16 /**
17 * The base class that should be extended by plugins that compute their own
18 * analytics data.
19 *
20 * Descendants should implement the {@link aggregateDayReport()} and {@link aggregateMultipleReports()}
21 * methods.
22 *
23 * Both of these methods should persist analytics data using the {@link \Piwik\ArchiveProcessor}
24 * instance returned by {@link getProcessor()}. The {@link aggregateDayReport()} method should
25 * compute analytics data using the {@link \Piwik\DataAccess\LogAggregator} instance
26 * returned by {@link getLogAggregator()}.
27 *
28 * ### Examples
29 *
30 * **Extending Archiver**
31 *
32 * class MyArchiver extends Archiver
33 * {
34 * public function aggregateDayReport()
35 * {
36 * $logAggregator = $this->getLogAggregator();
37 *
38 * $data = $logAggregator->queryVisitsByDimension(...);
39 *
40 * $dataTable = new DataTable();
41 * $dataTable->addRowsFromSimpleArray($data);
42 *
43 * $archiveProcessor = $this->getProcessor();
44 * $archiveProcessor->insertBlobRecords('MyPlugin_myReport', $dataTable->getSerialized(500));
45 * }
46 *
47 * public function aggregateMultipleReports()
48 * {
49 * $archiveProcessor = $this->getProcessor();
50 * $archiveProcessor->aggregateDataTableRecords('MyPlugin_myReport', 500);
51 * }
52 * }
53 *
54 * @api
55 */
56 abstract class Archiver
57 {
58 /**
59 * @var \Piwik\ArchiveProcessor
60 */
61 private $processor;
62
63 /**
64 * @var bool
65 */
66 private $enabled;
67
68 /**
69 * @var mixed
70 */
71 protected $maximumRows;
72
73 /**
74 * Constructor.
75 *
76 * @param ArchiveProcessor $processor The ArchiveProcessor instance to use when persisting archive
77 * data.
78 */
79 public function __construct(ArchiveProcessor $processor)
80 {
81 $this->maximumRows = PiwikConfig::getInstance()->General['datatable_archiving_maximum_rows_standard'];
82 $this->processor = $processor;
83 $this->enabled = true;
84 }
85
86 /**
87 * @ignore
88 */
89 final public function callAggregateDayReport()
90 {
91 try {
92 ErrorHandler::pushFatalErrorBreadcrumb(static::class);
93
94 $this->aggregateDayReport();
95 } finally {
96 ErrorHandler::popFatalErrorBreadcrumb();
97 }
98 }
99
100 /**
101 * @ignore
102 */
103 final public function callAggregateMultipleReports()
104 {
105 try {
106 ErrorHandler::pushFatalErrorBreadcrumb(static::class);
107
108 $this->aggregateMultipleReports();
109 } finally {
110 ErrorHandler::popFatalErrorBreadcrumb();
111 }
112 }
113
114 /**
115 * Archives data for a day period.
116 *
117 * Implementations of this method should do more computation intensive activities such
118 * as aggregating data across log tables. Since this method only deals w/ data logged for a day,
119 * aggregating individual log table rows isn't a problem. Doing this for any larger period,
120 * however, would cause performance degradation.
121 *
122 * Aggregate log table rows using a {@link Piwik\DataAccess\LogAggregator} instance. Get a
123 * {@link Piwik\DataAccess\LogAggregator} instance using the {@link getLogAggregator()} method.
124 */
125 abstract public function aggregateDayReport();
126
127 /**
128 * Archives data for a non-day period.
129 *
130 * Implementations of this method should only aggregate existing reports of subperiods of the
131 * current period. For example, it is more efficient to aggregate reports for each day of a
132 * week than to aggregate each log entry of the week.
133 *
134 * Use {@link Piwik\ArchiveProcessor::aggregateNumericMetrics()} and {@link Piwik\ArchiveProcessor::aggregateDataTableRecords()}
135 * to aggregate archived reports. Get the {@link Piwik\ArchiveProcessor} instance using the {@link getProcessor()}
136 * method.
137 */
138 abstract public function aggregateMultipleReports();
139
140 /**
141 * Returns a {@link Piwik\ArchiveProcessor} instance that can be used to insert archive data for
142 * the period, segment and site we are archiving data for.
143 *
144 * @return \Piwik\ArchiveProcessor
145 * @api
146 */
147 protected function getProcessor()
148 {
149 return $this->processor;
150 }
151
152 /**
153 * Returns a {@link Piwik\DataAccess\LogAggregator} instance that can be used to aggregate log table rows
154 * for this period, segment and site.
155 *
156 * @return \Piwik\DataAccess\LogAggregator
157 * @api
158 */
159 protected function getLogAggregator()
160 {
161 return $this->getProcessor()->getLogAggregator();
162 }
163
164 public function disable()
165 {
166 $this->enabled = false;
167 }
168
169 /**
170 * Whether this Archiver should be used or not.
171 *
172 * @return bool
173 */
174 public function isEnabled()
175 {
176 return $this->enabled;
177 }
178
179 /**
180 * By overwriting this method and returning true, a plugin archiver can force the archiving to run even when there
181 * was no visit for the website/date/period/segment combination
182 * (by default, archivers are skipped when there is no visit).
183 *
184 * @return bool
185 */
186 public static function shouldRunEvenWhenNoVisits()
187 {
188 return false;
189 }
190
191 protected function isRequestedReport(string $reportName)
192 {
193 $requestedReport = $this->getProcessor()->getParams()->getArchiveOnlyReport();
194
195 return empty($requestedReport) || $requestedReport == $reportName;
196 }
197 }
198