예제 #1
0
 /**
  * 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 = new View('@DBStats/index');
     $this->setBasicVariablesView($view);
     $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) = API::getInstance()->getGeneralInformation();
     $view->siteCount = MetricsFormatter::getPrettyNumber($siteCount);
     $view->userCount = MetricsFormatter::getPrettyNumber($userCount);
     $view->totalSpaceUsed = MetricsFormatter::getPrettySizeFromBytes($totalSpaceUsed);
     return $view->render();
 }
예제 #2
0
 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 = new MySQLMetadataProvider();
     $tableStatuses = $metadataProvider->getAllTablesStatus();
     $totalBytes = 0;
     foreach ($tableStatuses as $status) {
         $totalBytes += $status['Data_length'] + $status['Index_length'];
     }
     $result = array('currentSize' => MetricsFormatter::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'] = MetricsFormatter::getPrettySizeFromBytes($totalAfterPurge);
         $result['spaceSaved'] = MetricsFormatter::getPrettySizeFromBytes($totalBytes - $totalAfterPurge);
     }
     return $result;
 }