/**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $this->config->load($this->argument('conversion'));
     $command = $this->commandStringBuilder->build($this->config);
     $outputPath = $this->config->outputPath();
     if (file_exists($outputPath)) {
         @unlink($outputPath);
     }
     if ($this->config->debug()) {
         $this->output->block('[DEBUG] Running command: ' . $command);
     }
     if (empty(shell_exec("which mysqldump"))) {
         throw new MissingDependency('mysqldump is not available');
     }
     if (is_executable($this->config->converterExecutable()) === false) {
         $process = new Process('chmod +x ' . $this->config->converterExecutable());
         $process->run();
     }
     $process = new Process($command);
     $outputFilter = $this->outputFilter;
     $process->mustRun(function ($type, $output) use($outputFilter) {
         // some things are expected, so we'll hide that
         // to avoid misleading warnings/errors
         $output = $outputFilter->filter($output);
         if ($output != null) {
             if (Process::ERR === $type) {
                 echo 'ERR > ' . $output;
             } else {
                 echo 'OUT > ' . $output;
             }
         }
     });
     $this->output->success('Dump created at ' . $outputPath);
 }
 /**
  * Build the command string from the configuration
  *
  * @return string
  */
 public function build(ConversionConfig $config)
 {
     $command = [$config->converterExecutable()];
     $command[] = '-h ' . $config->host();
     $command[] = '-u ' . $config->username();
     $command[] = '-p' . $config->password();
     $command[] = '-P ' . $config->port();
     $command[] = $config->database();
     if ($config->hasConfiguredTables()) {
         $command[] = implode(' ', $config->tables());
     }
     // append any additional mysqldump options
     foreach ($config->extraOptions() as $option => $value) {
         // determine if it's an option or a key/value pair
         if (is_numeric($option)) {
             $command[] = $value;
         } else {
             $command[] = $option . '="' . addslashes($value) . '"';
         }
     }
     $command[] = '| sqlite3 ' . $config->outputPath();
     return implode(' ', $command);
 }