diff options
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 |