diff options
author | sgiehl <stefan@piwik.org> | 2014-12-06 20:24:01 +0300 |
---|---|---|
committer | sgiehl <stefan@piwik.org> | 2014-12-06 20:24:01 +0300 |
commit | c21d46f791c5eb7a68ebd8fc8c982786f3005cea (patch) | |
tree | c95823b500330323b11b6ed6a3294cb3e91261a5 /plugins/DevicesDetection | |
parent | 0bb5558f8a97e1bace18e87741b37837d5954d47 (diff) |
refs #6750 - only rename archives in update script. do not rebuild archives without versions where they do not exist. Instead added a fallback in the api methods to build the reports on the fly if requested
Diffstat (limited to 'plugins/DevicesDetection')
-rw-r--r-- | plugins/DevicesDetection/API.php | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/plugins/DevicesDetection/API.php b/plugins/DevicesDetection/API.php index b6c58388b9..ad7d01d6e7 100644 --- a/plugins/DevicesDetection/API.php +++ b/plugins/DevicesDetection/API.php @@ -123,11 +123,60 @@ class API extends \Piwik\Plugin\API public function getOsFamilies($idSite, $period, $date, $segment = false) { $dataTable = $this->getDataTable('DevicesDetection_os', $idSite, $period, $date, $segment); + + // handle legacy archives + $this->checkForFallbackToOsVersions($dataTable, $idSite, $period, $date, $segment); + $dataTable->filter('GroupBy', array('label', __NAMESPACE__ . '\getOSFamilyFullName')); $dataTable->filter('ColumnCallbackAddMetadata', array('label', 'logo', __NAMESPACE__ . '\getOsFamilyLogo')); return $dataTable; } + + /** + * That methods handles teh fallback to os version datatables to calculate those without versions. + * + * 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. + * + * @param DataTable\DataTableInterface $dataTable + * @param $idSite + * @param $period + * @param $date + * @param $segment + */ + protected function checkForFallbackToOsVersions(DataTable\DataTableInterface &$dataTable, $idSite, $period, $date, $segment) + { + if ($dataTable instanceof DataTable\Map) { + $dataTables = $dataTable->getDataTables(); + foreach ($dataTables as $date => &$table) { + if (!$table->getRowsCount()) { + $subTable = $this->getDataTable('DevicesDetection_osVersions', $idSite, $period, $date, $segment); + $subTable->filter('GroupBy', array('label', function ($osWithVersion) { + if (strpos($osWithVersion, ';')) { + return substr($osWithVersion, 0, 3); + } + return $osWithVersion; + })); + $dataTable->addTable($subTable, $date); + } + } + + } else if (!$dataTable->getRowsCount()) { + $dataTable = $this->getDataTable('DevicesDetection_osVersions', $idSite, $period, $date, $segment); + $dataTable->filter('GroupBy', array('label', function ($osWithVersion) { + if (strpos($osWithVersion, ';')) { + return substr($osWithVersion, 0, 3); + } + return $osWithVersion; + })); + } + } + /** * Gets datatable displaying number of visits by OS version (eg. Android 4.0, Windows 7) * @param int $idSite @@ -171,12 +220,60 @@ class API extends \Piwik\Plugin\API public function getBrowsers($idSite, $period, $date, $segment = false) { $dataTable = $this->getDataTable('DevicesDetection_browsers', $idSite, $period, $date, $segment); + + // handle legacy archives + $this->checkForFallbackToBrowserVersions($dataTable, $idSite, $period, $date, $segment); + $dataTable->filter('GroupBy', array('label', __NAMESPACE__ . '\getBrowserName')); $dataTable->filter('ColumnCallbackAddMetadata', array('label', 'logo', __NAMESPACE__ . '\getBrowserFamilyLogo')); return $dataTable; } /** + * That methods handles teh fallback to browser version datatables to calculate those without versions. + * + * 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. + * + * @param DataTable\DataTableInterface $dataTable + * @param $idSite + * @param $period + * @param $date + * @param $segment + */ + protected function checkForFallbackToBrowserVersions(DataTable\DataTableInterface &$dataTable, $idSite, $period, $date, $segment) + { + if ($dataTable instanceof DataTable\Map) { + $dataTables = $dataTable->getDataTables(); + foreach ($dataTables as $date => &$table) { + if (!$table->getRowsCount()) { + $subTable = $this->getDataTable('DevicesDetection_browserVersions', $idSite, $period, $date, $segment); + $subTable->filter('GroupBy', array('label', function ($browserWithVersion) { + if (preg_match("/(.+) [0-9]+(?:\.[0-9]+)?$/", $browserWithVersion, $matches) === 0) { + return $browserWithVersion; + } + return $matches[1]; + })); + $dataTable->addTable($subTable, $date); + } + } + + } else if (!$dataTable->getRowsCount()) { + $dataTable = $this->getDataTable('DevicesDetection_browserVersions', $idSite, $period, $date, $segment); + $dataTable->filter('GroupBy', array('label', function ($browserWithVersion) { + if (preg_match("/(.+) [0-9]+(?:\.[0-9]+)?$/", $browserWithVersion, $matches) === 0) { + return $browserWithVersion; + } + return $matches[1]; + })); + } + } + + /** * Gets datatable displaying number of visits by Browser version (eg. Firefox 20, Safari 6.0) * @param int $idSite * @param string $period |