Example #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $file = $input->getArgument('sql-file');
     $filesystem = new Filesystem();
     if (!$filesystem->isFile($file)) {
         throw new FileNotFoundException("We could not find the file you wanted to send to the remote server");
     }
     $vars = $input->getArguments();
     $keyLocation = $vars['ssh-secret'];
     if (!$filesystem->isFile($keyLocation)) {
         $output->writeln(sprintf('<error>Oh NO! We couldn\'t find the private key located here: %s</error>', $keyLocation));
         $pattern = '/^~\\//i';
         if (preg_match($pattern, $keyLocation) === 1) {
             $output->writeln('<error>Maybe use the key absolute path?</error>');
         }
         $output->writeln('<error>We are going to bail and let you fix this. </error>');
         return;
     }
     $auth = ['key' => $vars['ssh-secret']];
     $output->writeln("Connecting to remote host");
     $remote = new Connection('remote', $vars['ssh-host'], $vars['ssh-user'], $auth);
     if ($remote->getGateway()) {
         $output->writeln("Connection established. Transferring file " . $file);
     }
     $fileName = $filesystem->name($file);
     $remoteFile = $fileName;
     $remote->put($file, $remoteFile);
     $output->writeln("File transfered. Importing into database");
     $mysqlCommandFormat = "mysql -u %s -p'%s' %s < %s";
     $mysqlImportCommand = sprintf($mysqlCommandFormat, $vars['db-user'], $vars['db-password'], $vars['db-name'], $remoteFile);
     $mysqlDropDbCommand = sprintf("mysql -u %s -p'%s' -e 'DROP DATABASE %s;'", $vars['db-user'], $vars['db-password'], $vars['db-name']);
     $mysqlCreateDbCommand = sprintf("mysql -u %s -p'%s' -e 'CREATE DATABASE %s;'", $vars['db-user'], $vars['db-password'], $vars['db-name']);
     $remote->run($mysqlDropDbCommand, function ($line) use($output) {
     });
     $remote->run($mysqlCreateDbCommand, function ($line) use($output) {
     });
     $remote->run($mysqlImportCommand, function ($line) use($output) {
         $output->writeln($line);
     });
     /*
      * Cleanup the remote machine
      */
     $remote->run('rm ' . $remoteFile, function ($line) {
     });
     $output->writeln("Remote Importer is ALL DONE !!!");
 }
Example #2
0
 /**
  * Set the output implementation.
  *
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  * @return void 
  * @static 
  */
 public static function setOutput($output)
 {
     \Illuminate\Remote\Connection::setOutput($output);
 }
Example #3
0
 public function __construct($name, Credential $remote)
 {
     parent::__construct($name, $remote->host(), $remote->user(), ['key' => $remote->secret()]);
     $this->remote = $remote;
 }
Example #4
0
 /**
  * Set the output implementation on the connection.
  *
  * @param  \Illuminate\Remote\Connection  $connection
  * @return void
  */
 protected function setOutput(Connection $connection)
 {
     $output = php_sapi_name() == 'cli' ? new ConsoleOutput() : new NullOutput();
     $connection->setOutput($output);
 }