@@ -31,6 +31,9 @@ public function createCommand(): void
3131
3232 /**
3333 * restores a single backup of a specific package
34+ *
35+ * @param string $name The name of the backup you want to restore
36+ * @param bool $noConfirm If true, you dant have to confirm the restore action
3437 */
3538 public function restoreCommand (string $ name , bool $ noConfirm = false ): void
3639 {
@@ -53,7 +56,7 @@ public function restoreCommand(string $name, bool $noConfirm = false): void
5356 }
5457
5558 if ($ noConfirm === false ) {
56- $ 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 );
5760 }
5861
5962 if (!$ shouldRestore ) {
@@ -73,6 +76,9 @@ public function restoreCommand(string $name, bool $noConfirm = false): void
7376
7477 /**
7578 * lists all backups
79+ *
80+ * @param int $offset Offset
81+ * @param int $limit Number of backups shown
7682 */
7783 public function listCommand ($ offset = 0 , $ limit = 60 ): void
7884 {
@@ -89,13 +95,16 @@ public function listCommand($offset = 0, $limit = 60): void
8995
9096 /**
9197 * deletes backups
98+ *
99+ * @param string $name The name of the backup you want to delete
100+ * @param bool $noConfirm If true, you dant have to confirm the delete action
92101 */
93102 public function deleteCommand (string $ name , bool $ noConfirm = false ): void
94103 {
95104 $ confirmed = true ;
96105
97106 if (!$ noConfirm ) {
98- $ 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? ' );
99108 }
100109
101110 if (!$ confirmed ) {
@@ -114,6 +123,43 @@ public function deleteCommand(string $name, bool $noConfirm = false): void
114123 }
115124 }
116125
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+
117163 protected function outputError (string $ message ): void
118164 {
119165 $ this ->outputLine ('<error>failed</error> ' );
0 commit comments