Пример #1
0
 /**
  * Purge backups.
  *
  * The function purges all failed and unfinished backups if there are backups more recent then them.
  * Deletes local files and Google Drive files if there are more than the wanted number.
  * If both the local and Drive files have been removed then the log file is deleted as well as
  * all accounts of that backup.
  */
 private function purge_backups()
 {
     $count_local = 0;
     $count_drive = 0;
     $found = false;
     foreach (array_reverse($this->options['backup_list']) as $key => $backup) {
         if (1 == $backup['status']) {
             if (!empty($backup['file_path'])) {
                 $count_local++;
             }
             if (!empty($backup['drive_id'])) {
                 $count_drive++;
             }
             $found = true;
         } elseif ($found) {
             unset($this->options['backup_list'][$key]);
             if (!empty($backup['file_path'])) {
                 delete_path($backup['file_path']);
             }
             if (is_gdocs($this->gdocs) && !empty($backup['drive_id'])) {
                 $this->gdocs->delete_resource($backup['drive_id']);
             }
             delete_path($backup['log']);
             continue;
         }
         if ($count_local > $this->options['local_number']) {
             delete_path($this->options['backup_list'][$key]['file_path']);
             $this->options['backup_list'][$key]['file_path'] = '';
         }
         if (is_gdocs($this->gdocs) && $count_drive > $this->options['drive_number']) {
             $this->gdocs->delete_resource($this->options['backup_list'][$key]['drive_id']);
             $this->options['backup_list'][$key]['drive_id'] = '';
         }
         if (empty($this->options['backup_list'][$key]['file_path']) && empty($this->options['backup_list'][$key]['drive_id'])) {
             delete_path($this->options['backup_list'][$key]['log']);
             unset($this->options['backup_list'][$key]);
         }
     }
 }