File tree Expand file tree Collapse file tree 3 files changed +66
-5
lines changed
Expand file tree Collapse file tree 3 files changed +66
-5
lines changed Original file line number Diff line number Diff line change 55namespace Itiden \Backup \Console \Commands ;
66
77use Illuminate \Console \Command ;
8- use Illuminate \Contracts \Console \PromptsForMissingInput ;
98use Itiden \Backup \Contracts \Repositories \BackupRepository ;
109use Itiden \Backup \DataTransferObjects \BackupDto ;
1110use Itiden \Backup \Facades \Restorer ;
1514/**
1615 * Restore content from a directory / backup
1716 */
18- class RestoreCommand extends Command implements PromptsForMissingInput
17+ final class RestoreCommand extends Command
1918{
2019 protected $ signature = 'statamic:backup:restore {--path=} {--force} ' ;
2120
@@ -31,15 +30,17 @@ public function handle(BackupRepository $repo)
3130 scroll: 10 ,
3231 options: $ repo ->all ()->flatMap (
3332 fn (BackupDto $ backup ) => [$ backup ->path => $ backup ->path ]
34- )
33+ ),
34+ required: true
3535 )),
3636 };
3737
3838 if (
3939 $ this ->option ('force ' )
4040 || confirm (
4141 label: "Are you sure you want to restore your content? " ,
42- hint: "This will overwrite your current content with state from {$ backup ->created_at ->format ('Y-m-d H:i:s ' )}"
42+ hint: "This will overwrite your current content with state from {$ backup ->created_at ->format ('Y-m-d H:i:s ' )}" ,
43+ required: true
4344 )
4445 ) {
4546 spin (fn () => Restorer::restore ($ backup ), 'Restoring backup ' );
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ use Illuminate \Support \Facades \Storage ;
4+ use Itiden \Backup \Contracts \Repositories \BackupRepository ;
5+ use Itiden \Backup \Facades \Backuper ;
6+
7+ use function Pest \Laravel \artisan ;
8+
9+ uses ()->group ('restore-command ' );
10+
11+ it ('shows all available backups ' , function () {
12+ app (BackupRepository::class)->empty ();
13+
14+ Backuper::backup ();
15+
16+ $ backups = app (BackupRepository::class)->all ();
17+
18+ artisan ('statamic:backup:restore ' )
19+ ->expectsQuestion (
20+ question: 'Which backup do you want to restore to? ' ,
21+ answer: $ backups ->first ()->path
22+ )
23+ ->expectsConfirmation ('Are you sure you want to restore your content? ' )
24+ ->assertFailed ();
25+ });
26+
27+ it ('can restore from a specific path ' , function () {
28+ app (BackupRepository::class)->empty ();
29+
30+ $ backup = Backuper::backup ();
31+
32+ artisan ('statamic:backup:restore ' , ['--path ' => Storage::disk (config ('backup.destination.disk ' ))->path ($ backup ->path )])
33+ ->expectsConfirmation ('Are you sure you want to restore your content? ' )
34+ ->assertFailed ();
35+ });
Original file line number Diff line number Diff line change 4343 Assets::class,
4444]);
4545
46- test ('can skip a pipe ' , function () {
46+ test ('can skip a pipe with users ' , function () {
4747 /** @var Users::class $pipe */
4848 $ pipe = app ()->make (Users::class);
4949
6363
6464 $ zipper ->close ();
6565});
66+
67+ test ('can skip a pipe with content ' , function () {
68+ /** @var Users::class $pipe */
69+ $ pipe = app ()->make (Content::class);
70+
71+ $ callable = function ($ z ) {
72+ return $ z ;
73+ };
74+
75+ File::copyDirectory (config ('backup.content_path ' ), config ('backup.content_path ' ) . '_backup ' );
76+ File::deleteDirectory (config ('backup.content_path ' ));
77+
78+ $ zipper = Zipper::open (config ('backup.temp_path ' ) . '/backup.zip ' );
79+
80+ $ pipe ->backup (zip: $ zipper , next: $ callable );
81+
82+
83+ expect ($ zipper ->getMeta ())->toHaveKey (Content::class);
84+ expect ($ zipper ->getMeta ()[Content::class])->toHaveKey ('skipped ' , 'Content directory didn \'t exist, is it configured correctly? ' );
85+
86+ $ zipper ->close ();
87+
88+ File::copyDirectory (config ('backup.content_path ' ) . '_backup ' , config ('backup.content_path ' ));
89+ File::deleteDirectory (config ('backup.content_path ' ) . '_backup ' );
90+ });
You can’t perform that action at this time.
0 commit comments