Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormattab <matthieu.aubry@gmail.com>2013-03-28 03:42:39 +0400
committermattab <matthieu.aubry@gmail.com>2013-03-28 03:42:40 +0400
commitae4b03163792f0b6e933933e5d37df87dc3fd566 (patch)
treed1d7510a9728f587d3d63ebd03e4ecf3d904838b /plugins/DBStats
parent158c2150f5f2e13ece459b8d131244c11b763997 (diff)
Mass conversion of all files to the newly agreed coding standard: PSR 1/2
Converting Piwik core source files, PHP, JS, TPL, CSS More info: http://piwik.org/participate/coding-standards/
Diffstat (limited to 'plugins/DBStats')
-rw-r--r--plugins/DBStats/API.php584
-rw-r--r--plugins/DBStats/Controller.php717
-rw-r--r--plugins/DBStats/DBStats.php128
-rwxr-xr-xplugins/DBStats/MySQLMetadataProvider.php706
-rwxr-xr-xplugins/DBStats/templates/index.tpl231
5 files changed, 1163 insertions, 1203 deletions
diff --git a/plugins/DBStats/API.php b/plugins/DBStats/API.php
index b72d0a2e49..fec0e0fe71 100644
--- a/plugins/DBStats/API.php
+++ b/plugins/DBStats/API.php
@@ -1,10 +1,10 @@
<?php
/**
* Piwik - Open source web analytics
- *
+ *
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
- *
+ *
* @category Piwik_Plugins
* @package Piwik_DBStats
*/
@@ -16,304 +16,292 @@ require_once PIWIK_INCLUDE_PATH . '/plugins/DBStats/MySQLMetadataProvider.php';
/**
* DBStats API is used to request the overall status of the Mysql tables in use by Piwik.
- *
+ *
* @package Piwik_DBStats
*/
class Piwik_DBStats_API
{
- /** Singleton instance of this class. */
- static private $instance = null;
-
- /**
- * Gets or creates the DBStats API singleton.
- */
- static public function getInstance()
- {
- if (self::$instance == null)
- {
- self::$instance = new self;
- }
- return self::$instance;
- }
-
- /**
- * The MySQLMetadataProvider instance that fetches table/db status information.
- */
- private $metadataProvider;
-
- /**
- * Constructor.
- */
- public function __construct()
- {
- $this->metadataProvider = new Piwik_DBStats_MySQLMetadataProvider();
- }
-
- /**
- * Forces the next table status request to issue a query by reseting the table status cache.
- */
- public function resetTableStatuses()
- {
- Piwik::checkUserIsSuperUser();
- self::getInstance()->metadataProvider = new Piwik_DBStats_MySQLMetadataProvider();
- }
-
- /**
- * Gets some general information about this Piwik installation, including the count of
- * websites tracked, the count of users and the total space used by the database.
- *
- * @return array Contains the website count, user count and total space used by the database.
- */
- public function getGeneralInformation()
- {
- Piwik::checkUserIsSuperUser();
- // calculate total size
- $totalSpaceUsed = 0;
- foreach ($this->metadataProvider->getAllTablesStatus() as $status)
- {
- $totalSpaceUsed += $status['Data_length'] + $status['Index_length'];
- }
-
- $siteTableStatus = $this->metadataProvider->getTableStatus('site');
- $userTableStatus = $this->metadataProvider->getTableStatus('user');
-
- $siteCount = $siteTableStatus['Rows'];
- $userCount = $userTableStatus['Rows'];
-
- return array($siteCount, $userCount, $totalSpaceUsed);
- }
-
- /**
- * Gets general database info that is not specific to any table.
- *
- * @return array See http://dev.mysql.com/doc/refman/5.1/en/show-status.html .
- */
- public function getDBStatus()
- {
- Piwik::checkUserIsSuperUser();
- return $this->metadataProvider->getDBStatus();
- }
-
- /**
- * Returns a datatable summarizing how data is distributed among Piwik tables.
- *
- * This function will group tracker tables, numeric archive tables, blob archive tables
- * and other tables together so only four rows are shown.
- *
- * @return Piwik_DataTable A datatable with three columns: 'data_size', 'index_size', 'row_count'.
- */
- public function getDatabaseUsageSummary()
- {
- Piwik::checkUserIsSuperUser();
-
- $emptyRow = array('data_size' => 0, 'index_size' => 0, 'row_count' => 0);
- $rows = array(
- 'tracker_data' => $emptyRow,
- 'metric_data' => $emptyRow,
- 'report_data' => $emptyRow,
- 'other_data' => $emptyRow
- );
-
- foreach ($this->metadataProvider->getAllTablesStatus() as $status)
- {
- if ($this->isNumericArchiveTable($status['Name']))
- {
- $rowToAddTo = &$rows['metric_data'];
- }
- else if ($this->isBlobArchiveTable($status['Name']))
- {
- $rowToAddTo = &$rows['report_data'];
- }
- else if ($this->isTrackerTable($status['Name']))
- {
- $rowToAddTo = &$rows['tracker_data'];
- }
- else
- {
- $rowToAddTo = &$rows['other_data'];
- }
-
- $rowToAddTo['data_size'] += $status['Data_length'];
- $rowToAddTo['index_size'] += $status['Index_length'];
- $rowToAddTo['row_count'] += $status['Rows'];
- }
-
- $result = new Piwik_DataTable();
- $result->addRowsFromArrayWithIndexLabel($rows);
- return $result;
- }
-
- /**
- * Returns a datatable describing how much space is taken up by each log table.
- *
- * @return Piwik_DataTable A datatable with three columns: 'data_size', 'index_size', 'row_count'.
- */
- public function getTrackerDataSummary()
- {
- Piwik::checkUserIsSuperUser();
- return $this->getTablesSummary($this->metadataProvider->getAllLogTableStatus());
- }
-
- /**
- * Returns a datatable describing how much space is taken up by each numeric
- * archive table.
- *
- * @return Piwik_DataTable A datatable with three columns: 'data_size', 'index_size', 'row_count'.
- */
- public function getMetricDataSummary()
- {
- Piwik::checkUserIsSuperUser();
- return $this->getTablesSummary($this->metadataProvider->getAllNumericArchiveStatus());
- }
-
- /**
- * Returns a datatable describing how much space is taken up by each numeric
- * archive table, grouped by year.
- *
- * @return Piwik_DataTable A datatable with three columns: 'data_size', 'index_size', 'row_count'.
- */
- public function getMetricDataSummaryByYear()
- {
- Piwik::checkUserIsSuperUser();
-
- $dataTable = $this->getMetricDataSummary();
-
- $getTableYear = array('Piwik_DBStats_API', 'getArchiveTableYear');
- $dataTable->filter('GroupBy', array('label', $getTableYear));
-
- return $dataTable;
- }
-
- /**
- * Returns a datatable describing how much space is taken up by each blob
- * archive table.
- *
- * @return Piwik_DataTable A datatable with three columns: 'data_size', 'index_size', 'row_count'.
- */
- public function getReportDataSummary()
- {
- Piwik::checkUserIsSuperUser();
- return $this->getTablesSummary($this->metadataProvider->getAllBlobArchiveStatus());
- }
-
- /**
- * Returns a datatable describing how much space is taken up by each blob
- * archive table, grouped by year.
- *
- * @return Piwik_DataTable A datatable with three columns: 'data_size', 'index_size', 'row_count'.
- */
- public function getReportDataSummaryByYear()
- {
- Piwik::checkUserIsSuperUser();
-
- $dataTable = $this->getReportDataSummary();
-
- $getTableYear = array('Piwik_DBStats_API', 'getArchiveTableYear');
- $dataTable->filter('GroupBy', array('label', $getTableYear));
-
- return $dataTable;
- }
-
- /**
- * Returns a datatable describing how much space is taken up by 'admin' tables.
- *
- * An 'admin' table is a table that is not central to analytics functionality.
- * So any table that isn't an archive table or a log table is an 'admin' table.
- *
- * @return Piwik_DataTable A datatable with three columns: 'data_size', 'index_size', 'row_count'.
- */
- public function getAdminDataSummary()
- {
- Piwik::checkUserIsSuperUser();
- return $this->getTablesSummary($this->metadataProvider->getAllAdminTableStatus());
- }
-
- /**
- * Returns a datatable describing how much total space is taken up by each
- * individual report type.
- *
- * Goal reports and reports of the format .*_[0-9]+ are grouped together.
- *
- * @param bool $forceCache false to use the cached result, true to run the queries again and
- * cache the result.
- * @return Piwik_DataTable A datatable with three columns: 'data_size', 'index_size', 'row_count'.
- */
- public function getIndividualReportsSummary( $forceCache = false )
- {
- Piwik::checkUserIsSuperUser();
- return $this->metadataProvider->getRowCountsAndSizeByBlobName($forceCache);
- }
-
- /**
- * Returns a datatable describing how much total space is taken up by each
- * individual metric type.
- *
- * Goal metrics, metrics of the format .*_[0-9]+ and 'done...' metrics are grouped together.
- *
- * @param bool $forceCache false to use the cached result, true to run the queries again and
- * cache the result.
- * @return Piwik_DataTable A datatable with three columns: 'data_size', 'index_size', 'row_count'.
- */
- public function getIndividualMetricsSummary( $forceCache = false )
- {
- Piwik::checkUserIsSuperUser();
- return $this->metadataProvider->getRowCountsAndSizeByMetricName($forceCache);
- }
-
- /**
- * Returns a datatable representation of a set of table statuses.
- *
- * @param array $statuses The table statuses to summarize.
- * @return Piwik_DataTable
- */
- private function getTablesSummary( $statuses )
- {
- $dataTable = new Piwik_DataTable();
- foreach ($statuses as $status)
- {
- $dataTable->addRowFromSimpleArray(array(
- 'label' => $status['Name'],
- 'data_size' => $status['Data_length'],
- 'index_size' => $status['Index_length'],
- 'row_count' => $status['Rows']
- ));
- }
- return $dataTable;
- }
-
- /** Returns true if $name is the name of a numeric archive table, false if otherwise. */
- private function isNumericArchiveTable( $name )
- {
- return strpos($name, Piwik_Common::prefixTable('archive_numeric_')) === 0;
- }
-
- /** Returns true if $name is the name of a blob archive table, false if otherwise. */
- private function isBlobArchiveTable( $name )
- {
- return strpos($name, Piwik_Common::prefixTable('archive_blob_')) === 0;
- }
-
- /** Returns true if $name is the name of a log table, false if otherwise. */
- private function isTrackerTable( $name )
- {
- return strpos($name, Piwik_Common::prefixTable('log_')) === 0;
- }
-
- /**
- * Gets the year of an archive table from its name.
- *
- * @param string $tableName
- * @param string The year.
- *
- * @ignore
- */
- public static function getArchiveTableYear( $tableName )
- {
- if (preg_match("/archive_(?:numeric|blob)_([0-9]+)_/", $tableName, $matches) === 0)
- {
- return '';
- }
-
- return $matches[1];
- }
+ /** Singleton instance of this class. */
+ static private $instance = null;
+
+ /**
+ * Gets or creates the DBStats API singleton.
+ */
+ static public function getInstance()
+ {
+ if (self::$instance == null) {
+ self::$instance = new self;
+ }
+ return self::$instance;
+ }
+
+ /**
+ * The MySQLMetadataProvider instance that fetches table/db status information.
+ */
+ private $metadataProvider;
+
+ /**
+ * Constructor.
+ */
+ public function __construct()
+ {
+ $this->metadataProvider = new Piwik_DBStats_MySQLMetadataProvider();
+ }
+
+ /**
+ * Forces the next table status request to issue a query by reseting the table status cache.
+ */
+ public function resetTableStatuses()
+ {
+ Piwik::checkUserIsSuperUser();
+ self::getInstance()->metadataProvider = new Piwik_DBStats_MySQLMetadataProvider();
+ }
+
+ /**
+ * Gets some general information about this Piwik installation, including the count of
+ * websites tracked, the count of users and the total space used by the database.
+ *
+ * @return array Contains the website count, user count and total space used by the database.
+ */
+ public function getGeneralInformation()
+ {
+ Piwik::checkUserIsSuperUser();
+ // calculate total size
+ $totalSpaceUsed = 0;
+ foreach ($this->metadataProvider->getAllTablesStatus() as $status) {
+ $totalSpaceUsed += $status['Data_length'] + $status['Index_length'];
+ }
+
+ $siteTableStatus = $this->metadataProvider->getTableStatus('site');
+ $userTableStatus = $this->metadataProvider->getTableStatus('user');
+
+ $siteCount = $siteTableStatus['Rows'];
+ $userCount = $userTableStatus['Rows'];
+
+ return array($siteCount, $userCount, $totalSpaceUsed);
+ }
+
+ /**
+ * Gets general database info that is not specific to any table.
+ *
+ * @return array See http://dev.mysql.com/doc/refman/5.1/en/show-status.html .
+ */
+ public function getDBStatus()
+ {
+ Piwik::checkUserIsSuperUser();
+ return $this->metadataProvider->getDBStatus();
+ }
+
+ /**
+ * Returns a datatable summarizing how data is distributed among Piwik tables.
+ *
+ * This function will group tracker tables, numeric archive tables, blob archive tables
+ * and other tables together so only four rows are shown.
+ *
+ * @return Piwik_DataTable A datatable with three columns: 'data_size', 'index_size', 'row_count'.
+ */
+ public function getDatabaseUsageSummary()
+ {
+ Piwik::checkUserIsSuperUser();
+
+ $emptyRow = array('data_size' => 0, 'index_size' => 0, 'row_count' => 0);
+ $rows = array(
+ 'tracker_data' => $emptyRow,
+ 'metric_data' => $emptyRow,
+ 'report_data' => $emptyRow,
+ 'other_data' => $emptyRow
+ );
+
+ foreach ($this->metadataProvider->getAllTablesStatus() as $status) {
+ if ($this->isNumericArchiveTable($status['Name'])) {
+ $rowToAddTo = & $rows['metric_data'];
+ } else if ($this->isBlobArchiveTable($status['Name'])) {
+ $rowToAddTo = & $rows['report_data'];
+ } else if ($this->isTrackerTable($status['Name'])) {
+ $rowToAddTo = & $rows['tracker_data'];
+ } else {
+ $rowToAddTo = & $rows['other_data'];
+ }
+
+ $rowToAddTo['data_size'] += $status['Data_length'];
+ $rowToAddTo['index_size'] += $status['Index_length'];
+ $rowToAddTo['row_count'] += $status['Rows'];
+ }
+
+ $result = new Piwik_DataTable();
+ $result->addRowsFromArrayWithIndexLabel($rows);
+ return $result;
+ }
+
+ /**
+ * Returns a datatable describing how much space is taken up by each log table.
+ *
+ * @return Piwik_DataTable A datatable with three columns: 'data_size', 'index_size', 'row_count'.
+ */
+ public function getTrackerDataSummary()
+ {
+ Piwik::checkUserIsSuperUser();
+ return $this->getTablesSummary($this->metadataProvider->getAllLogTableStatus());
+ }
+
+ /**
+ * Returns a datatable describing how much space is taken up by each numeric
+ * archive table.
+ *
+ * @return Piwik_DataTable A datatable with three columns: 'data_size', 'index_size', 'row_count'.
+ */
+ public function getMetricDataSummary()
+ {
+ Piwik::checkUserIsSuperUser();
+ return $this->getTablesSummary($this->metadataProvider->getAllNumericArchiveStatus());
+ }
+
+ /**
+ * Returns a datatable describing how much space is taken up by each numeric
+ * archive table, grouped by year.
+ *
+ * @return Piwik_DataTable A datatable with three columns: 'data_size', 'index_size', 'row_count'.
+ */
+ public function getMetricDataSummaryByYear()
+ {
+ Piwik::checkUserIsSuperUser();
+
+ $dataTable = $this->getMetricDataSummary();
+
+ $getTableYear = array('Piwik_DBStats_API', 'getArchiveTableYear');
+ $dataTable->filter('GroupBy', array('label', $getTableYear));
+
+ return $dataTable;
+ }
+
+ /**
+ * Returns a datatable describing how much space is taken up by each blob
+ * archive table.
+ *
+ * @return Piwik_DataTable A datatable with three columns: 'data_size', 'index_size', 'row_count'.
+ */
+ public function getReportDataSummary()
+ {
+ Piwik::checkUserIsSuperUser();
+ return $this->getTablesSummary($this->metadataProvider->getAllBlobArchiveStatus());
+ }
+
+ /**
+ * Returns a datatable describing how much space is taken up by each blob
+ * archive table, grouped by year.
+ *
+ * @return Piwik_DataTable A datatable with three columns: 'data_size', 'index_size', 'row_count'.
+ */
+ public function getReportDataSummaryByYear()
+ {
+ Piwik::checkUserIsSuperUser();
+
+ $dataTable = $this->getReportDataSummary();
+
+ $getTableYear = array('Piwik_DBStats_API', 'getArchiveTableYear');
+ $dataTable->filter('GroupBy', array('label', $getTableYear));
+
+ return $dataTable;
+ }
+
+ /**
+ * Returns a datatable describing how much space is taken up by 'admin' tables.
+ *
+ * An 'admin' table is a table that is not central to analytics functionality.
+ * So any table that isn't an archive table or a log table is an 'admin' table.
+ *
+ * @return Piwik_DataTable A datatable with three columns: 'data_size', 'index_size', 'row_count'.
+ */
+ public function getAdminDataSummary()
+ {
+ Piwik::checkUserIsSuperUser();
+ return $this->getTablesSummary($this->metadataProvider->getAllAdminTableStatus());
+ }
+
+ /**
+ * Returns a datatable describing how much total space is taken up by each
+ * individual report type.
+ *
+ * Goal reports and reports of the format .*_[0-9]+ are grouped together.
+ *
+ * @param bool $forceCache false to use the cached result, true to run the queries again and
+ * cache the result.
+ * @return Piwik_DataTable A datatable with three columns: 'data_size', 'index_size', 'row_count'.
+ */
+ public function getIndividualReportsSummary($forceCache = false)
+ {
+ Piwik::checkUserIsSuperUser();
+ return $this->metadataProvider->getRowCountsAndSizeByBlobName($forceCache);
+ }
+
+ /**
+ * Returns a datatable describing how much total space is taken up by each
+ * individual metric type.
+ *
+ * Goal metrics, metrics of the format .*_[0-9]+ and 'done...' metrics are grouped together.
+ *
+ * @param bool $forceCache false to use the cached result, true to run the queries again and
+ * cache the result.
+ * @return Piwik_DataTable A datatable with three columns: 'data_size', 'index_size', 'row_count'.
+ */
+ public function getIndividualMetricsSummary($forceCache = false)
+ {
+ Piwik::checkUserIsSuperUser();
+ return $this->metadataProvider->getRowCountsAndSizeByMetricName($forceCache);
+ }
+
+ /**
+ * Returns a datatable representation of a set of table statuses.
+ *
+ * @param array $statuses The table statuses to summarize.
+ * @return Piwik_DataTable
+ */
+ private function getTablesSummary($statuses)
+ {
+ $dataTable = new Piwik_DataTable();
+ foreach ($statuses as $status) {
+ $dataTable->addRowFromSimpleArray(array(
+ 'label' => $status['Name'],
+ 'data_size' => $status['Data_length'],
+ 'index_size' => $status['Index_length'],
+ 'row_count' => $status['Rows']
+ ));
+ }
+ return $dataTable;
+ }
+
+ /** Returns true if $name is the name of a numeric archive table, false if otherwise. */
+ private function isNumericArchiveTable($name)
+ {
+ return strpos($name, Piwik_Common::prefixTable('archive_numeric_')) === 0;
+ }
+
+ /** Returns true if $name is the name of a blob archive table, false if otherwise. */
+ private function isBlobArchiveTable($name)
+ {
+ return strpos($name, Piwik_Common::prefixTable('archive_blob_')) === 0;
+ }
+
+ /** Returns true if $name is the name of a log table, false if otherwise. */
+ private function isTrackerTable($name)
+ {
+ return strpos($name, Piwik_Common::prefixTable('log_')) === 0;
+ }
+
+ /**
+ * Gets the year of an archive table from its name.
+ *
+ * @param string $tableName
+ * @param string The year.
+ *
+ * @ignore
+ */
+ public static function getArchiveTableYear($tableName)
+ {
+ if (preg_match("/archive_(?:numeric|blob)_([0-9]+)_/", $tableName, $matches) === 0) {
+ return '';
+ }
+
+ return $matches[1];
+ }
}
diff --git a/plugins/DBStats/Controller.php b/plugins/DBStats/Controller.php
index 06bae7232b..ab0de6a292 100644
--- a/plugins/DBStats/Controller.php
+++ b/plugins/DBStats/Controller.php
@@ -1,10 +1,10 @@
<?php
/**
* Piwik - Open source web analytics
- *
+ *
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
- *
+ *
* @category Piwik_Plugins
* @package Piwik_DBStats
*/
@@ -15,366 +15,355 @@
*/
class Piwik_DBStats_Controller extends Piwik_Controller_Admin
{
- /**
- * Returns the index for this plugin. Shows every other report defined by this plugin,
- * except the '...ByYear' reports. These can be loaded as related reports.
- *
- * Also, the 'getIndividual...Summary' reports are loaded by AJAX, as they can take
- * a significant amount of time to load on setups w/ lots of websites.
- */
- public function index()
- {
- Piwik::checkUserIsSuperUser();
- $view = Piwik_View::factory('index');
- $this->setBasicVariablesView($view);
- $view->menu = Piwik_GetAdminMenu();
-
- $view->databaseUsageSummary = $this->getDatabaseUsageSummary(true);
- $view->trackerDataSummary = $this->getTrackerDataSummary(true);
- $view->metricDataSummary = $this->getMetricDataSummary(true);
- $view->reportDataSummary = $this->getReportDataSummary(true);
- $view->adminDataSummary = $this->getAdminDataSummary(true);
-
- list($siteCount, $userCount, $totalSpaceUsed) = Piwik_DBStats_API::getInstance()->getGeneralInformation();
- $view->siteCount = Piwik::getPrettyNumber($siteCount);
- $view->userCount = Piwik::getPrettyNumber($userCount);
- $view->totalSpaceUsed = Piwik::getPrettySizeFromBytes($totalSpaceUsed);
-
- echo $view->render();
- }
-
- /**
- * Shows a datatable that displays how much space the tracker tables, numeric
- * archive tables, report tables and other tables take up in the MySQL database.
- *
- * @param bool $fetch If true, the rendered HTML datatable is returned, otherwise,
- * it is echoed.
- */
- public function getDatabaseUsageSummary( $fetch = false )
- {
- Piwik::checkUserIsSuperUser();
-
- $view = $this->getDataTableView(__FUNCTION__, $viewType = 'graphPie', $orderDir = 'desc',
- $addPercentColumn = true);
- $view->disableOffsetInformationAndPaginationControls();
-
- if ($view instanceof Piwik_ViewDataTable_GenerateGraphHTML)
- {
- $view->showAllTicks();
- }
-
- // translate the labels themselves
- $translateSummaryLabel = array($this, 'translateSummarylabel');
- $view->queueFilter('ColumnCallbackReplace', array(array('label'), $translateSummaryLabel),
- $runBeforeGenericFilters = true);
-
- return $this->renderView($view, $fetch);
- }
-
- /**
- * Shows a datatable that displays the amount of space each individual log table
- * takes up in the MySQL database.
- *
- * @param bool $fetch If true, the rendered HTML datatable is returned, otherwise,
- * it is echoed.
- */
- public function getTrackerDataSummary( $fetch = false )
- {
- Piwik::checkUserIsSuperUser();
-
- $view = $this->getDataTableView(__FUNCTION__);
- $view->disableOffsetInformationAndPaginationControls();
- return $this->renderView($view, $fetch);
- }
-
- /**
- * Shows a datatable that displays the amount of space each numeric archive table
- * takes up in the MySQL database.
- *
- * @param bool $fetch If true, the rendered HTML datatable is returned, otherwise,
- * it is echoed.
- */
- public function getMetricDataSummary( $fetch = false )
- {
- Piwik::checkUserIsSuperUser();
- $view = $this->getDataTableView(__FUNCTION__, $viewType = 'table', $orderDir = 'desc');
- $view->addRelatedReports(Piwik_Translate('DBStats_MetricTables'), array(
- 'DBStats.getMetricDataSummaryByYear' => Piwik_Translate('DBStats_MetricDataByYear')
- ));
- return $this->renderView($view, $fetch);
- }
-
- /**
- * Shows a datatable that displays the amount of space each numeric archive table
- * takes up in the MySQL database, for each year of numeric data.
- *
- * @param bool $fetch If true, the rendered HTML datatable is returned, otherwise,
- * it is echoed.
- */
- public function getMetricDataSummaryByYear( $fetch = false )
- {
- Piwik::checkUserIsSuperUser();
- $view = $this->getDataTableView(__FUNCTION__, $viewType = 'table', $orderDir = 'desc',
- $addPercentColumn = false, $labelKey = 'CoreHome_PeriodYear');
- $view->addRelatedReports(Piwik_Translate('DBStats_MetricDataByYear'), array(
- 'DBStats.getMetricDataSummary' => Piwik_Translate('DBStats_MetricTables')
- ));
- return $this->renderView($view, $fetch);
- }
-
- /**
- * Shows a datatable that displays the amount of space each blob archive table
- * takes up in the MySQL database.
- *
- * @param bool $fetch If true, the rendered HTML datatable is returned, otherwise,
- * it is echoed.
- */
- public function getReportDataSummary( $fetch = false )
- {
- Piwik::checkUserIsSuperUser();
- $view = $this->getDataTableView(__FUNCTION__, $viewType = 'table', $orderDir = 'desc');
- $view->addRelatedReports(Piwik_Translate('DBStats_ReportTables'), array(
- 'DBStats.getReportDataSummaryByYear' => Piwik_Translate('DBStats_ReportDataByYear')
- ));
- return $this->renderView($view, $fetch);
- }
-
- /**
- * Shows a datatable that displays the amount of space each blob archive table
- * takes up in the MySQL database, for each year of blob data.
- *
- * @param bool $fetch If true, the rendered HTML datatable is returned, otherwise,
- * it is echoed.
- */
- public function getReportDataSummaryByYear( $fetch = false )
- {
- Piwik::checkUserIsSuperUser();
- $view = $this->getDataTableView(__FUNCTION__, $viewType = 'table', $orderDir = 'desc',
- $addPercentColumn = false, $labelKey = 'CoreHome_PeriodYear');
- $view->addRelatedReports(Piwik_Translate('DBStats_ReportDataByYear'), array(
- 'DBStats.getReportDataSummary' => Piwik_Translate('DBStats_ReportTables')
- ));
- return $this->renderView($view, $fetch);
- }
-
- /**
- * Shows a datatable that displays how many occurances there are of each individual
- * report type stored in the MySQL database.
- *
- * Goal reports and reports of the format: .*_[0-9]+ are grouped together.
- *
- * @param bool $fetch If true, the rendered HTML datatable is returned, otherwise,
- * it is echoed.
- */
- public function getIndividualReportsSummary( $fetch = false )
- {
- Piwik::checkUserIsSuperUser();
- $view = $this->getDataTableView(__FUNCTION__, $viewType = 'table', $orderDir = 'asc',
- $addPercentColumn = false, $labelKey = 'General_Report',
- $sizeColumns = array('estimated_size'));
-
- // this report table has some extra columns that shouldn't be shown
- if ($view instanceof Piwik_ViewDataTable_HtmlTable)
- {
- $view->setColumnsToDisplay(array('label', 'row_count', 'estimated_size'));
- }
-
- $this->setIndividualSummaryFooterMessage($view);
-
- return $this->renderView($view, $fetch);
- }
-
- /**
- * Shows a datatable that displays how many occurances there are of each individual
- * metric type stored in the MySQL database.
- *
- * Goal metrics, metrics of the format .*_[0-9]+ and 'done...' metrics are grouped together.
- *
- * @param bool $fetch If true, the rendered HTML datatable is returned, otherwise,
- * it is echoed.
- */
- public function getIndividualMetricsSummary( $fetch = false )
- {
- Piwik::checkUserIsSuperUser();
- $view = $this->getDataTableView(__FUNCTION__, $viewType = 'table', $orderDir = 'asc',
- $addPercentColumn = false, $labelKey = 'General_Metric',
- $sizeColumns = array('estimated_size'));
-
- $this->setIndividualSummaryFooterMessage($view);
-
- return $this->renderView($view, $fetch);
- }
-
- /**
- * Shows a datatable that displays the amount of space each 'admin' table takes
- * up in the MySQL database.
- *
- * An 'admin' table is a table that is not central to analytics functionality.
- * So any table that isn't an archive table or a log table is an 'admin' table.
- *
- * @param bool $fetch If true, the rendered HTML datatable is returned, otherwise,
- * it is echoed.
- */
- public function getAdminDataSummary( $fetch = false )
- {
- Piwik::checkUserIsSuperUser();
- $view = $this->getDataTableView(__FUNCTION__, $viewType = 'table');
- $view->disableOffsetInformationAndPaginationControls();
- return $this->renderView($view, $fetch);
- }
-
- /**
- * Utility function that creates and prepares a ViewDataTable for this plugin.
- */
- private function getDataTableView( $function, $viewType = 'table', $orderDir = 'asc', $addPercentColumn = false,
- $labelKey = 'DBStats_Table', $sizeColumns = array('data_size', 'index_size'),
- $limit = 25 )
- {
- $columnTranslations = array(
- 'label' => Piwik_Translate($labelKey),
- 'year' => Piwik_Translate('CoreHome_PeriodYear'),
- 'data_size' => Piwik_Translate('DBStats_DataSize'),
- 'index_size' => Piwik_Translate('DBStats_IndexSize'),
- 'total_size' => Piwik_Translate('DBStats_TotalSize'),
- 'row_count' => Piwik_Translate('DBStats_RowCount'),
- 'percent_total' => '%&nbsp;'.Piwik_Translate('DBStats_DBSize'),
- 'estimated_size' => Piwik_Translate('DBStats_EstimatedSize')
- );
-
- $view = Piwik_ViewDataTable::factory($viewType);
- $view->init($this->pluginName, $function, "DBStats.$function");
- $view->setSortedColumn('label', $orderDir);
- $view->setLimit($limit);
- $view->setHighlightSummaryRow(true);
- $view->disableSearchBox();
- $view->disableExcludeLowPopulation();
- $view->disableTagCloud();
- $view->disableShowAllColumns();
- $view->alwaysShowSummaryRow();
-
- // translate columns
- foreach ($columnTranslations as $columnName => $translation)
- {
- $view->setColumnTranslation($columnName, $translation);
- }
-
- // add total_size column (if necessary columns are present)
- if (in_array('data_size', $sizeColumns) && in_array('index_size', $sizeColumns))
- {
- $getTotalTableSize = array($this, 'getTotalTableSize');
- $view->queueFilter('ColumnCallbackAddColumn',
- array(array('data_size', 'index_size'), 'total_size', $getTotalTableSize),
- $runBeforeGenericFilters = true);
-
- $sizeColumns[] = 'total_size';
- }
-
- $runPrettySizeFilterBeforeGeneric = false;
- $fixedMemoryUnit = false;
- if ($view instanceof Piwik_ViewDataTable_HtmlTable) // if displaying a table
- {
- $view->disableRowEvolution();
-
- // add summary row only if displaying a table
- $view->queueFilter('AddSummaryRow', array(0, Piwik_Translate('General_Total'), 'label', false),
- $runBeforeGenericFilters = true);
-
- // add other filters
- if ($addPercentColumn && in_array('total_size', $sizeColumns))
- {
- $view->queueFilter('ColumnCallbackAddColumnPercentage',
- array('percent_total', 'total_size', 'total_size', $quotientPrecision = 0, $shouldSkipRows = false,
- $getDivisorFromSummaryRow = true),
- $runBeforeGenericFilters = true);
- $view->setSortedColumn('percent_total', $orderDir);
- }
- }
- else if ($view instanceof Piwik_ViewDataTable_GenerateGraphData) // if displaying a graph
- {
- if (in_array('total_size', $sizeColumns))
- {
- $view->setColumnsToDisplay(array('label', 'total_size'));
-
- // when displaying a graph, we force sizes to be shown as the same unit so axis labels
- // will be readable. NOTE: The unit should depend on the smallest value of the data table,
- // however there's no way to know this information, short of creating a custom filter. For
- // now, just assume KB.
- $fixedMemoryUnit = 'K';
- $view->setAxisYUnit(' K');
-
- $view->setSortedColumn('total_size', 'desc');
-
- $runPrettySizeFilterBeforeGeneric = true;
- }
- else
- {
- $view->setColumnsToDisplay(array('label', 'row_count'));
- $view->setAxisYUnit(' '.Piwik_Translate('General_Rows'));
-
- $view->setSortedColumn('row_count', 'desc');
- }
- }
-
- $getPrettySize = array('Piwik', 'getPrettySizeFromBytes');
- $params = $fixedMemoryUnit === false ? array() : array($fixedMemoryUnit);
- $view->queueFilter(
- 'ColumnCallbackReplace', array($sizeColumns, $getPrettySize, $params), $runPrettySizeFilterBeforeGeneric);
-
- // jqPlot will display &nbsp; as, well, '&nbsp;', so don't replace the spaces when rendering as a graph
- if (!($view instanceof Piwik_ViewDataTable_GenerateGraphData))
- {
- $replaceSpaces = array($this, 'replaceColumnSpaces');
- $view->queueFilter('ColumnCallbackReplace', array($sizeColumns, $replaceSpaces));
- }
-
- $getPrettyNumber = array('Piwik', 'getPrettyNumber');
- $view->queueFilter('ColumnCallbackReplace', array(array('row_count'), $getPrettyNumber));
-
- return $view;
- }
-
- /**
- * Replaces spaces w/ &nbsp; for correct HTML output.
- */
- public function replaceColumnSpaces( $value )
- {
- return str_replace(' ', '&nbsp;', $value);
- }
-
- /**
- * Row callback function that calculates a tables total size.
- */
- public function getTotalTableSize( $dataSize, $indexSize )
- {
- return $dataSize + $indexSize;
- }
-
- /**
- * Column callback used to translate the column values in the database usage summary table.
- */
- public function translateSummarylabel( $value )
- {
- static $valueToTranslationStr = array(
- 'tracker_data' => 'DBStats_TrackerTables',
- 'report_data' => 'DBStats_ReportTables',
- 'metric_data' => 'DBStats_MetricTables',
- 'other_data' => 'DBStats_OtherTables'
- );
-
- return isset($valueToTranslationStr[$value])
- ? Piwik_Translate($valueToTranslationStr[$value])
- : $value;
- }
-
- /**
- * Sets the footer message for the Individual...Summary reports.
- */
- private function setIndividualSummaryFooterMessage( $view )
- {
- $lastGenerated = Piwik_DBStats::getDateOfLastCachingRun();
- if ($lastGenerated !== false)
- {
- $view->setFooterMessage(Piwik_Translate('Mobile_LastUpdated', $lastGenerated));
- }
- }
+ /**
+ * Returns the index for this plugin. Shows every other report defined by this plugin,
+ * except the '...ByYear' reports. These can be loaded as related reports.
+ *
+ * Also, the 'getIndividual...Summary' reports are loaded by AJAX, as they can take
+ * a significant amount of time to load on setups w/ lots of websites.
+ */
+ public function index()
+ {
+ Piwik::checkUserIsSuperUser();
+ $view = Piwik_View::factory('index');
+ $this->setBasicVariablesView($view);
+ $view->menu = Piwik_GetAdminMenu();
+
+ $view->databaseUsageSummary = $this->getDatabaseUsageSummary(true);
+ $view->trackerDataSummary = $this->getTrackerDataSummary(true);
+ $view->metricDataSummary = $this->getMetricDataSummary(true);
+ $view->reportDataSummary = $this->getReportDataSummary(true);
+ $view->adminDataSummary = $this->getAdminDataSummary(true);
+
+ list($siteCount, $userCount, $totalSpaceUsed) = Piwik_DBStats_API::getInstance()->getGeneralInformation();
+ $view->siteCount = Piwik::getPrettyNumber($siteCount);
+ $view->userCount = Piwik::getPrettyNumber($userCount);
+ $view->totalSpaceUsed = Piwik::getPrettySizeFromBytes($totalSpaceUsed);
+
+ echo $view->render();
+ }
+
+ /**
+ * Shows a datatable that displays how much space the tracker tables, numeric
+ * archive tables, report tables and other tables take up in the MySQL database.
+ *
+ * @param bool $fetch If true, the rendered HTML datatable is returned, otherwise,
+ * it is echoed.
+ */
+ public function getDatabaseUsageSummary($fetch = false)
+ {
+ Piwik::checkUserIsSuperUser();
+
+ $view = $this->getDataTableView(__FUNCTION__, $viewType = 'graphPie', $orderDir = 'desc',
+ $addPercentColumn = true);
+ $view->disableOffsetInformationAndPaginationControls();
+
+ if ($view instanceof Piwik_ViewDataTable_GenerateGraphHTML) {
+ $view->showAllTicks();
+ }
+
+ // translate the labels themselves
+ $translateSummaryLabel = array($this, 'translateSummarylabel');
+ $view->queueFilter('ColumnCallbackReplace', array(array('label'), $translateSummaryLabel),
+ $runBeforeGenericFilters = true);
+
+ return $this->renderView($view, $fetch);
+ }
+
+ /**
+ * Shows a datatable that displays the amount of space each individual log table
+ * takes up in the MySQL database.
+ *
+ * @param bool $fetch If true, the rendered HTML datatable is returned, otherwise,
+ * it is echoed.
+ */
+ public function getTrackerDataSummary($fetch = false)
+ {
+ Piwik::checkUserIsSuperUser();
+
+ $view = $this->getDataTableView(__FUNCTION__);
+ $view->disableOffsetInformationAndPaginationControls();
+ return $this->renderView($view, $fetch);
+ }
+
+ /**
+ * Shows a datatable that displays the amount of space each numeric archive table
+ * takes up in the MySQL database.
+ *
+ * @param bool $fetch If true, the rendered HTML datatable is returned, otherwise,
+ * it is echoed.
+ */
+ public function getMetricDataSummary($fetch = false)
+ {
+ Piwik::checkUserIsSuperUser();
+ $view = $this->getDataTableView(__FUNCTION__, $viewType = 'table', $orderDir = 'desc');
+ $view->addRelatedReports(Piwik_Translate('DBStats_MetricTables'), array(
+ 'DBStats.getMetricDataSummaryByYear' => Piwik_Translate('DBStats_MetricDataByYear')
+ ));
+ return $this->renderView($view, $fetch);
+ }
+
+ /**
+ * Shows a datatable that displays the amount of space each numeric archive table
+ * takes up in the MySQL database, for each year of numeric data.
+ *
+ * @param bool $fetch If true, the rendered HTML datatable is returned, otherwise,
+ * it is echoed.
+ */
+ public function getMetricDataSummaryByYear($fetch = false)
+ {
+ Piwik::checkUserIsSuperUser();
+ $view = $this->getDataTableView(__FUNCTION__, $viewType = 'table', $orderDir = 'desc',
+ $addPercentColumn = false, $labelKey = 'CoreHome_PeriodYear');
+ $view->addRelatedReports(Piwik_Translate('DBStats_MetricDataByYear'), array(
+ 'DBStats.getMetricDataSummary' => Piwik_Translate('DBStats_MetricTables')
+ ));
+ return $this->renderView($view, $fetch);
+ }
+
+ /**
+ * Shows a datatable that displays the amount of space each blob archive table
+ * takes up in the MySQL database.
+ *
+ * @param bool $fetch If true, the rendered HTML datatable is returned, otherwise,
+ * it is echoed.
+ */
+ public function getReportDataSummary($fetch = false)
+ {
+ Piwik::checkUserIsSuperUser();
+ $view = $this->getDataTableView(__FUNCTION__, $viewType = 'table', $orderDir = 'desc');
+ $view->addRelatedReports(Piwik_Translate('DBStats_ReportTables'), array(
+ 'DBStats.getReportDataSummaryByYear' => Piwik_Translate('DBStats_ReportDataByYear')
+ ));
+ return $this->renderView($view, $fetch);
+ }
+
+ /**
+ * Shows a datatable that displays the amount of space each blob archive table
+ * takes up in the MySQL database, for each year of blob data.
+ *
+ * @param bool $fetch If true, the rendered HTML datatable is returned, otherwise,
+ * it is echoed.
+ */
+ public function getReportDataSummaryByYear($fetch = false)
+ {
+ Piwik::checkUserIsSuperUser();
+ $view = $this->getDataTableView(__FUNCTION__, $viewType = 'table', $orderDir = 'desc',
+ $addPercentColumn = false, $labelKey = 'CoreHome_PeriodYear');
+ $view->addRelatedReports(Piwik_Translate('DBStats_ReportDataByYear'), array(
+ 'DBStats.getReportDataSummary' => Piwik_Translate('DBStats_ReportTables')
+ ));
+ return $this->renderView($view, $fetch);
+ }
+
+ /**
+ * Shows a datatable that displays how many occurances there are of each individual
+ * report type stored in the MySQL database.
+ *
+ * Goal reports and reports of the format: .*_[0-9]+ are grouped together.
+ *
+ * @param bool $fetch If true, the rendered HTML datatable is returned, otherwise,
+ * it is echoed.
+ */
+ public function getIndividualReportsSummary($fetch = false)
+ {
+ Piwik::checkUserIsSuperUser();
+ $view = $this->getDataTableView(__FUNCTION__, $viewType = 'table', $orderDir = 'asc',
+ $addPercentColumn = false, $labelKey = 'General_Report',
+ $sizeColumns = array('estimated_size'));
+
+ // this report table has some extra columns that shouldn't be shown
+ if ($view instanceof Piwik_ViewDataTable_HtmlTable) {
+ $view->setColumnsToDisplay(array('label', 'row_count', 'estimated_size'));
+ }
+
+ $this->setIndividualSummaryFooterMessage($view);
+
+ return $this->renderView($view, $fetch);
+ }
+
+ /**
+ * Shows a datatable that displays how many occurances there are of each individual
+ * metric type stored in the MySQL database.
+ *
+ * Goal metrics, metrics of the format .*_[0-9]+ and 'done...' metrics are grouped together.
+ *
+ * @param bool $fetch If true, the rendered HTML datatable is returned, otherwise,
+ * it is echoed.
+ */
+ public function getIndividualMetricsSummary($fetch = false)
+ {
+ Piwik::checkUserIsSuperUser();
+ $view = $this->getDataTableView(__FUNCTION__, $viewType = 'table', $orderDir = 'asc',
+ $addPercentColumn = false, $labelKey = 'General_Metric',
+ $sizeColumns = array('estimated_size'));
+
+ $this->setIndividualSummaryFooterMessage($view);
+
+ return $this->renderView($view, $fetch);
+ }
+
+ /**
+ * Shows a datatable that displays the amount of space each 'admin' table takes
+ * up in the MySQL database.
+ *
+ * An 'admin' table is a table that is not central to analytics functionality.
+ * So any table that isn't an archive table or a log table is an 'admin' table.
+ *
+ * @param bool $fetch If true, the rendered HTML datatable is returned, otherwise,
+ * it is echoed.
+ */
+ public function getAdminDataSummary($fetch = false)
+ {
+ Piwik::checkUserIsSuperUser();
+ $view = $this->getDataTableView(__FUNCTION__, $viewType = 'table');
+ $view->disableOffsetInformationAndPaginationControls();
+ return $this->renderView($view, $fetch);
+ }
+
+ /**
+ * Utility function that creates and prepares a ViewDataTable for this plugin.
+ */
+ private function getDataTableView($function, $viewType = 'table', $orderDir = 'asc', $addPercentColumn = false,
+ $labelKey = 'DBStats_Table', $sizeColumns = array('data_size', 'index_size'),
+ $limit = 25)
+ {
+ $columnTranslations = array(
+ 'label' => Piwik_Translate($labelKey),
+ 'year' => Piwik_Translate('CoreHome_PeriodYear'),
+ 'data_size' => Piwik_Translate('DBStats_DataSize'),
+ 'index_size' => Piwik_Translate('DBStats_IndexSize'),
+ 'total_size' => Piwik_Translate('DBStats_TotalSize'),
+ 'row_count' => Piwik_Translate('DBStats_RowCount'),
+ 'percent_total' => '%&nbsp;' . Piwik_Translate('DBStats_DBSize'),
+ 'estimated_size' => Piwik_Translate('DBStats_EstimatedSize')
+ );
+
+ $view = Piwik_ViewDataTable::factory($viewType);
+ $view->init($this->pluginName, $function, "DBStats.$function");
+ $view->setSortedColumn('label', $orderDir);
+ $view->setLimit($limit);
+ $view->setHighlightSummaryRow(true);
+ $view->disableSearchBox();
+ $view->disableExcludeLowPopulation();
+ $view->disableTagCloud();
+ $view->disableShowAllColumns();
+ $view->alwaysShowSummaryRow();
+
+ // translate columns
+ foreach ($columnTranslations as $columnName => $translation) {
+ $view->setColumnTranslation($columnName, $translation);
+ }
+
+ // add total_size column (if necessary columns are present)
+ if (in_array('data_size', $sizeColumns) && in_array('index_size', $sizeColumns)) {
+ $getTotalTableSize = array($this, 'getTotalTableSize');
+ $view->queueFilter('ColumnCallbackAddColumn',
+ array(array('data_size', 'index_size'), 'total_size', $getTotalTableSize),
+ $runBeforeGenericFilters = true);
+
+ $sizeColumns[] = 'total_size';
+ }
+
+ $runPrettySizeFilterBeforeGeneric = false;
+ $fixedMemoryUnit = false;
+ if ($view instanceof Piwik_ViewDataTable_HtmlTable) // if displaying a table
+ {
+ $view->disableRowEvolution();
+
+ // add summary row only if displaying a table
+ $view->queueFilter('AddSummaryRow', array(0, Piwik_Translate('General_Total'), 'label', false),
+ $runBeforeGenericFilters = true);
+
+ // add other filters
+ if ($addPercentColumn && in_array('total_size', $sizeColumns)) {
+ $view->queueFilter('ColumnCallbackAddColumnPercentage',
+ array('percent_total', 'total_size', 'total_size', $quotientPrecision = 0, $shouldSkipRows = false,
+ $getDivisorFromSummaryRow = true),
+ $runBeforeGenericFilters = true);
+ $view->setSortedColumn('percent_total', $orderDir);
+ }
+ } else if ($view instanceof Piwik_ViewDataTable_GenerateGraphData) // if displaying a graph
+ {
+ if (in_array('total_size', $sizeColumns)) {
+ $view->setColumnsToDisplay(array('label', 'total_size'));
+
+ // when displaying a graph, we force sizes to be shown as the same unit so axis labels
+ // will be readable. NOTE: The unit should depend on the smallest value of the data table,
+ // however there's no way to know this information, short of creating a custom filter. For
+ // now, just assume KB.
+ $fixedMemoryUnit = 'K';
+ $view->setAxisYUnit(' K');
+
+ $view->setSortedColumn('total_size', 'desc');
+
+ $runPrettySizeFilterBeforeGeneric = true;
+ } else {
+ $view->setColumnsToDisplay(array('label', 'row_count'));
+ $view->setAxisYUnit(' ' . Piwik_Translate('General_Rows'));
+
+ $view->setSortedColumn('row_count', 'desc');
+ }
+ }
+
+ $getPrettySize = array('Piwik', 'getPrettySizeFromBytes');
+ $params = $fixedMemoryUnit === false ? array() : array($fixedMemoryUnit);
+ $view->queueFilter(
+ 'ColumnCallbackReplace', array($sizeColumns, $getPrettySize, $params), $runPrettySizeFilterBeforeGeneric);
+
+ // jqPlot will display &nbsp; as, well, '&nbsp;', so don't replace the spaces when rendering as a graph
+ if (!($view instanceof Piwik_ViewDataTable_GenerateGraphData)) {
+ $replaceSpaces = array($this, 'replaceColumnSpaces');
+ $view->queueFilter('ColumnCallbackReplace', array($sizeColumns, $replaceSpaces));
+ }
+
+ $getPrettyNumber = array('Piwik', 'getPrettyNumber');
+ $view->queueFilter('ColumnCallbackReplace', array(array('row_count'), $getPrettyNumber));
+
+ return $view;
+ }
+
+ /**
+ * Replaces spaces w/ &nbsp; for correct HTML output.
+ */
+ public function replaceColumnSpaces($value)
+ {
+ return str_replace(' ', '&nbsp;', $value);
+ }
+
+ /**
+ * Row callback function that calculates a tables total size.
+ */
+ public function getTotalTableSize($dataSize, $indexSize)
+ {
+ return $dataSize + $indexSize;
+ }
+
+ /**
+ * Column callback used to translate the column values in the database usage summary table.
+ */
+ public function translateSummarylabel($value)
+ {
+ static $valueToTranslationStr = array(
+ 'tracker_data' => 'DBStats_TrackerTables',
+ 'report_data' => 'DBStats_ReportTables',
+ 'metric_data' => 'DBStats_MetricTables',
+ 'other_data' => 'DBStats_OtherTables'
+ );
+
+ return isset($valueToTranslationStr[$value])
+ ? Piwik_Translate($valueToTranslationStr[$value])
+ : $value;
+ }
+
+ /**
+ * Sets the footer message for the Individual...Summary reports.
+ */
+ private function setIndividualSummaryFooterMessage($view)
+ {
+ $lastGenerated = Piwik_DBStats::getDateOfLastCachingRun();
+ if ($lastGenerated !== false) {
+ $view->setFooterMessage(Piwik_Translate('Mobile_LastUpdated', $lastGenerated));
+ }
+ }
}
diff --git a/plugins/DBStats/DBStats.php b/plugins/DBStats/DBStats.php
index 01a745c3ef..479596f30a 100644
--- a/plugins/DBStats/DBStats.php
+++ b/plugins/DBStats/DBStats.php
@@ -1,10 +1,10 @@
<?php
/**
* Piwik - Open source web analytics
- *
+ *
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
- *
+ *
* @category Piwik_Plugins
* @package Piwik_DBStats
*/
@@ -15,70 +15,70 @@
*/
class Piwik_DBStats extends Piwik_Plugin
{
- const TIME_OF_LAST_TASK_RUN_OPTION = 'dbstats_time_of_last_cache_task_run';
-
- public function getInformation()
- {
- return array(
- 'description' => Piwik_Translate('DBStats_PluginDescription'),
- 'author' => 'Piwik',
- 'author_homepage' => 'http://piwik.org/',
- 'version' => Piwik_Version::VERSION,
- );
- }
+ const TIME_OF_LAST_TASK_RUN_OPTION = 'dbstats_time_of_last_cache_task_run';
- function getListHooksRegistered()
- {
- return array(
- 'AdminMenu.add' => 'addMenu',
+ public function getInformation()
+ {
+ return array(
+ 'description' => Piwik_Translate('DBStats_PluginDescription'),
+ 'author' => 'Piwik',
+ 'author_homepage' => 'http://piwik.org/',
+ 'version' => Piwik_Version::VERSION,
+ );
+ }
+
+ function getListHooksRegistered()
+ {
+ return array(
+ 'AdminMenu.add' => 'addMenu',
'TaskScheduler.getScheduledTasks' => 'getScheduledTasks',
- );
- }
-
- function addMenu()
- {
- Piwik_AddAdminSubMenu('CoreAdminHome_MenuDiagnostic', 'DBStats_DatabaseUsage',
- array('module' => 'DBStats', 'action' => 'index'),
- Piwik::isUserIsSuperUser(),
- $order = 9);
- }
+ );
+ }
+
+ function addMenu()
+ {
+ Piwik_AddAdminSubMenu('CoreAdminHome_MenuDiagnostic', 'DBStats_DatabaseUsage',
+ array('module' => 'DBStats', 'action' => 'index'),
+ Piwik::isUserIsSuperUser(),
+ $order = 9);
+ }
+
+ /**
+ * Gets all scheduled tasks executed by this plugin.
+ *
+ * @param Piwik_Event_Notification $notification notification object
+ */
+ public function getScheduledTasks($notification)
+ {
+ $tasks = & $notification->getNotificationObject();
+
+ $cacheDataByArchiveNameReportsTask = new Piwik_ScheduledTask(
+ $this,
+ 'cacheDataByArchiveNameReports',
+ null,
+ new Piwik_ScheduledTime_Weekly(),
+ Piwik_ScheduledTask::LOWEST_PRIORITY
+ );
+ $tasks[] = $cacheDataByArchiveNameReportsTask;
+ }
+
+ /**
+ * Caches the intermediate DataTables used in the getIndividualReportsSummary and
+ * getIndividualMetricsSummary reports in the option table.
+ */
+ public function cacheDataByArchiveNameReports()
+ {
+ $api = Piwik_DBStats_API::getInstance();
+ $api->getIndividualReportsSummary(true);
+ $api->getIndividualMetricsSummary(true);
- /**
- * Gets all scheduled tasks executed by this plugin.
- *
- * @param Piwik_Event_Notification $notification notification object
- */
- public function getScheduledTasks($notification)
- {
- $tasks = &$notification->getNotificationObject();
+ $now = Piwik_Date::now()->getLocalized("%longYear%, %shortMonth% %day%");
+ Piwik_SetOption(self::TIME_OF_LAST_TASK_RUN_OPTION, $now);
+ }
- $cacheDataByArchiveNameReportsTask = new Piwik_ScheduledTask(
- $this,
- 'cacheDataByArchiveNameReports',
- null,
- new Piwik_ScheduledTime_Weekly(),
- Piwik_ScheduledTask::LOWEST_PRIORITY
- );
- $tasks[] = $cacheDataByArchiveNameReportsTask;
- }
-
- /**
- * Caches the intermediate DataTables used in the getIndividualReportsSummary and
- * getIndividualMetricsSummary reports in the option table.
- */
- public function cacheDataByArchiveNameReports()
- {
- $api = Piwik_DBStats_API::getInstance();
- $api->getIndividualReportsSummary(true);
- $api->getIndividualMetricsSummary(true);
-
- $now = Piwik_Date::now()->getLocalized("%longYear%, %shortMonth% %day%");
- Piwik_SetOption(self::TIME_OF_LAST_TASK_RUN_OPTION, $now);
- }
-
- /** Returns the date when the cacheDataByArchiveNameReports was last run. */
- public static function getDateOfLastCachingRun()
- {
- return Piwik_GetOption(self::TIME_OF_LAST_TASK_RUN_OPTION);
- }
+ /** Returns the date when the cacheDataByArchiveNameReports was last run. */
+ public static function getDateOfLastCachingRun()
+ {
+ return Piwik_GetOption(self::TIME_OF_LAST_TASK_RUN_OPTION);
+ }
}
diff --git a/plugins/DBStats/MySQLMetadataProvider.php b/plugins/DBStats/MySQLMetadataProvider.php
index ccb3ae2431..6240a24b19 100755
--- a/plugins/DBStats/MySQLMetadataProvider.php
+++ b/plugins/DBStats/MySQLMetadataProvider.php
@@ -1,10 +1,10 @@
<?php
/**
* Piwik - Open source web analytics
- *
+ *
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
- *
+ *
* @category Piwik_Plugins
* @package Piwik_DBStats
*/
@@ -13,374 +13,348 @@
* Utility class that provides general information about databases, including the size of
* the entire database, the size and row count of each table and the size and row count
* of each metric/report type currently stored.
- *
+ *
* This class will cache the table information it retrieves from the database. In order to
* issue a new query instead of using this cache, you must create a new instance of this type.
*/
class Piwik_DBStats_MySQLMetadataProvider
{
- /**
- * Cached MySQL table statuses. So we won't needlessly re-issue SHOW TABLE STATUS queries.
- */
- private $tableStatuses = null;
-
- /**
- * Constructor.
- */
- public function __construct()
- {
- // empty
- }
-
- /**
- * Gets general database info that is not specific to any table.
- *
- * @return array See http://dev.mysql.com/doc/refman/5.1/en/show-status.html .
- */
- public function getDBStatus()
- {
- if (function_exists('mysql_connect'))
- {
- $configDb = Piwik_Config::getInstance()->database;
- $link = mysql_connect($configDb['host'], $configDb['username'], $configDb['password']);
- $status = mysql_stat($link);
- mysql_close($link);
- $status = explode(" ", $status);
- }
- else
- {
- $fullStatus = Piwik_FetchAssoc('SHOW STATUS');
- if (empty($fullStatus))
- {
- throw new Exception('Error, SHOW STATUS failed');
- }
-
- $status = array(
- 'Uptime' => $fullStatus['Uptime']['Value'],
- 'Threads' => $fullStatus['Threads_running']['Value'],
- 'Questions' => $fullStatus['Questions']['Value'],
- 'Slow queries' => $fullStatus['Slow_queries']['Value'],
- 'Flush tables' => $fullStatus['Flush_commands']['Value'],
- 'Open tables' => $fullStatus['Open_tables']['Value'],
- 'Opens' => 'unavailable', // not available via SHOW STATUS
- 'Queries per second avg' => 'unavailable' // not available via SHOW STATUS
- );
- }
-
- return $status;
- }
-
- /**
- * Gets the MySQL table status of the requested Piwik table.
- *
- * @param string $table The name of the table. Should not be prefixed (ie, 'log_visit' is
- * correct, 'piwik_log_visit' is not).
- * @return array See http://dev.mysql.com/doc/refman/5.1/en/show-table-status.html .
- */
- public function getTableStatus( $table )
- {
- $prefixed = Piwik_Common::prefixTable($table);
-
- // if we've already gotten every table status, don't issue an uneeded query
- if (!is_null($this->tableStatuses) && isset($this->tableStatuses[$prefixed]))
- {
- return $this->tableStatuses[$prefixed];
- }
- else
- {
- return Piwik_FetchRow("SHOW TABLE STATUS LIKE ?", array($prefixed));
- }
- }
-
- /**
- * Gets the result of a SHOW TABLE STATUS query for every Piwik table in the DB.
- * Non-piwik tables are ignored.
- *
- * @param string $matchingRegex Regex used to filter out tables whose name doesn't
- * match it.
- * @return array The table information. See http://dev.mysql.com/doc/refman/5.5/en/show-table-status.html
- * for specifics.
- */
- public function getAllTablesStatus( $matchingRegex = null )
- {
- if (is_null($this->tableStatuses))
- {
- $tablesPiwik = Piwik::getTablesInstalled();
-
- $this->tableStatuses = array();
- foreach(Piwik_FetchAll("SHOW TABLE STATUS") as $t)
- {
- if (in_array($t['Name'], $tablesPiwik))
- {
- $this->tableStatuses[$t['Name']] = $t;
- }
- }
- }
-
- if (is_null($matchingRegex))
- {
- return $this->tableStatuses;
- }
-
- $result = array();
- foreach ($this->tableStatuses as $status)
- {
- if (preg_match($matchingRegex, $status['Name']))
- {
- $result[] = $status;
- }
- }
- return $result;
- }
-
- /**
- * Returns table statuses for every log table.
- *
- * @return array An array of status arrays. See http://dev.mysql.com/doc/refman/5.5/en/show-table-status.html.
- */
- public function getAllLogTableStatus()
- {
- $regex = "/^".Piwik_Common::prefixTable('log_')."(?!profiling)/";
- return $this->getAllTablesStatus($regex);
- }
-
- /**
- * Returns table statuses for every numeric archive table.
- *
- * @return array An array of status arrays. See http://dev.mysql.com/doc/refman/5.5/en/show-table-status.html.
- */
- public function getAllNumericArchiveStatus()
- {
- $regex = "/^".Piwik_Common::prefixTable('archive_numeric')."_/";
- return $this->getAllTablesStatus($regex);
- }
-
- /**
- * Returns table statuses for every blob archive table.
- *
- * @return array An array of status arrays. See http://dev.mysql.com/doc/refman/5.5/en/show-table-status.html.
- */
- public function getAllBlobArchiveStatus()
- {
- $regex = "/^".Piwik_Common::prefixTable('archive_blob')."_/";
- return $this->getAllTablesStatus($regex);
- }
-
- /**
- * Retruns table statuses for every admin table.
- *
- * @return array An array of status arrays. See http://dev.mysql.com/doc/refman/5.5/en/show-table-status.html.
- */
- public function getAllAdminTableStatus()
- {
- $regex = "/^".Piwik_Common::prefixTable('')."(?!archive_|(?:log_(?!profiling)))/";
- return $this->getAllTablesStatus($regex);
- }
-
- /**
- * Returns a DataTable that lists the number of rows and the estimated amount of space
- * each blob archive type takes up in the database.
- *
- * Blob types are differentiated by name.
- *
- * @param bool $forceCache false to use the cached result, true to run the queries again and
- * cache the result.
- * @return Piwik_DataTable
- */
- public function getRowCountsAndSizeByBlobName( $forceCache = false )
- {
- $extraSelects = array("SUM(OCTET_LENGTH(value)) AS 'blob_size'", "SUM(LENGTH(name)) AS 'name_size'");
- $extraCols = array('blob_size', 'name_size');
- return $this->getRowCountsByArchiveName(
- $this->getAllBlobArchiveStatus(), 'getEstimatedBlobArchiveRowSize', $forceCache, $extraSelects,
- $extraCols);
- }
-
- /**
- * Returns a DataTable that lists the number of rows and the estimated amount of space
- * each metric archive type takes up in the database.
- *
- * Metric types are differentiated by name.
- *
- * @param bool $forceCache false to use the cached result, true to run the queries again and
- * cache the result.
- * @return Piwik_DataTable
- */
- public function getRowCountsAndSizeByMetricName( $forceCache = false )
- {
- return $this->getRowCountsByArchiveName(
- $this->getAllNumericArchiveStatus(), 'getEstimatedRowsSize', $forceCache);
- }
-
- /**
- * Utility function. Gets row count of a set of tables grouped by the 'name' column.
- * This is the implementation of the getRowCountsAndSizeBy... functions.
- */
- private function getRowCountsByArchiveName( $statuses, $getRowSizeMethod, $forceCache = false,
- $otherSelects = array(), $otherDataTableColumns = array() )
- {
- $extraCols = '';
- if (!empty($otherSelects))
- {
- $extraCols = ', '.implode(', ', $otherSelects);
- }
-
- $cols = array_merge(array('row_count'), $otherDataTableColumns);
-
- $dataTable = new Piwik_DataTable();
- foreach ($statuses as $status)
- {
- $dataTableOptionName = $this->getCachedOptionName($status['Name'], 'byArchiveName');
-
- // if option exists && !$forceCache, use the cached data, otherwise create the
- $cachedData = Piwik_GetOption($dataTableOptionName);
- if ($cachedData !== false && !$forceCache)
- {
- $table = new Piwik_DataTable();
- $table->addRowsFromSerializedArray($cachedData);
- }
- else
- {
- // otherwise, create data table & cache it
- $sql = "SELECT name as 'label', COUNT(*) as 'row_count'$extraCols FROM {$status['Name']} GROUP BY name";
-
- $table = new Piwik_DataTable();
- $table->addRowsFromSimpleArray(Piwik_FetchAll($sql));
-
- $reduceArchiveRowName = array($this, 'reduceArchiveRowName');
- $table->filter('GroupBy', array('label', $reduceArchiveRowName));
-
- $serializedTables = $table->getSerialized();
- $serializedTable = reset($serializedTables);
- Piwik_SetOption($dataTableOptionName, $serializedTable);
- }
-
- // add estimated_size column
- $getEstimatedSize = array($this, $getRowSizeMethod);
- $table->filter('ColumnCallbackAddColumn',
- array($cols, 'estimated_size', $getEstimatedSize, array($status)));
-
- $dataTable->addDataTable($table);
- destroy($table);
- }
- return $dataTable;
- }
-
- /**
- * Gets the estimated database size a count of rows takes in a table.
- */
- public function getEstimatedRowsSize( $row_count, $status )
- {
- if($status['Rows'] == 0)
- {
- return 0;
- }
- $avgRowSize = ($status['Data_length'] + $status['Index_length']) / $status['Rows'];
- return $avgRowSize * $row_count;
- }
-
- /**
- * Gets the estimated database size a count of rows in a blob_archive table. Depends on
- * the data table row to contain the size of all blobs & name strings in the row set it
- * represents.
- */
- public function getEstimatedBlobArchiveRowSize( $row_count, $blob_size, $name_size, $status )
- {
- // calculate the size of each fixed size column in a blob archive table
- static $fixedSizeColumnLength = null;
- if (is_null($fixedSizeColumnLength))
- {
- $fixedSizeColumnLength = 0;
- foreach (Piwik_FetchAll("SHOW COLUMNS FROM ".$status['Name']) as $column)
- {
- $columnType = $column['Type'];
-
- if (($paren = strpos($columnType, '(')) !== false)
- {
- $columnType = substr($columnType, 0, $paren);
- }
-
- $fixedSizeColumnLength += $this->sizeOfMySQLColumn($columnType);
- }
- }
- // calculate the average row size
- if($status['Rows'] == 0) {
- $avgRowSize = 0;
- } else {
- $avgRowSize = $status['Index_length'] / $status['Rows'] + $fixedSizeColumnLength;
- }
-
- // calculate the row set's size
- return $avgRowSize * $row_count + $blob_size + $name_size;
- }
-
- /** Returns the size in bytes of a fixed size MySQL data type. Returns 0 for unsupported data type. */
- private function sizeOfMySQLColumn( $columnType )
- {
- switch (strtolower($columnType))
- {
- case "tinyint":
- case "year":
- return 1;
- case "smallint":
- return 2;
- case "mediumint":
- case "date":
- case "time":
- return 3;
- case "int":
- case "float": // assumes precision isn't used
- case "timestamp":
- return 4;
- case "bigint":
- case "double":
- case "real":
- case "datetime":
- return 8;
- default:
- return 0;
- }
- }
-
- /**
- * Gets the option name used to cache the result of an intensive query.
- */
- private function getCachedOptionName( $tableName, $suffix )
- {
- return 'dbstats_cached_'.$tableName.'_'.$suffix;
- }
-
- /**
- * Reduces the given metric name. Used to simplify certain reports.
- *
- * Some metrics, like goal metrics, can have different string names. For goal metrics,
- * there's one name per goal ID. Grouping metrics and reports like these together
- * simplifies the tables that display them.
- *
- * This function makes goal names, 'done...' names and names of the format .*_[0-9]+
- * equivalent.
- */
- public function reduceArchiveRowName( $name )
- {
- // all 'done...' fields are considered the same
- if (strpos($name, 'done') === 0)
- {
- return 'done';
- }
-
- // check for goal id, if present (Goals_... reports should not be reduced here, just Goal_... ones)
- if (preg_match("/^Goal_(?:-?[0-9]+_)?(.*)/", $name, $matches))
- {
- $name = "Goal_*_".$matches[1];
- }
-
- // remove subtable id suffix, if present
- if (preg_match("/^(.*)_[0-9]+$/", $name, $matches))
- {
- $name = $matches[1]."_*";
- }
-
- return $name;
- }
+ /**
+ * Cached MySQL table statuses. So we won't needlessly re-issue SHOW TABLE STATUS queries.
+ */
+ private $tableStatuses = null;
+
+ /**
+ * Constructor.
+ */
+ public function __construct()
+ {
+ // empty
+ }
+
+ /**
+ * Gets general database info that is not specific to any table.
+ *
+ * @return array See http://dev.mysql.com/doc/refman/5.1/en/show-status.html .
+ */
+ public function getDBStatus()
+ {
+ if (function_exists('mysql_connect')) {
+ $configDb = Piwik_Config::getInstance()->database;
+ $link = mysql_connect($configDb['host'], $configDb['username'], $configDb['password']);
+ $status = mysql_stat($link);
+ mysql_close($link);
+ $status = explode(" ", $status);
+ } else {
+ $fullStatus = Piwik_FetchAssoc('SHOW STATUS');
+ if (empty($fullStatus)) {
+ throw new Exception('Error, SHOW STATUS failed');
+ }
+
+ $status = array(
+ 'Uptime' => $fullStatus['Uptime']['Value'],
+ 'Threads' => $fullStatus['Threads_running']['Value'],
+ 'Questions' => $fullStatus['Questions']['Value'],
+ 'Slow queries' => $fullStatus['Slow_queries']['Value'],
+ 'Flush tables' => $fullStatus['Flush_commands']['Value'],
+ 'Open tables' => $fullStatus['Open_tables']['Value'],
+ 'Opens' => 'unavailable', // not available via SHOW STATUS
+ 'Queries per second avg' => 'unavailable' // not available via SHOW STATUS
+ );
+ }
+
+ return $status;
+ }
+
+ /**
+ * Gets the MySQL table status of the requested Piwik table.
+ *
+ * @param string $table The name of the table. Should not be prefixed (ie, 'log_visit' is
+ * correct, 'piwik_log_visit' is not).
+ * @return array See http://dev.mysql.com/doc/refman/5.1/en/show-table-status.html .
+ */
+ public function getTableStatus($table)
+ {
+ $prefixed = Piwik_Common::prefixTable($table);
+
+ // if we've already gotten every table status, don't issue an uneeded query
+ if (!is_null($this->tableStatuses) && isset($this->tableStatuses[$prefixed])) {
+ return $this->tableStatuses[$prefixed];
+ } else {
+ return Piwik_FetchRow("SHOW TABLE STATUS LIKE ?", array($prefixed));
+ }
+ }
+
+ /**
+ * Gets the result of a SHOW TABLE STATUS query for every Piwik table in the DB.
+ * Non-piwik tables are ignored.
+ *
+ * @param string $matchingRegex Regex used to filter out tables whose name doesn't
+ * match it.
+ * @return array The table information. See http://dev.mysql.com/doc/refman/5.5/en/show-table-status.html
+ * for specifics.
+ */
+ public function getAllTablesStatus($matchingRegex = null)
+ {
+ if (is_null($this->tableStatuses)) {
+ $tablesPiwik = Piwik::getTablesInstalled();
+
+ $this->tableStatuses = array();
+ foreach (Piwik_FetchAll("SHOW TABLE STATUS") as $t) {
+ if (in_array($t['Name'], $tablesPiwik)) {
+ $this->tableStatuses[$t['Name']] = $t;
+ }
+ }
+ }
+
+ if (is_null($matchingRegex)) {
+ return $this->tableStatuses;
+ }
+
+ $result = array();
+ foreach ($this->tableStatuses as $status) {
+ if (preg_match($matchingRegex, $status['Name'])) {
+ $result[] = $status;
+ }
+ }
+ return $result;
+ }
+
+ /**
+ * Returns table statuses for every log table.
+ *
+ * @return array An array of status arrays. See http://dev.mysql.com/doc/refman/5.5/en/show-table-status.html.
+ */
+ public function getAllLogTableStatus()
+ {
+ $regex = "/^" . Piwik_Common::prefixTable('log_') . "(?!profiling)/";
+ return $this->getAllTablesStatus($regex);
+ }
+
+ /**
+ * Returns table statuses for every numeric archive table.
+ *
+ * @return array An array of status arrays. See http://dev.mysql.com/doc/refman/5.5/en/show-table-status.html.
+ */
+ public function getAllNumericArchiveStatus()
+ {
+ $regex = "/^" . Piwik_Common::prefixTable('archive_numeric') . "_/";
+ return $this->getAllTablesStatus($regex);
+ }
+
+ /**
+ * Returns table statuses for every blob archive table.
+ *
+ * @return array An array of status arrays. See http://dev.mysql.com/doc/refman/5.5/en/show-table-status.html.
+ */
+ public function getAllBlobArchiveStatus()
+ {
+ $regex = "/^" . Piwik_Common::prefixTable('archive_blob') . "_/";
+ return $this->getAllTablesStatus($regex);
+ }
+
+ /**
+ * Retruns table statuses for every admin table.
+ *
+ * @return array An array of status arrays. See http://dev.mysql.com/doc/refman/5.5/en/show-table-status.html.
+ */
+ public function getAllAdminTableStatus()
+ {
+ $regex = "/^" . Piwik_Common::prefixTable('') . "(?!archive_|(?:log_(?!profiling)))/";
+ return $this->getAllTablesStatus($regex);
+ }
+
+ /**
+ * Returns a DataTable that lists the number of rows and the estimated amount of space
+ * each blob archive type takes up in the database.
+ *
+ * Blob types are differentiated by name.
+ *
+ * @param bool $forceCache false to use the cached result, true to run the queries again and
+ * cache the result.
+ * @return Piwik_DataTable
+ */
+ public function getRowCountsAndSizeByBlobName($forceCache = false)
+ {
+ $extraSelects = array("SUM(OCTET_LENGTH(value)) AS 'blob_size'", "SUM(LENGTH(name)) AS 'name_size'");
+ $extraCols = array('blob_size', 'name_size');
+ return $this->getRowCountsByArchiveName(
+ $this->getAllBlobArchiveStatus(), 'getEstimatedBlobArchiveRowSize', $forceCache, $extraSelects,
+ $extraCols);
+ }
+
+ /**
+ * Returns a DataTable that lists the number of rows and the estimated amount of space
+ * each metric archive type takes up in the database.
+ *
+ * Metric types are differentiated by name.
+ *
+ * @param bool $forceCache false to use the cached result, true to run the queries again and
+ * cache the result.
+ * @return Piwik_DataTable
+ */
+ public function getRowCountsAndSizeByMetricName($forceCache = false)
+ {
+ return $this->getRowCountsByArchiveName(
+ $this->getAllNumericArchiveStatus(), 'getEstimatedRowsSize', $forceCache);
+ }
+
+ /**
+ * Utility function. Gets row count of a set of tables grouped by the 'name' column.
+ * This is the implementation of the getRowCountsAndSizeBy... functions.
+ */
+ private function getRowCountsByArchiveName($statuses, $getRowSizeMethod, $forceCache = false,
+ $otherSelects = array(), $otherDataTableColumns = array())
+ {
+ $extraCols = '';
+ if (!empty($otherSelects)) {
+ $extraCols = ', ' . implode(', ', $otherSelects);
+ }
+
+ $cols = array_merge(array('row_count'), $otherDataTableColumns);
+
+ $dataTable = new Piwik_DataTable();
+ foreach ($statuses as $status) {
+ $dataTableOptionName = $this->getCachedOptionName($status['Name'], 'byArchiveName');
+
+ // if option exists && !$forceCache, use the cached data, otherwise create the
+ $cachedData = Piwik_GetOption($dataTableOptionName);
+ if ($cachedData !== false && !$forceCache) {
+ $table = new Piwik_DataTable();
+ $table->addRowsFromSerializedArray($cachedData);
+ } else {
+ // otherwise, create data table & cache it
+ $sql = "SELECT name as 'label', COUNT(*) as 'row_count'$extraCols FROM {$status['Name']} GROUP BY name";
+
+ $table = new Piwik_DataTable();
+ $table->addRowsFromSimpleArray(Piwik_FetchAll($sql));
+
+ $reduceArchiveRowName = array($this, 'reduceArchiveRowName');
+ $table->filter('GroupBy', array('label', $reduceArchiveRowName));
+
+ $serializedTables = $table->getSerialized();
+ $serializedTable = reset($serializedTables);
+ Piwik_SetOption($dataTableOptionName, $serializedTable);
+ }
+
+ // add estimated_size column
+ $getEstimatedSize = array($this, $getRowSizeMethod);
+ $table->filter('ColumnCallbackAddColumn',
+ array($cols, 'estimated_size', $getEstimatedSize, array($status)));
+
+ $dataTable->addDataTable($table);
+ destroy($table);
+ }
+ return $dataTable;
+ }
+
+ /**
+ * Gets the estimated database size a count of rows takes in a table.
+ */
+ public function getEstimatedRowsSize($row_count, $status)
+ {
+ if ($status['Rows'] == 0) {
+ return 0;
+ }
+ $avgRowSize = ($status['Data_length'] + $status['Index_length']) / $status['Rows'];
+ return $avgRowSize * $row_count;
+ }
+
+ /**
+ * Gets the estimated database size a count of rows in a blob_archive table. Depends on
+ * the data table row to contain the size of all blobs & name strings in the row set it
+ * represents.
+ */
+ public function getEstimatedBlobArchiveRowSize($row_count, $blob_size, $name_size, $status)
+ {
+ // calculate the size of each fixed size column in a blob archive table
+ static $fixedSizeColumnLength = null;
+ if (is_null($fixedSizeColumnLength)) {
+ $fixedSizeColumnLength = 0;
+ foreach (Piwik_FetchAll("SHOW COLUMNS FROM " . $status['Name']) as $column) {
+ $columnType = $column['Type'];
+
+ if (($paren = strpos($columnType, '(')) !== false) {
+ $columnType = substr($columnType, 0, $paren);
+ }
+
+ $fixedSizeColumnLength += $this->sizeOfMySQLColumn($columnType);
+ }
+ }
+ // calculate the average row size
+ if ($status['Rows'] == 0) {
+ $avgRowSize = 0;
+ } else {
+ $avgRowSize = $status['Index_length'] / $status['Rows'] + $fixedSizeColumnLength;
+ }
+
+ // calculate the row set's size
+ return $avgRowSize * $row_count + $blob_size + $name_size;
+ }
+
+ /** Returns the size in bytes of a fixed size MySQL data type. Returns 0 for unsupported data type. */
+ private function sizeOfMySQLColumn($columnType)
+ {
+ switch (strtolower($columnType)) {
+ case "tinyint":
+ case "year":
+ return 1;
+ case "smallint":
+ return 2;
+ case "mediumint":
+ case "date":
+ case "time":
+ return 3;
+ case "int":
+ case "float": // assumes precision isn't used
+ case "timestamp":
+ return 4;
+ case "bigint":
+ case "double":
+ case "real":
+ case "datetime":
+ return 8;
+ default:
+ return 0;
+ }
+ }
+
+ /**
+ * Gets the option name used to cache the result of an intensive query.
+ */
+ private function getCachedOptionName($tableName, $suffix)
+ {
+ return 'dbstats_cached_' . $tableName . '_' . $suffix;
+ }
+
+ /**
+ * Reduces the given metric name. Used to simplify certain reports.
+ *
+ * Some metrics, like goal metrics, can have different string names. For goal metrics,
+ * there's one name per goal ID. Grouping metrics and reports like these together
+ * simplifies the tables that display them.
+ *
+ * This function makes goal names, 'done...' names and names of the format .*_[0-9]+
+ * equivalent.
+ */
+ public function reduceArchiveRowName($name)
+ {
+ // all 'done...' fields are considered the same
+ if (strpos($name, 'done') === 0) {
+ return 'done';
+ }
+
+ // check for goal id, if present (Goals_... reports should not be reduced here, just Goal_... ones)
+ if (preg_match("/^Goal_(?:-?[0-9]+_)?(.*)/", $name, $matches)) {
+ $name = "Goal_*_" . $matches[1];
+ }
+
+ // remove subtable id suffix, if present
+ if (preg_match("/^(.*)_[0-9]+$/", $name, $matches)) {
+ $name = $matches[1] . "_*";
+ }
+
+ return $name;
+ }
}
diff --git a/plugins/DBStats/templates/index.tpl b/plugins/DBStats/templates/index.tpl
index efe3550e89..5c85eea7d9 100755
--- a/plugins/DBStats/templates/index.tpl
+++ b/plugins/DBStats/templates/index.tpl
@@ -2,145 +2,154 @@
{loadJavascriptTranslations plugins='CoreAdminHome CoreHome'}
{literal}
-<style>
-.dbstatsTable {
- display: inline-block;
-}
-.dbstatsTable>tbody>tr>td:first-child {
- width: 550px;
-}
-.dbstatsTable h2 {
- width: 500px;
-}
-.adminTable.dbstatsTable a {
- color: black;
- text-decoration: underline;
-}
-</style>
+ <style>
+ .dbstatsTable {
+ display: inline-block;
+ }
+
+ .dbstatsTable>tbody>tr>td:first-child {
+ width: 550px;
+ }
+
+ .dbstatsTable h2 {
+ width: 500px;
+ }
+
+ .adminTable.dbstatsTable a {
+ color: black;
+ text-decoration: underline;
+ }
+ </style>
{/literal}
<a name="databaseUsageSummary"></a>
<h2>{'DBStats_DatabaseUsage'|translate}</h2>
<p>
- {'DBStats_MainDescription'|translate:$totalSpaceUsed}<br/>
- {'DBStats_LearnMore'|translate:"<a href='?module=Proxy&action=redirect&url=http://piwik.org/docs/setup-auto-archiving/' target='_blank'>Piwik Auto Archiving</a>"}<br/>
- <br/>
+ {'DBStats_MainDescription'|translate:$totalSpaceUsed}<br/>
+ {'DBStats_LearnMore'|translate:"<a href='?module=Proxy&action=redirect&url=http://piwik.org/docs/setup-auto-archiving/' target='_blank'>Piwik Auto Archiving</a>"}
+ <br/>
+ <br/>
</p>
<table class="adminTable dbstatsTable">
- <tbody>
- <tr>
- <td>{$databaseUsageSummary}</td>
- <td>
- <h3 style="margin-top:0">{'General_GeneralInformation'|translate}</h3><br/>
- <p style="font-size:1.4em;padding-left:21px;line-height:1.8em">
- <strong><em>{$userCount}</strong></em>&nbsp;{if $userCount == 1}{'UsersManager_User'|translate}{else}{'UsersManager_MenuUsers'|translate}{/if}<br/>
- <strong><em>{$siteCount}</strong></em>&nbsp;{if $siteCount == 1}{'General_Website'|translate}{else}{'Referers_Websites'|translate}{/if}
- </p><br/>
- {capture assign=clickDeleteLogSettings}{'PrivacyManager_DeleteDataSettings'|translate}{/capture}
- <h3 style="margin-top:0">{'PrivacyManager_DeleteDataSettings'|translate}</h3><br/>
- <p>
- {'PrivacyManager_DeleteDataDescription'|translate}
- <br/>
- <a href='{url module="PrivacyManager" action="privacySettings"}#deleteLogsAnchor'>
- {'PrivacyManager_ClickHereSettings'|translate:"'$clickDeleteLogSettings'"}
- </a>
- </p>
- </td>
- </tr>
- </tbody>
+ <tbody>
+ <tr>
+ <td>{$databaseUsageSummary}</td>
+ <td>
+ <h3 style="margin-top:0">{'General_GeneralInformation'|translate}</h3><br/>
+
+ <p style="font-size:1.4em;padding-left:21px;line-height:1.8em">
+ <strong><em>{$userCount}</strong></em>&nbsp;{if $userCount == 1}{'UsersManager_User'|translate}{else}{'UsersManager_MenuUsers'|translate}{/if}
+ <br/>
+ <strong><em>{$siteCount}</strong></em>&nbsp;{if $siteCount == 1}{'General_Website'|translate}{else}{'Referers_Websites'|translate}{/if}
+ </p><br/>
+ {capture assign=clickDeleteLogSettings}{'PrivacyManager_DeleteDataSettings'|translate}{/capture}
+ <h3 style="margin-top:0">{'PrivacyManager_DeleteDataSettings'|translate}</h3><br/>
+
+ <p>
+ {'PrivacyManager_DeleteDataDescription'|translate}
+ <br/>
+ <a href='{url module="PrivacyManager" action="privacySettings"}#deleteLogsAnchor'>
+ {'PrivacyManager_ClickHereSettings'|translate:"'$clickDeleteLogSettings'"}
+ </a>
+ </p>
+ </td>
+ </tr>
+ </tbody>
</table>
<br/>
<a name="trackerDataSummary"></a>
<table class="adminTable dbstatsTable">
- <tbody>
- <tr>
- <td>
- <h2>{'DBStats_TrackerTables'|translate}</h2>
- {$trackerDataSummary}
- </td>
- <td>&nbsp;</td>
- </tr>
- </tbody>
+ <tbody>
+ <tr>
+ <td>
+ <h2>{'DBStats_TrackerTables'|translate}</h2>
+ {$trackerDataSummary}
+ </td>
+ <td>&nbsp;</td>
+ </tr>
+ </tbody>
</table>
<a name="reportDataSummary"></a>
<table class="adminTable dbstatsTable">
- <tbody>
- <tr>
- <td>
- <h2>{'DBStats_ReportTables'|translate}</h2>
- {$reportDataSummary}
- </td>
- <td>
- <h2>{'General_Reports'|translate}</h2>
- <div class="ajaxLoad" action="getIndividualReportsSummary">
- <span class="loadingPiwik"><img src="themes/default/images/loading-blue.gif" />{'General_LoadingData'|translate}</span>
- </div>
- </td>
- </tr>
- </tbody>
+ <tbody>
+ <tr>
+ <td>
+ <h2>{'DBStats_ReportTables'|translate}</h2>
+ {$reportDataSummary}
+ </td>
+ <td>
+ <h2>{'General_Reports'|translate}</h2>
+
+ <div class="ajaxLoad" action="getIndividualReportsSummary">
+ <span class="loadingPiwik"><img src="themes/default/images/loading-blue.gif"/>{'General_LoadingData'|translate}</span>
+ </div>
+ </td>
+ </tr>
+ </tbody>
</table>
<a name="metricDataSummary"></a>
<table class="adminTable dbstatsTable">
- <tbody>
- <tr>
- <td>
- <h2>{'DBStats_MetricTables'|translate}</h2>
- {$metricDataSummary}
- </td>
- <td>
- <h2>{'General_Metrics'|translate}</h2>
- <div class="ajaxLoad" action="getIndividualMetricsSummary">
- <span class="loadingPiwik"><img src="themes/default/images/loading-blue.gif" />{'General_LoadingData'|translate}</span>
- </div>
- </td>
- </tr>
- </tbody>
+ <tbody>
+ <tr>
+ <td>
+ <h2>{'DBStats_MetricTables'|translate}</h2>
+ {$metricDataSummary}
+ </td>
+ <td>
+ <h2>{'General_Metrics'|translate}</h2>
+
+ <div class="ajaxLoad" action="getIndividualMetricsSummary">
+ <span class="loadingPiwik"><img src="themes/default/images/loading-blue.gif"/>{'General_LoadingData'|translate}</span>
+ </div>
+ </td>
+ </tr>
+ </tbody>
</table>
<a name="adminDataSummary"></a>
<table class="adminTable dbstatsTable">
- <tbody>
- <tr>
- <td>
- <h2>{'DBStats_OtherTables'|translate}</h2>
- {$adminDataSummary}
- </td>
- <td>&nbsp;</td>
- </tr>
- </tbody>
+ <tbody>
+ <tr>
+ <td>
+ <h2>{'DBStats_OtherTables'|translate}</h2>
+ {$adminDataSummary}
+ </td>
+ <td>&nbsp;</td>
+ </tr>
+ </tbody>
</table>
{literal}
-<script type="text/javascript">
-(function( $ ){
- $(document).ready(function() {
- $('.ajaxLoad').each(function() {
- var self = this;
- var action = $(this).attr('action');
-
- // build & execute AJAX request
- var ajaxRequest = new ajaxHelper();
- ajaxRequest.addParams({
- module: 'DBStats',
- action: action,
- viewDataTable: 'table'
- }, 'get');
- ajaxRequest.setCallback(
- function (data) {
- $('.loadingPiwik', self).remove();
- $(self).html(data);
- }
- );
- ajaxRequest.setFormat('html');
- ajaxRequest.send(false);
- });
- });
-})( jQuery );
-</script>
+ <script type="text/javascript">
+ (function ($) {
+ $(document).ready(function () {
+ $('.ajaxLoad').each(function () {
+ var self = this;
+ var action = $(this).attr('action');
+
+ // build & execute AJAX request
+ var ajaxRequest = new ajaxHelper();
+ ajaxRequest.addParams({
+ module: 'DBStats',
+ action: action,
+ viewDataTable: 'table'
+ }, 'get');
+ ajaxRequest.setCallback(
+ function (data) {
+ $('.loadingPiwik', self).remove();
+ $(self).html(data);
+ }
+ );
+ ajaxRequest.setFormat('html');
+ ajaxRequest.send(false);
+ });
+ });
+ })(jQuery);
+ </script>
{/literal}
{include file="CoreAdminHome/templates/footer.tpl"}