/** * 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::checkUserHasSuperUserAccess(); $view = new View('@DBStats/index'); $this->setBasicVariablesView($view); $view->databaseUsageSummary = $this->renderReport('getDatabaseUsageSummary'); $view->trackerDataSummary = $this->renderReport('getTrackerDataSummary'); $view->metricDataSummary = $this->renderReport('getMetricDataSummary'); $view->reportDataSummary = $this->renderReport('getReportDataSummary'); $view->adminDataSummary = $this->renderReport('getAdminDataSummary'); list($siteCount, $userCount, $totalSpaceUsed) = API::getInstance()->getGeneralInformation(); $formatter = new Formatter(); $view->siteCount = $formatter->getPrettyNumber($siteCount); $view->userCount = $formatter->getPrettyNumber($userCount); $view->totalSpaceUsed = $formatter->getPrettySizeFromBytes($totalSpaceUsed); return $view->render(); }
protected function getDeleteDBSizeEstimate($getSettingsFromQuery = false, $forceEstimate = false) { $this->checkDataPurgeAdminSettingsIsEnabled(); // get the purging settings & create two purger instances if ($getSettingsFromQuery) { $settings = $this->getPurgeSettingsFromRequest(); } else { $settings = PrivacyManager::getPurgeDataSettings(); } $doDatabaseSizeEstimate = PiwikConfig::getInstance()->Deletelogs['enable_auto_database_size_estimate']; // determine the DB size & purged DB size $metadataProvider = StaticContainer::get('Piwik\\Plugins\\DBStats\\MySQLMetadataProvider'); $tableStatuses = $metadataProvider->getAllTablesStatus(); $totalBytes = 0; foreach ($tableStatuses as $status) { $totalBytes += $status['Data_length'] + $status['Index_length']; } $formatter = new Formatter(); $result = array('currentSize' => $formatter->getPrettySizeFromBytes($totalBytes)); // if the db size estimate feature is enabled, get the estimate if ($doDatabaseSizeEstimate || $forceEstimate == 1) { // maps tables whose data will be deleted with number of rows that will be deleted // if a value is -1, it means the table will be dropped. $deletedDataSummary = PrivacyManager::getPurgeEstimate($settings); $totalAfterPurge = $totalBytes; foreach ($tableStatuses as $status) { $tableName = $status['Name']; if (isset($deletedDataSummary[$tableName])) { $tableTotalBytes = $status['Data_length'] + $status['Index_length']; // if dropping the table if ($deletedDataSummary[$tableName] === ReportsPurger::DROP_TABLE) { $totalAfterPurge -= $tableTotalBytes; } else { if ($status['Rows'] > 0) { $totalAfterPurge -= $tableTotalBytes / $status['Rows'] * $deletedDataSummary[$tableName]; } } } } $result['sizeAfterPurge'] = $formatter->getPrettySizeFromBytes($totalAfterPurge); $result['spaceSaved'] = $formatter->getPrettySizeFromBytes($totalBytes - $totalAfterPurge); } return $result; }
/** * @dataProvider getPrettySizeFromBytesTestData */ public function test_getPrettySizeFromBytes_ReturnsCorrectResult($bytesSize, $unit, $expected) { $this->assertEquals($expected, $this->formatter->getPrettySizeFromBytes($bytesSize, $unit)); }
public function getPrettySizeFromBytes($size, $unit = null, $precision = 1) { $result = parent::getPrettySizeFromBytes($size, $unit, $precision); $result = $this->replaceSpaceWithNonBreakingSpace($result); return $result; }