<?php

// LOADED FROM: core.php, periodic_cleanup().
// INCOMING VARIABLES: $backup_age_limit = 172800, $die_on_fail = true
$max_site_log_size = pb_backupbuddy::$options['max_site_log_size'] * 1024 * 1024;
// in bytes.
pb_backupbuddy::status('message', 'Starting cleanup procedure for BackupBuddy v' . pb_backupbuddy::settings('version') . '.');
if (!isset(pb_backupbuddy::$options)) {
    pb_backupbuddy::load();
}
// Validate that all internal schedules are properly registered in the WordPress cron
backupbuddy_core::validateSchedules();
// Clean up any old rollback undo files hanging around.
$files = (array) glob(ABSPATH . 'backupbuddy_rollback*');
foreach ($files as $file) {
    $file_stats = stat($file);
    if (time() - $file_stats['mtime'] > backupbuddy_constants::CLEANUP_MAX_STATUS_LOG_AGE) {
        @unlink($file);
    }
}
// If temp directory exists (should only be transient but just in case it is hanging around) make sure it's secured. BB will try to delete this directory but if it can't it will at least be checked to be secure.
if (file_exists(backupbuddy_core::getTempDirectory())) {
    pb_backupbuddy::anti_directory_browsing(backupbuddy_core::getTempDirectory(), $die = false);
}
// Clean up any old cron file transfer locks.
$files = (array) glob(backupbuddy_core::getLogDirectory() . 'cronSend-*');
foreach ($files as $file) {
    $file_stats = stat($file);
    if (time() - $file_stats['mtime'] > backupbuddy_constants::CLEANUP_MAX_STATUS_LOG_AGE) {
        @unlink($file);
    }