22
33namespace DivineOmega \FileSync \FileSyncStrategies ;
44
5+ use DivineOmega \CliProgressBar \ProgressBar ;
56use DivineOmega \FileSync \FileListing \FileListing ;
67use DivineOmega \FileSync \FileListing \FileListingFactory ;
78use DivineOmega \FileSync \FileListing \TransferAction ;
@@ -28,10 +29,26 @@ public function withProgressBar(): self
2829
2930 public function begin (): void
3031 {
31- $ transferActions = [];
32+ if ($ this ->showProgressBar ) {
33+ $ maxProgress = 1 ;
34+ $ progressBar = new ProgressBar ();
35+ $ progressBar ->setMaxProgress (1 );
36+ $ progressBar ->setMessage ('Getting file listings... ' );
37+ $ progressBar ->display ();
38+ }
3239
3340 $ fileListings = FileListingFactory::createFromFilesystems ($ this ->filesystems );
3441
42+ if ($ this ->showProgressBar ) {
43+ $ progressBar ->advance ();
44+ $ maxProgress += count ($ fileListings );
45+ $ progressBar ->setMaxProgress ($ maxProgress );
46+ $ progressBar ->setMessage ('Determining differences... ' );
47+ $ progressBar ->display ();
48+ }
49+
50+ $ transferActions = [];
51+
3552 foreach ($ fileListings as $ key => $ fileListing ) {
3653
3754 $ otherFileListings = $ fileListings ;
@@ -50,10 +67,31 @@ public function begin(): void
5067 $ transferActions = array_merge ($ transferActions , $ newTransferActions );
5168
5269 }
70+
71+ if ($ this ->showProgressBar ) {
72+ $ progressBar ->advance ();
73+ $ progressBar ->display ();
74+ }
75+ }
76+
77+ if ($ this ->showProgressBar ) {
78+ $ maxProgress += count ($ transferActions );
79+ $ progressBar ->setMaxProgress ($ maxProgress );
80+ $ progressBar ->setMessage ('Transferring files... ' );
81+ $ progressBar ->display ();
5382 }
5483
5584 foreach ($ transferActions as $ transferAction ) {
5685 $ transferAction ->transfer ();
86+
87+ if ($ this ->showProgressBar ) {
88+ $ progressBar ->advance ();
89+ $ progressBar ->display ();
90+ }
91+ }
92+
93+ if ($ this ->showProgressBar ) {
94+ $ progressBar ->complete ();
5795 }
5896 }
5997}
0 commit comments