Esempio n. 1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $schema = $this->schemaGenerator->createSchema($this->entities);
     if (file_exists($this->logFile)) {
         $fromSchema = unserialize(file_get_contents($this->logFile));
         $sqlStatements = $schema->getMigrateFromSql($fromSchema, $this->platform);
     } else {
         $sqlStatements = $schema->toSql($this->platform);
     }
     if (count($sqlStatements) > 0) {
         $output->writeln('Creating database schema...');
         $output->writeln(count($sqlStatements) . ' queries');
         if ($input->getOption('print')) {
             foreach ($sqlStatements as $query) {
                 $output->writeln($query . ';');
                 $output->writeln('');
             }
         } else {
             file_put_contents($this->logFile, serialize($schema));
             $output->writeln($this->logFile . ' updated');
             $name = $input->getArgument('name');
             $migration = $this->manager->createFromLeanMapper($sqlStatements, $name);
             $output->writeln($migration . ' created');
         }
     } else {
         $output->writeln('Nothing to change...');
     }
 }