@@ -66,6 +66,28 @@ public function __construct(
6666 parent ::__construct ($ this ->localMachineHelper , $ this ->datastoreCloud , $ this ->datastoreAcli , $ this ->cloudCredentials , $ this ->telemetryHelper , $ this ->projectDir , $ this ->cloudApiClientService , $ this ->sshHelper , $ this ->sshDir , $ logger , $ this ->selfUpdateManager );
6767 }
6868
69+ /**
70+ * Get the backup download URL.
71+ * This is primarily used for testing purposes.
72+ */
73+ public function getBackupDownloadUrl (): ?UriInterface
74+ {
75+ return $ this ->backupDownloadUrl ?? null ;
76+ }
77+
78+ /**
79+ * Set the backup download URL.
80+ * This is primarily used for testing purposes.
81+ */
82+ public function setBackupDownloadUrl (string |UriInterface $ url ): void
83+ {
84+ if (is_string ($ url )) {
85+ $ this ->backupDownloadUrl = new \GuzzleHttp \Psr7 \Uri ($ url );
86+ } else {
87+ $ this ->backupDownloadUrl = $ url ;
88+ }
89+ }
90+
6991 /**
7092 * @see https://github.com/drush-ops/drush/blob/c21a5a24a295cc0513bfdecead6f87f1a2cf91a2/src/Sql/SqlMysql.php#L168
7193 * @return string[]
@@ -404,6 +426,28 @@ private function validateGzipFile(string $localFilepath): void
404426 }
405427 }
406428
429+ public static function displayDownloadProgress (mixed $ totalBytes , mixed $ downloadedBytes , mixed &$ progress , OutputInterface $ output ): void
430+ {
431+ if ($ totalBytes > 0 && is_null ($ progress )) {
432+ $ progress = new \Symfony \Component \Console \Helper \ProgressBar ($ output , $ totalBytes );
433+ $ progress ->setFormat (' %current%/%max% [%bar%] %percent:3s%% ' );
434+ $ progress ->setProgressCharacter ('💧 ' );
435+ $ progress ->setOverwrite (true );
436+ $ progress ->start ();
437+ }
438+
439+ if (!is_null ($ progress )) {
440+ if ($ totalBytes === $ downloadedBytes && $ progress ->getProgressPercent () !== 1.0 ) {
441+ $ progress ->finish ();
442+ if ($ output instanceof \Symfony \Component \Console \Output \ConsoleSectionOutput) {
443+ $ output ->clear ();
444+ }
445+ return ;
446+ }
447+ $ progress ->setProgress ($ downloadedBytes );
448+ }
449+ }
450+
407451 /**
408452 * Create an on-demand backup and wait for it to become available.
409453 */
0 commit comments