Issue #3412542 by Eduardo Morales Alberti: Backups are deleted due a bad contion on the limit
Merged
requested to merge issue/acquia_cloud_backup_manager-3412542:3412542-backups-are-deleted into 1.0.x
4 unresolved threads
Closes #3412542
Merge request reports
Activity
198 198 break; 199 199 200 200 case 'number_to_keep': 201 $elements_to_delete = []; 202 $number_of_backups = count($backup_list); 203 204 if ($number_of_backups > $limit) { 205 $elements_to_delete = array_slice($backup_list, 0, -$limit, TRUE); 201 // Do not delete backups if the count of backups is minus than changed this line in version 2 of the diff
200 200 case 'number_to_keep': 201 $elements_to_delete = []; 202 $number_of_backups = count($backup_list); 203 204 if ($number_of_backups > $limit) { 205 $elements_to_delete = array_slice($backup_list, 0, -$limit, TRUE); 201 // Do not delete backups if the count of backups is minus than 202 // the limit. 203 if ($limit < 1 || count($backup_list) < $limit) { 204 return []; 206 205 } 207 foreach ($elements_to_delete as $uuid => $backup_time) { 208 $backups_to_delete[$uuid]['date'] = date(\DateTimeInterface::ATOM, $backup_time); 206 207 // Calculate the number of backups to delete. 208 $number_backups_to_delete = count($backup_list) - $limit; changed this line in version 3 of the diff
198 198 break; 199 199 200 200 case 'number_to_keep': 201 $elements_to_delete = []; 202 $number_of_backups = count($backup_list); 203 204 if ($number_of_backups > $limit) { 205 $elements_to_delete = array_slice($backup_list, 0, -$limit, TRUE); 201 // Do not delete backups if the count of backups is minus than 202 // the limit. 203 if ($limit < 1 || count($backup_list) < $limit) { changed this line in version 2 of the diff
202 $number_of_backups = count($backup_list); 203 204 if ($number_of_backups > $limit) { 205 $elements_to_delete = array_slice($backup_list, 0, -$limit, TRUE); 201 // Do not delete backups if the count of backups is minus than 202 // the limit. 203 if ($limit < 1 || count($backup_list) < $limit) { 204 return []; 206 205 } 207 foreach ($elements_to_delete as $uuid => $backup_time) { 208 $backups_to_delete[$uuid]['date'] = date(\DateTimeInterface::ATOM, $backup_time); 206 207 // Calculate the number of backups to delete. 208 $number_backups_to_delete = count($backup_list) - $limit; 209 210 $count = 0; I would use
$backups_to_delete
for the loop to avoid creating another variable ($count
) for readability reasons. Also, let's break early:// Calculate the number of backups to delete. $number_backups_to_delete = count($backup_list) - $limit; foreach ($backup_list as $uuid => $backup_time) { if ($number_backups_to_delete === 0) { break; } $backups_to_delete[$uuid]['date'] = date(\DateTimeInterface::ATOM, $backup_time); $number_backups_to_delete--; }
changed this line in version 3 of the diff
Please register or sign in to reply