Piwik\Plugins\DevicesDetection\API::mergeDataTables PHP Method

mergeDataTables() protected method

Unlike DevicesDetection plugin now, the UserSettings plugin did not store archives holding the os and browser data without their version number. The "version-less" reports were always generated out of the "version-containing" archives . For big archives (month/year) that ment that some of the data was truncated, due to the datatable entry limit. To avoid that data loss / inaccuracy in the future, DevicesDetection plugin will also store archives without the version. For data archived before DevicesDetection plugin was enabled, those archives do not exist, so we try to calculate them here from the "version-containing" reports if possible.
protected mergeDataTables ( Piwik\DataTable\DataTableInterface $dataTable, Piwik\DataTable\DataTableInterface $dataTable2 ) : Piwik\DataTable\DataTableInterface
$dataTable Piwik\DataTable\DataTableInterface
$dataTable2 Piwik\DataTable\DataTableInterface
return Piwik\DataTable\DataTableInterface
    protected function mergeDataTables(DataTable\DataTableInterface $dataTable, DataTable\DataTableInterface $dataTable2)
    {
        if ($dataTable instanceof DataTable\Map) {
            $dataTables = $dataTable->getDataTables();
            foreach ($dataTables as $label => $table) {
                $versionDataTables = $dataTable2->getDataTables();
                if (!array_key_exists($label, $versionDataTables)) {
                    continue;
                }
                $newDataTable = $this->mergeDataTables($table, $versionDataTables[$label]);
                $dataTable->addTable($newDataTable, $label);
            }
        } else {
            if (!$dataTable->getRowsCount() && $dataTable2->getRowsCount()) {
                $dataTable2->filter('GroupBy', array('label', function ($label) {
                    if (preg_match("/(.+) [0-9]+(?:\\.[0-9]+)?\$/", $label, $matches)) {
                        return $matches[1];
                        // should match for browsers
                    }
                    if (strpos($label, ';')) {
                        return substr($label, 0, 3);
                        // should match for os
                    }
                    return $label;
                }));
                return $dataTable2;
            }
        }
        return $dataTable;
    }