public function DatabaseLogger::cleanup in Ultimate Cron 8.2
Cleans and purges data stored by this plugin.
Overrides PluginCleanupInterface::cleanup
File
- src/
Plugin/ ultimate_cron/ Logger/ DatabaseLogger.php, line 76
Class
- DatabaseLogger
- Database logger.
Namespace
Drupal\ultimate_cron\Plugin\ultimate_cron\LoggerCode
public function cleanup() {
$jobs = CronJob::loadMultiple();
$current = 1;
$max = 0;
$counter = 0;
$count_deleted = [];
foreach ($jobs as $job) {
if ($job
->getLoggerId() === $this
->getPluginId()) {
$max++;
}
}
foreach ($jobs as $job) {
if ($job
->getLoggerId() === $this
->getPluginId()) {
// Get the plugin through the job so it has the right configuration.
$counter = $job
->getPlugin('logger')
->cleanupJob($job);
$class = \Drupal::entityTypeManager()
->getDefinition('ultimate_cron_job')
->getClass();
if ($class::$currentJob) {
$class::$currentJob
->setProgress($current / $max);
$current++;
}
if ($counter) {
// Store number of deleted messages for each job.
$count_deleted[$job
->id()] = $counter;
}
}
}
if ($count_deleted) {
\Drupal::logger('database_logger')
->info('@count_entries log entries removed for @jobs_count jobs', array(
'@count_entries' => array_sum($count_deleted),
'@jobs_count' => count($count_deleted),
));
}
}