@@ -90,6 +90,11 @@ protected function execute(InputInterface $input, OutputInterface $output) {
9090 throw new SiteCommandException ('Please specify a file to import the dump from ' );
9191 }
9292
93+ // If the dump is on s3, download it locally.
94+ if (substr ($ this ->filename , 0 , 5 ) == 's3:// ' ) {
95+ $ this ->filename = $ this ->s3_download ($ this ->filename );
96+ }
97+
9398 // Check if the file exits.
9499 if (!$ this ->is_absolute_path ($ this ->filename )) {
95100 $ filename = realpath (getcwd () . trim ($ this ->filename , '. ' ));
@@ -196,6 +201,7 @@ protected function execute(InputInterface $input, OutputInterface $output) {
196201 $ this ->filename = '/tmp/ ' . $ baseNameSql ;
197202 break ;
198203 }
204+
199205 if (is_null ($ input ->getOption ('db-name ' ))) {
200206 $ input ->setOption ('db-name ' , $ this ->siteName );
201207 }
@@ -228,4 +234,36 @@ protected function execute(InputInterface $input, OutputInterface $output) {
228234 }
229235
230236 }
237+
238+ /**
239+ * Downloads the dump from s3 bucket.
240+ *
241+ * @param $filename
242+ *
243+ * @return string The absolute path for the dump.
244+ *
245+ * @throws SiteCommandException
246+ */
247+ protected function s3_download ($ filename ) {
248+ $ tmp_folder = '/tmp/ ' ;
249+ $ shellProcess = $ this ->getShellProcess ();
250+
251+ // First get the contents of the file to know which dump to use.
252+ $ command = sprintf (
253+ 'cd %s && ' .
254+ 's3cmd --force get %s ' ,
255+ $ tmp_folder ,
256+ $ filename
257+ );
258+
259+ if ($ shellProcess ->exec ($ command , TRUE )) {
260+ $ this ->io ->writeln ($ shellProcess ->getOutput ());
261+ }
262+ else {
263+ throw new SiteCommandException ($ shellProcess ->getOutput ());
264+ }
265+
266+ return $ tmp_folder . basename ($ this ->filename );
267+ }
268+
231269}
0 commit comments