function task_sn_backupcleaner($task) {
global $mybb, $lang, $config;
$lang->load('sn_backupcleaner');
if(!defined('MYBB_ADMIN_DIR'))
{
if(!isset($config['admin_dir']))
{
$config['admin_dir'] = "admin";
}
define('MYBB_ADMIN_DIR', MYBB_ROOT.$config['admin_dir']);
}
// Check if folder is writable
if(!is_writable(MYBB_ADMIN_DIR."/backups"))
{
add_task_log($task, $lang->sn_backupcleaner_cantwrite);
}
$ba_files = MYBB_ADMIN_DIR."/backups/*.sql.gz";
$backup_file = glob($ba_files);
$ba_count = 0;
$ba_min = $mybb->settings['backupcleaner_keep'];
$ba_age_max = $mybb->settings['backupcleaner_delay'];
// delete every file in the array which is >= $ba_age_max days and keep files = $ba_min
if(count($backup_file) > $ba_min)
{
foreach($backup_file as $ba)
{
if(is_file($ba) && time() - filectime($ba) >= $ba_age_max*24*60*60)
{
$ba_count++;
unlink($ba);
}
}
add_task_log($task, $lang->sprintf($lang->sn_backupcleaner_ran, $ba_count));
}
}