Ejemplo n.º 1
0
 /**
  * @param \Symfony\Component\Console\Input\InputInterface $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  * @return int|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->detectDbSettings($output);
     $query = $this->getOrAskForArgument('query', $input, $output, 'SQL Query');
     $query = $this->getEscapedSql($query);
     $exec = 'mysql ' . $this->getMysqlClientToolConnectionString() . " -e '" . $query . "'";
     if ($input->getOption('only-command')) {
         $output->writeln($exec);
     } else {
         Exec::run($exec, $commandOutput, $returnValue);
         $output->writeln($commandOutput);
         if ($returnValue > 0) {
             $output->writeln('<error>' . $commandOutput . '</error>');
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * get current working directory
  */
 public static function getCwd()
 {
     if (!Exec::allowed() || OperatingSystem::isWindows()) {
         return getcwd();
     }
     Exec::run('pwd', $folder);
     return $folder;
 }
Ejemplo n.º 3
0
 /**
  * @param array $execs
  * @param string $fileName
  * @param InputInterface $input
  * @param OutputInterface $output
  */
 private function runExecs(array $execs, $fileName, InputInterface $input, OutputInterface $output)
 {
     if ($input->getOption('only-command') && !$input->getOption('print-only-filename')) {
         foreach ($execs as $exec) {
             $output->writeln($exec);
         }
     } else {
         if (!$input->getOption('stdout') && !$input->getOption('only-command') && !$input->getOption('print-only-filename')) {
             $output->writeln('<comment>Start dumping database <info>' . $this->dbSettings['dbname'] . '</info> to file <info>' . $fileName . '</info>');
         }
         foreach ($execs as $exec) {
             $commandOutput = '';
             if ($input->getOption('stdout')) {
                 passthru($exec, $returnValue);
             } else {
                 Exec::run($exec, $commandOutput, $returnValue);
             }
             if ($returnValue > 0) {
                 $output->writeln('<error>' . $commandOutput . '</error>');
                 $output->writeln('<error>Return Code: ' . $returnValue . '. ABORTED.</error>');
                 return;
             }
         }
         if (!$input->getOption('stdout') && !$input->getOption('print-only-filename')) {
             $output->writeln('<info>Finished</info>');
         }
     }
     if ($input->getOption('print-only-filename')) {
         $output->writeln($fileName);
     }
 }
Ejemplo n.º 4
0
 /**
  * @param OutputInterface $output
  * @param string          $fileName
  * @param string          $exec
  *
  * @return void
  */
 protected function doImport(OutputInterface $output, $fileName, $exec)
 {
     $returnValue = null;
     $commandOutput = null;
     $output->writeln('<comment>Importing SQL dump <info>' . $fileName . '</info> to database <info>' . $this->dbSettings['dbname'] . '</info>');
     Exec::run($exec, $commandOutput, $returnValue);
     if ($returnValue != 0) {
         $output->writeln('<error>' . $commandOutput . '</error>');
     }
     $output->writeln('<info>Finished</info>');
 }