PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 1.3.1
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v1.3.1
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 6 years ago API.php 6 years ago AggregatedMetric.php 6 years ago ArchivedMetric.php 6 years ago Archiver.php 6 years ago Categories.php 6 years ago ComponentFactory.php 6 years ago ComputedMetric.php 6 years ago ConsoleCommand.php 6 years ago Controller.php 6 years ago ControllerAdmin.php 6 years ago Dependency.php 6 years ago LogTablesProvider.php 6 years ago Manager.php 6 years ago Menu.php 6 years ago MetadataLoader.php 6 years ago Metric.php 6 years ago PluginException.php 6 years ago ProcessedMetric.php 6 years ago ReleaseChannels.php 6 years ago Report.php 6 years ago ReportsProvider.php 6 years ago RequestProcessors.php 6 years ago Segment.php 6 years ago SettingsProvider.php 6 years ago Tasks.php 6 years ago ThemeStyles.php 6 years ago ViewDataTable.php 6 years ago Visualization.php 6 years ago WidgetsProvider.php 6 years ago
Archiver.php
186 lines
1 <?php
2 /**
3 * Piwik - 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 * Constructor.
70 *
71 * @param ArchiveProcessor $processor The ArchiveProcessor instance to use when persisting archive
72 * data.
73 */
74 public function __construct(ArchiveProcessor $processor)
75 {
76 $this->maximumRows = PiwikConfig::getInstance()->General['datatable_archiving_maximum_rows_standard'];
77 $this->processor = $processor;
78 $this->enabled = true;
79 }
80
81 /**
82 * @ignore
83 */
84 final public function callAggregateDayReport()
85 {
86 try {
87 ErrorHandler::pushFatalErrorBreadcrumb(static::class);
88
89 $this->aggregateDayReport();
90 } finally {
91 ErrorHandler::popFatalErrorBreadcrumb();
92 }
93 }
94
95 /**
96 * @ignore
97 */
98 final public function callAggregateMultipleReports()
99 {
100 try {
101 ErrorHandler::pushFatalErrorBreadcrumb(static::class);
102
103 $this->aggregateMultipleReports();
104 } finally {
105 ErrorHandler::popFatalErrorBreadcrumb();
106 }
107 }
108
109 /**
110 * Archives data for a day period.
111 *
112 * Implementations of this method should do more computation intensive activities such
113 * as aggregating data across log tables. Since this method only deals w/ data logged for a day,
114 * aggregating individual log table rows isn't a problem. Doing this for any larger period,
115 * however, would cause performance degradation.
116 *
117 * Aggregate log table rows using a {@link Piwik\DataAccess\LogAggregator} instance. Get a
118 * {@link Piwik\DataAccess\LogAggregator} instance using the {@link getLogAggregator()} method.
119 */
120 abstract public function aggregateDayReport();
121
122 /**
123 * Archives data for a non-day period.
124 *
125 * Implementations of this method should only aggregate existing reports of subperiods of the
126 * current period. For example, it is more efficient to aggregate reports for each day of a
127 * week than to aggregate each log entry of the week.
128 *
129 * Use {@link Piwik\ArchiveProcessor::aggregateNumericMetrics()} and {@link Piwik\ArchiveProcessor::aggregateDataTableRecords()}
130 * to aggregate archived reports. Get the {@link Piwik\ArchiveProcessor} instance using the {@link getProcessor()}
131 * method.
132 */
133 abstract public function aggregateMultipleReports();
134
135 /**
136 * Returns a {@link Piwik\ArchiveProcessor} instance that can be used to insert archive data for
137 * the period, segment and site we are archiving data for.
138 *
139 * @return \Piwik\ArchiveProcessor
140 * @api
141 */
142 protected function getProcessor()
143 {
144 return $this->processor;
145 }
146
147 /**
148 * Returns a {@link Piwik\DataAccess\LogAggregator} instance that can be used to aggregate log table rows
149 * for this period, segment and site.
150 *
151 * @return \Piwik\DataAccess\LogAggregator
152 * @api
153 */
154 protected function getLogAggregator()
155 {
156 return $this->getProcessor()->getLogAggregator();
157 }
158
159 public function disable()
160 {
161 $this->enabled = false;
162 }
163
164 /**
165 * Whether this Archiver should be used or not.
166 *
167 * @return bool
168 */
169 public function isEnabled()
170 {
171 return $this->enabled;
172 }
173
174 /**
175 * By overwriting this method and returning true, a plugin archiver can force the archiving to run even when there
176 * was no visit for the website/date/period/segment combination
177 * (by default, archivers are skipped when there is no visit).
178 *
179 * @return bool
180 */
181 public static function shouldRunEvenWhenNoVisits()
182 {
183 return false;
184 }
185 }
186