@@ -67,12 +67,20 @@ public function __construct()
6767 *
6868 * @param string $siteName
6969 * The Drupal site name.
70+ * @option db
71+ * Provide a path to a database dump to be used instead of downloading the latest dump.
7072 */
71- public function databaseRefreshDdev (string $ siteName = 'default ' ): Result
73+ public function databaseRefreshDdev (string $ siteName = 'default ' , array $ options = [ ' db ' => '' ] ): Result
7274 {
7375 $ this ->io ()->title ('DDEV database refresh. ' );
7476
75- $ dbPath = $ this ->databaseDownload ($ siteName );
77+ ['db ' => $ dbPath ] = $ options ;
78+ // Track whether a database path was provided by the user or not.
79+ $ dbPathProvidedByUser = $ dbPath !== '' ;
80+
81+ if (!$ dbPathProvidedByUser ) {
82+ $ dbPath = $ this ->databaseDownload ($ siteName );
83+ }
7684
7785 $ this ->io ()->section ("importing $ siteName database. " );
7886 $ this ->say ("Importing $ dbPath " );
@@ -82,8 +90,11 @@ public function databaseRefreshDdev(string $siteName = 'default'): Result
8290 ->option ('file ' , $ dbPath )
8391 ->run ();
8492
85- $ this ->say ("Deleting $ dbPath " );
86- $ this ->taskExec ('rm ' )->args ($ dbPath )->run ();
93+ // If a database was downloaded as part of this process, delete it.
94+ if (!$ dbPathProvidedByUser ) {
95+ $ this ->deleteDatabase ($ dbPath );
96+ }
97+
8798 return $ this ->drushDeployWith (
8899 localEnvironmentType: LocalDevEnvironmentTypes::DDEV ,
89100 siteDir: $ siteName ,
@@ -95,12 +106,20 @@ public function databaseRefreshDdev(string $siteName = 'default'): Result
95106 *
96107 * @param string $siteName
97108 * The Drupal site name.
109+ * @option db
110+ * Provide a path to a database dump to be used instead of downloading the latest dump.
98111 */
99- public function databaseRefreshLando (string $ siteName = 'default ' ): Result
112+ public function databaseRefreshLando (string $ siteName = 'default ' , array $ options = [ ' db ' => '' ] ): Result
100113 {
101114 $ this ->io ()->title ('lando database refresh. ' );
102115
103- $ dbPath = $ this ->databaseDownload ($ siteName );
116+ ['db ' => $ dbPath ] = $ options ;
117+ // Track whether a database path was provided by the user or not.
118+ $ dbPathProvidedByUser = $ dbPath !== '' ;
119+
120+ if (!$ dbPathProvidedByUser ) {
121+ $ dbPath = $ this ->databaseDownload ($ siteName );
122+ }
104123
105124 $ this ->io ()->section ("importing $ siteName database. " );
106125 $ this ->say ("Importing $ dbPath " );
@@ -112,8 +131,11 @@ public function databaseRefreshLando(string $siteName = 'default'): Result
112131 ->arg ($ hostOption )
113132 ->run ();
114133
115- $ this ->say ("Deleting $ dbPath " );
116- $ this ->taskExec ('rm ' )->args ($ dbPath )->run ();
134+ // If a database was downloaded as part of this process, delete it.
135+ if (!$ dbPathProvidedByUser ) {
136+ $ this ->deleteDatabase ($ dbPath );
137+ }
138+
117139 return $ this ->drushDeployWith (
118140 localEnvironmentType: LocalDevEnvironmentTypes::LANDO ,
119141 siteDir: $ siteName ,
@@ -242,6 +264,7 @@ protected function devRefreshDrupal(
242264 LocalDevEnvironmentTypes $ environmentType ,
243265 string $ siteName = 'default ' ,
244266 bool $ startLocalEnv = false ,
267+ string $ databasePath = '' ,
245268 ): Result {
246269 $ this ->io ()->title ('development environment refresh. 🦄✨ ' );
247270 $ result = $ this ->taskComposerInstall ()->run ();
@@ -258,10 +281,11 @@ protected function devRefreshDrupal(
258281 $ result = $ this ->taskExec ("composer robo theme:build $ siteName " )
259282 ->run ();
260283 $ result = $ this ->frontendDevEnableDrupal ($ siteName , ['yes ' => true ]);
284+
261285 if ($ environmentType == LocalDevEnvironmentTypes::LANDO ) {
262- $ result = $ this ->databaseRefreshLando ($ siteName );
286+ $ result = $ this ->databaseRefreshLando (siteName: $ siteName, options: [ ' db ' => $ databasePath ] );
263287 } elseif ($ environmentType == LocalDevEnvironmentTypes::DDEV ) {
264- $ result = $ this ->databaseRefreshDdev ($ siteName );
288+ $ result = $ this ->databaseRefreshDdev (siteName: $ siteName, options: [ ' db ' => $ databasePath ] );
265289 }
266290 return $ this ->drupalLoginLink ($ environmentType ->value , $ siteName );
267291 }
0 commit comments