diff options
author | diosmosis <diosmosis@users.noreply.github.com> | 2019-07-29 23:08:46 +0300 |
---|---|---|
committer | Thomas Steur <tsteur@users.noreply.github.com> | 2019-07-29 23:08:46 +0300 |
commit | 77e879bc4d86f9e8584415f575040a89f872edd6 (patch) | |
tree | bb26eac87188ef70f7c543e52287ab97495ff3df /core/DataTable.php | |
parent | 868bb88a7abf961f6f723c1a053a670f1b04913e (diff) |
Save DataTable metadata in records if added during archiving. (#14671)3.12.0-b1
* Save DataTable metadata in records if added during archiving.
* Use descriptive and rare string row label.
Diffstat (limited to 'core/DataTable.php')
-rw-r--r-- | core/DataTable.php | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/core/DataTable.php b/core/DataTable.php index 727cc5dd01..356ce86f69 100644 --- a/core/DataTable.php +++ b/core/DataTable.php @@ -200,9 +200,17 @@ class DataTable implements DataTableInterface, \IteratorAggregate, \ArrayAccess /** The ID of the Summary Row. */ const ID_SUMMARY_ROW = -1; + /** + * The ID of the special metadata row. This row only exists in the serialized row data and stores the datatable metadata. + * + * This allows us to save datatable metadata in archive data. + */ + const ID_ARCHIVED_METADATA_ROW = -3; + /** The original label of the Summary Row. */ const LABEL_SUMMARY_ROW = -1; const LABEL_TOTALS_ROW = -2; + const LABEL_ARCHIVED_METADATA_ROW = '__datatable_metadata__'; /** * Name for metadata that contains extra {@link Piwik\Plugin\ProcessedMetric}s for a DataTable. @@ -1291,6 +1299,15 @@ class DataTable implements DataTableInterface, \IteratorAggregate, \ArrayAccess $subtableId = 0; throw new Exception("Maximum recursion level of " . self::$maximumDepthLevelAllowed . " reached. Maybe you have set a DataTable\Row with an associated DataTable belonging already to one of its parent tables?"); } + + // gather metadata before filters are called, so their metadata is not stored in serialized form + $metadata = $this->getAllTableMetadata(); + foreach ($metadata as $key => $value) { + if (!is_scalar($value) && !is_string($value)) { + unset($metadata[$key]); + } + } + if (!is_null($maximumRowsInDataTable)) { $this->filter('Truncate', array($maximumRowsInDataTable - 1, @@ -1341,6 +1358,16 @@ class DataTable implements DataTableInterface, \IteratorAggregate, \ArrayAccess $rows[self::ID_SUMMARY_ROW] = $this->summaryRow->export(); } + if (!empty($metadata)) { + $metadataRow = new Row(); + $metadataRow->setColumns($metadata); + + // set the label so the row will be indexed correctly internally + $metadataRow->setColumn('label', self::LABEL_ARCHIVED_METADATA_ROW); + + $rows[self::ID_ARCHIVED_METADATA_ROW] = $metadataRow->export(); + } + $aSerializedDataTable[$forcedId] = serialize($rows); unset($rows); @@ -1402,6 +1429,13 @@ class DataTable implements DataTableInterface, \IteratorAggregate, \ArrayAccess unset($rows[self::ID_SUMMARY_ROW]); } + if (array_key_exists(self::ID_ARCHIVED_METADATA_ROW, $rows)) { + $metadata = $rows[self::ID_ARCHIVED_METADATA_ROW][Row::COLUMNS]; + unset($metadata['label']); + $this->setAllTableMetadata($metadata); + unset($rows[self::ID_ARCHIVED_METADATA_ROW]); + } + foreach ($rows as $id => $row) { if (isset($row->c)) { $this->addRow(new Row($row->c)); // Pre Piwik 2.13 |