@@ -56,7 +56,7 @@ public function restoreCommand(string $name, bool $noConfirm = false): void
5656 }
5757
5858 if ($ noConfirm === false ) {
59- $ shouldRestore = $ this ->output ->askConfirmation ('Are you sure you want to restore this Backup? ' , false );
59+ $ shouldRestore = $ this ->output ->askConfirmation ('Are you sure you want to restore this Backup? ' , false );
6060 }
6161
6262 if (!$ shouldRestore ) {
@@ -104,7 +104,7 @@ public function deleteCommand(string $name, bool $noConfirm = false): void
104104 $ confirmed = true ;
105105
106106 if (!$ noConfirm ) {
107- $ confirmed = $ this ->output ->askConfirmation ('Are you sure you want to delete this backup? ' );
107+ $ confirmed = $ this ->output ->askConfirmation ('Are you sure you want to delete this backup? ' );
108108 }
109109
110110 if (!$ confirmed ) {
@@ -123,6 +123,43 @@ public function deleteCommand(string $name, bool $noConfirm = false): void
123123 }
124124 }
125125
126+ /**
127+ * deletes all backups, but can keep X latest backups
128+ *
129+ * @param int $keep keep the latest X backups
130+ * @param bool $noConfirm If true, you dant have to confirm the delete action
131+ */
132+ public function pruneCommand (int $ keep = 0 , bool $ noConfirm = false ): void
133+ {
134+ $ confirmed = true ;
135+
136+ if (!$ noConfirm ) {
137+ $ question = ($ keep > 0 ? ', except the latest ' .$ keep .' backups ' : '' );
138+ $ question = 'Are you sure you want to delete all backups ' .$ question .'? ' ;
139+ $ confirmed = $ this ->output ->askConfirmation ($ question );
140+ }
141+
142+ if (!$ confirmed ) {
143+ $ this ->outputLine ();
144+ $ this ->outputLine ('<error>Canceled by user</error> ' );
145+ $ this ->quit ();
146+ }
147+
148+ $ backupCount = $ this ->backupService ->getCount ();
149+ $ backups = $ this ->backupService ->getBackups ($ keep , $ backupCount );
150+
151+ $ this ->output ('Deleting ' .($ backupCount - $ keep <= 0 ? '0 ' : $ backupCount - $ keep ).' backups... ' );
152+
153+ try {
154+ foreach ($ backups as $ backup ) {
155+ $ this ->backupService ->deleteBackup ($ backup ['name ' ]);
156+ }
157+ $ this ->outputLine ('<success>success</success> ' );
158+ } catch (\Exception $ e ) {
159+ $ this ->outputError ($ e ->getMessage ());
160+ }
161+ }
162+
126163 protected function outputError (string $ message ): void
127164 {
128165 $ this ->outputLine ('<error>failed</error> ' );
0 commit comments