Piwik\Plugins\PrivacyManager\PrivacyManager::getPurgeEstimate PHP Метод

getPurgeEstimate() публичный статический Метод

The returned array maps table names with the number of rows that will be deleted. If the table name is mapped with -1, the table will be dropped.
public static getPurgeEstimate ( array $settings = null ) : array
$settings array The config options to use in the estimate. If null, the real options are used.
Результат array
    public static function getPurgeEstimate($settings = null)
    {
        if (is_null($settings)) {
            $settings = self::getPurgeDataSettings();
        }
        $result = array();
        if ($settings['delete_logs_enable']) {
            /** @var LogDataPurger $logDataPurger */
            $logDataPurger = StaticContainer::get('Piwik\\Plugins\\PrivacyManager\\LogDataPurger');
            $result = array_merge($result, $logDataPurger->getPurgeEstimate($settings['delete_logs_older_than']));
        }
        if ($settings['delete_reports_enable']) {
            $reportsPurger = ReportsPurger::make($settings, self::getAllMetricsToKeep());
            $result = array_merge($result, $reportsPurger->getPurgeEstimate());
        }
        return $result;
    }

Usage Example

Пример #1
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;
 }
All Usage Examples Of Piwik\Plugins\PrivacyManager\PrivacyManager::getPurgeEstimate