input()->getOption('http-sync'); if (!empty($sql_dump_download_url)) { $user = $commandData->input()->getOption('http-sync-user'); $password = $commandData->input()->getOption('http-sync-password'); $source_dump_file = $this->downloadFile($sql_dump_download_url, $user, $password); $commandData->input()->setOption('target-dump', $source_dump_file); $commandData->input()->setOption('no-dump', true); $commandData->input()->setOption('no-sync', true); } } /** * Downloads a file. * * Optionally uses user authentication, using either wget or curl, as available. */ protected function downloadFile($url, $user = false, $password = false, $destination = false, $overwrite = true) { static $use_wget; if ($use_wget === null) { $use_wget = drush_shell_exec('which wget'); } $destination_tmp = drush_tempnam('download_file'); if ($use_wget) { if ($user && $password) { drush_shell_exec("wget -q --timeout=30 --user=%s --password=%s -O %s %s", $user, $password, $destination_tmp, $url); } else { drush_shell_exec("wget -q --timeout=30 -O %s %s", $destination_tmp, $url); } } else { if ($user && $password) { drush_shell_exec("curl -s -L --connect-timeout 30 --user %s:%s -o %s %s", $user, $password, $destination_tmp, $url); } else { drush_shell_exec("curl -s -L --connect-timeout 30 -o %s %s", $destination_tmp, $url); } } if (!Drush::simulate()) { if (!drush_file_not_empty($destination_tmp) && $file = @file_get_contents($url)) { @file_put_contents($destination_tmp, $file); } if (!drush_file_not_empty($destination_tmp)) { // Download failed. throw new \Exception(dt("The URL !url could not be downloaded.", ['!url' => $url])); } } if ($destination) { $fs = new Filesystem(); $fs->rename($destination_tmp, $destination, $overwrite); return $destination; } return $destination_tmp; } }