Skip to content

Commit 1afee28

Browse files
rcerljenkofreekmurze
authored andcommitted
extract checks to separate function
1 parent e922279 commit 1afee28

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/Tasks/Cleanup/Strategies/DefaultStrategy.php

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,33 @@ protected function removeBackupsOlderThan(Carbon $endDate, BackupCollection $bac
9595

9696
protected function removeOldBackupsUntilUsingLessThanMaximumStorage(BackupCollection $backups)
9797
{
98-
if (! $oldest = $backups->oldest()) {
98+
if (! $this->shouldRemoveOldestBackup($backups)) {
9999
return;
100100
}
101101

102+
$backups->oldest()->delete();
103+
104+
$backups = $backups->filter(fn (Backup $backup) => $backup->exists());
105+
106+
$this->removeOldBackupsUntilUsingLessThanMaximumStorage($backups);
107+
}
108+
109+
protected function shouldRemoveOldestBackup(BackupCollection $backups): bool
110+
{
111+
if (! $backups->oldest()) {
112+
return false;
113+
}
114+
102115
$maximumSize = $this->config->get('backup.cleanup.default_strategy.delete_oldest_backups_when_using_more_megabytes_than');
103116

104-
if ($maximumSize === null || ($backups->size() + $this->newestBackup->sizeInBytes()) <= $maximumSize * 1024 * 1024) {
105-
return;
117+
if ($maximumSize === null) {
118+
return false;
106119
}
107-
$oldest->delete();
108120

109-
$backups = $backups->filter(fn (Backup $backup) => $backup->exists());
121+
if (($backups->size() + $this->newestBackup->sizeInBytes()) <= $maximumSize * 1024 * 1024) {
122+
return false;
123+
}
110124

111-
$this->removeOldBackupsUntilUsingLessThanMaximumStorage($backups);
125+
return true;
112126
}
113127
}

0 commit comments

Comments
 (0)