PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 5.12.1
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v5.12.1
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 / BlobTableAggregator.php
matomo / app / core / ArchiveProcessor Last commit date
ArchivingStatus.php 6 months ago BlobTableAggregator.php 2 weeks ago Loader.php 2 weeks ago LoaderLock.php 2 weeks ago Parameters.php 2 weeks ago PluginsArchiver.php 2 weeks ago PluginsArchiverException.php 2 years ago Record.php 2 weeks ago RecordBuilder.php 2 weeks ago Rules.php 2 weeks ago
BlobTableAggregator.php
94 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\Common;
12 use Piwik\DataTable;
13 use Piwik\DataTable\Row;
14 /**
15 * Internal helper for aggregating blob rows into a DataTable.
16 *
17 * @internal
18 */
19 final class BlobTableAggregator
20 {
21 /**
22 * @param iterable<array{name: string, date1: string, date2: string, value: string}> $archiveDataRows
23 * @param callable(DataTable):void $renameColumnsCallback
24 * @param callable(array{name: string, date1: string, date2: string, value: string}):bool|null $shouldIncludeRow
25 * @param callable(string, int):void|null $onMissingParentTable
26 * @return array{0: DataTable, 1: bool}
27 */
28 public static function aggregateBlobRows(iterable $archiveDataRows, string $recordName, ?array $columnsAggregationOperation, callable $renameColumnsCallback, ?callable $shouldIncludeRow = null, ?callable $onMissingParentTable = null) : array
29 {
30 // maps period & subtable ID in database to the Row instance in $result that subtable should be added to
31 // [$row['date1'].','.$row['date2']][$tableId] = $row in $result
32 $tableIdToResultRowMapping = [];
33 $result = new DataTable();
34 $hasRows = \false;
35 if (!empty($columnsAggregationOperation)) {
36 $result->setMetadata(DataTable::COLUMN_AGGREGATION_OPS_METADATA_NAME, $columnsAggregationOperation);
37 }
38 foreach ($archiveDataRows as $archiveDataRow) {
39 if ($shouldIncludeRow !== null && !$shouldIncludeRow($archiveDataRow)) {
40 continue;
41 }
42 $hasRows = \true;
43 $period = $archiveDataRow['date1'] . ',' . $archiveDataRow['date2'];
44 $tableId = $archiveDataRow['name'] === $recordName ? null : self::parseSubtableIdFromBlobName($archiveDataRow['name']);
45 $blobTable = DataTable::fromSerializedArray($archiveDataRow['value']);
46 $blobTable->filter(function (DataTable $table) use($renameColumnsCallback) {
47 $renameColumnsCallback($table);
48 });
49 if ($tableId === null) {
50 $tableToAddTo = $result;
51 } elseif (empty($tableIdToResultRowMapping[$period][$tableId])) {
52 if ($onMissingParentTable !== null) {
53 $onMissingParentTable($period, $tableId);
54 }
55 Common::destroy($blobTable);
56 continue;
57 } else {
58 $rowToAddTo = $tableIdToResultRowMapping[$period][$tableId];
59 if (!$rowToAddTo->getIdSubDataTable()) {
60 $newTable = new DataTable();
61 if (!empty($columnsAggregationOperation)) {
62 $newTable->setMetadata(DataTable::COLUMN_AGGREGATION_OPS_METADATA_NAME, $columnsAggregationOperation);
63 }
64 $rowToAddTo->setSubtable($newTable);
65 }
66 $tableToAddTo = $rowToAddTo->getSubtable();
67 }
68 $tableToAddTo->addDataTable($blobTable);
69 foreach ($blobTable->getRows() as $blobTableRow) {
70 $label = $blobTableRow->getColumn('label');
71 $subtableId = $blobTableRow->getIdSubDataTable();
72 if (empty($subtableId)) {
73 continue;
74 }
75 $rowToAddTo = $tableToAddTo->getRowFromLabel($label);
76 if ($rowToAddTo instanceof Row) {
77 $tableIdToResultRowMapping[$period][$subtableId] = $rowToAddTo;
78 }
79 }
80 Common::destroy($blobTable);
81 }
82 return [$result, $hasRows];
83 }
84 public static function parseSubtableIdFromBlobName(string $recordName) : ?int
85 {
86 $parts = explode('_', $recordName);
87 $id = end($parts);
88 if (!is_numeric($id)) {
89 return null;
90 }
91 return (int) $id;
92 }
93 }
94