Exemplo n.º 1
0
 /**
  * Execute a command, capturing output and storing the exit code.
  *
  * @param  array $command
  * @return string
  */
 protected function executeRun(array $command)
 {
     // Output will be written to a temporary stream, so that it can be
     // collected after running the command.
     $stream = fopen('php://temp', 'w+');
     // Execute the command, capturing the output in the temporary stream
     // and storing the exit code for debugging purposes.
     $this->exit_code = $this->app->doRun(new ArrayInput($command), new StreamOutput($stream));
     // Get the output of the command and close the stream, which will
     // destroy the temporary file.
     $result = stream_get_contents($stream, -1, 0);
     fclose($stream);
     return $result;
 }
Exemplo n.º 2
0
 public static function migrateDatabase(Event $event = null, $testing = false)
 {
     if ($event) {
         // Use the event's IO
         $io = $event->getIO();
         $arguments = $event->getArguments();
         $testingArguments = array('testing', '--testing', '-t');
         $testing = count(array_intersect($arguments, $testingArguments)) > 0;
     } else {
         // Create our own IO
         $input = new ArrayInput(array());
         $output = new ConsoleOutput();
         $helperSet = new HelperSet(array(new QuestionHelper()));
         $io = new ConsoleIO($input, $output, $helperSet);
     }
     try {
         $config = self::getDatabaseConfig($testing);
     } catch (\Exception $e) {
         $io->write("<bg=red>\n\n [WARNING] " . $e->getMessage() . ", the database won't be updated\n</>");
         return;
     }
     // If the database doesn't exist, ask the user to create it and perform
     // the necessary migrations (unless the user didn't agree to
     // create the database)
     if (self::createDatabase($io, $config['host'], $config['username'], $config['password'], $config['database'])) {
         $io->write('');
         // newline
         $arguments = array('migrate', '-e' => $testing ? 'test' : 'main');
         $app = new PhinxApplication();
         $app->doRun(new ArrayInput($arguments), new ConsoleOutput());
     }
 }