MDL-29262 backup: new setting to control the ttl of backup logs

Add one new backup setting, moving from the general CFG->loglifetime,
to be able to delete backup logged information often.
This commit is contained in:
Eloy Lafuente (stronk7) 2012-04-22 21:16:54 +02:00
parent ead4f180a0
commit 14e2704ad4
4 changed files with 36 additions and 9 deletions

View file

@ -113,17 +113,18 @@ function cron_run() {
}
// Delete old backup_controllers and logs
if (!empty($CFG->loglifetime)) { // value in days
$loglifetime = $timenow - ($CFG->loglifetime * 3600 * 24);
// Delete child records from backup_logs
// Delete old backup_controllers and logs.
$loglifetime = get_config('backup', 'loglifetime');
if (!empty($loglifetime)) { // Value in days.
$loglifetime = $timenow - ($loglifetime * 3600 * 24);
// Delete child records from backup_logs.
$DB->execute("DELETE FROM {backup_logs}
WHERE EXISTS (
SELECT 'x'
FROM {backup_controllers} bc
WHERE bc.backupid = {backup_logs}.backupid
AND bc.timecreated < ?)", array($loglifetime));
// Delete records from backup_controllers
// Delete records from backup_controllers.
$DB->execute("DELETE FROM {backup_controllers}
WHERE timecreated < ?", array($loglifetime));
mtrace(" Deleted old backup records");