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 = ExecTrait::programExists('wget'); } $destination_tmp = drush_tempnam('download_file'); if ($use_wget) { $args = ['wget', '-q', '--timeout=30']; if ($user && $password) { $args = array_merge($args, ["--user=$user", "--password=$password", '-O', $destination_tmp, $url]); } else { $args = array_merge($args, ['-O', $destination_tmp, $url]); } } else { $args = ['curl', '-s', '-L', '--connect-timeout 30']; if ($user && $password) { $args = array_merge($args, ['--user', "$user:$password", '-o', $destination_tmp, $url]); } else { $args = array_merge($args, ['-o', $destination_tmp, $url]); } } $process = Drush::process($args); $process->mustRun(); 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; } }