/**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return bool
  * @throws \Symfony\Component\Console\Exception\ExceptionInterface
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $configFile = $input->getArgument('config');
     if (!empty($configFile) && !file_exists($configFile)) {
         $configFileFallbackCandidate = getcwd() . DIRECTORY_SEPARATOR . str_replace('.yml', '', $configFile) . '.yml';
         $configFile = file_exists($configFileFallbackCandidate) ? $configFileFallbackCandidate : false;
     }
     $configFile = empty($configFile) ? getcwd() . DIRECTORY_SEPARATOR . 'setup.yml' : $configFile;
     if (!file_exists($configFile)) {
         $output->writeln('<error>Configuration file [' . $configFile . '] does not exist.</error>');
         return false;
     }
     $config = Yaml::parse($this->yamlHasher->hash(file_get_contents($configFile)));
     $helper = $this->getHelper('question');
     foreach ($config as $sectionTitle => $sectionConfig) {
         $output->writeln('Configuring "' . $sectionTitle . '"');
         foreach ($sectionConfig as $key => $value) {
             $key = explode('-', $key);
             $key = $key[0];
             switch ($key) {
                 case 'var':
                     $instruction = new VarInstruction($value, $this->vars, $input, $output, $helper);
                     break;
                 case 'message':
                     $instruction = new MessageInstruction($value, $this->vars, $input, $output, $helper);
                     break;
                 case 'command':
                     $instruction = new CommandInstruction($value, $this->vars, $input, $output, $helper, $this);
                     break;
                 case 'exec':
                     $instruction = new ExecInstruction($value, $this->vars, $input, $output, $helper);
                     break;
                 case 'break':
                     $instruction = new BreakInstruction($value, $this->vars, $input, $output, $helper);
                     break;
                 default:
                     break;
             }
             if (!empty($instruction)) {
                 $executionResult = $instruction->execute();
                 if (false === $executionResult) {
                     break;
                 }
                 $this->vars = $executionResult;
             }
         }
     }
     parent::execute($input, $output);
     return true;
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $one = $this->getOption('one', $input);
     if ($one) {
         $output->writeln('Option one has a value of ' . $one);
     }
     $two = $this->getOption('two', $input);
     if ($two) {
         $output->writeln('Option two has a value of ' . $two);
     }
     $three = $this->getOption('three', $input);
     if ($three) {
         $output->writeln('Option three has a value of ' . $three);
     }
     parent::execute($input, $output);
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $file = $input->getArgument('file');
     $skipIfMissing = $input->getOption('skip-if-missing');
     $sourceExists = file_exists($file);
     if ($skipIfMissing && !$sourceExists) {
         $output->writeln('<info>Skipped as source file [' . $file . '] is missing.</info>');
         return true;
     }
     if (!$sourceExists) {
         $output->writeln('<error>File [' . $file . '] does not exist.</error>');
         return false;
     }
     if (!is_readable($file)) {
         $output->writeln('<error>File [' . $file . '] is not readable.</error>');
         return false;
     }
     if (!is_writeable($file)) {
         $output->writeln('<error>File [' . $file . '] is not writeable.</error>');
         return false;
     }
     $contents = file_get_contents($input->getArgument('file'));
     $count = 0;
     $out = str_replace($input->getArgument('old'), $input->getArgument('new'), $contents, $count);
     $output->writeln('<info>Made ' . $count . ' replacements.</info>');
     $outputFile = $input->getArgument('output');
     $outputFile = $outputFile ? $outputFile : $file;
     try {
         $exit = file_put_contents($outputFile, $out);
     } catch (\Exception $e) {
         $output->writeln('<error>Could not write to [' . $outputFile . '].</error>');
         return false;
     }
     if (empty($exit)) {
         $output->writeln('<error>Could not write to [' . $outputFile . '].</error>');
         return false;
     }
     $output->writeln('<info>Modified contents written to [' . $outputFile . '].</info>');
     parent::execute($input, $output);
     return true;
 }
Beispiel #4
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $host = $input->getOption('host');
     $user = $input->getOption('user');
     $pass = $input->getOption('pass');
     $dbName = $input->getArgument('name');
     try {
         $this->dump = $this->pdoFactory->makeDump($host, $user, $pass, $dbName);
     } catch (\PDOException $e) {
         throw new RuntimeException('Error while connecting to database [' . $dbName . ']: ' . $e->getMessage());
     }
     if (false === $this->dump) {
         $output->writeln('<error>Something went wrong with the dump component instance.</error>');
         return false;
     }
     \Codeception\Configuration::config();
     if (!empty($input->getOption('dump-file'))) {
         $dumpFile = $input->getOption('dump-file');
     } else {
         $dumpFile = codecept_data_dir($input->getArgument('snapshot') . '.sql');
     }
     $output->writeln('<info>Dump file will be written to [' . $dumpFile . ']</info>');
     if (!empty($input->getOption('dist-dump-file'))) {
         $distDumpFile = $input->getOption('dist-dump-file');
     } else {
         $distDumpFile = codecept_data_dir($input->getArgument('snapshot') . '.dist.sql');
     }
     $output->writeln('<info>Distribution version of dump file will be written to [' . $distDumpFile . ']</info>');
     $skipTables = $input->getOption('skip-tables');
     if (!empty($skipTables)) {
         $tables = explode(',', $skipTables);
         foreach ($tables as $table) {
             $this->dump->tables[$table] = \MySQLDump::NONE;
         }
     }
     $memory = fopen('php://memory', 'w');
     $this->dump->write($memory);
     rewind($memory);
     $dumpContents = stream_get_contents($memory);
     if (!$this->filesystem->file_put_contents($dumpFile, $dumpContents)) {
         $output->writeln('<error>Could not write dump to [' . $dumpFile . ']</error>');
         return false;
     }
     $output->writeln('<info>Dump file written to [' . $dumpFile . ']</info>');
     $localUrl = $input->getOption('local-url');
     $distUrl = $input->getOption('dist-url');
     $localDomain = rtrim(preg_replace('~http(s)*:\\/\\/(www\\.)*~', '', $localUrl), '/');
     $distDomain = rtrim(preg_replace('~http(s)*:\\/\\/(www\\.)*~', '', $distUrl), '/');
     $distDumpContents = str_replace($localDomain, $distDomain, $dumpContents);
     if (!$this->filesystem->file_put_contents($distDumpFile, $distDumpContents)) {
         $output->writeln('<error>Could not write dist dump to [' . $distDumpFile . ']</error>');
         return false;
     }
     $output->writeln('<info>Distribution version of dump file written to [' . $distDumpFile . ']</info>');
     $output->writeln('<comment>Any occurrence of [' . $localDomain . '] in it was replaced with [' . $distDomain . ']</comment>');
     parent::execute($input, $output);
     return true;
 }