Exemple #1
0
 public function handle(InputInterface $input, OutputInterface $output)
 {
     $registry = BaseOrm::getRegistry();
     $loader = new Loader();
     $issues = $loader->detectConflicts();
     if (!empty($issues)) {
         $message = 'The following migrations seem to indicate they are both the latest migration :' . PHP_EOL;
         $message .= ' %s ' . PHP_EOL;
         $output->writeln(sprintf($message, Tools::stringify($issues)));
         return;
     }
     if ($input->getOption('no-interaction')) {
         $asker = NonInteractiveAsker::createObject($input, $output);
     } else {
         $asker = InteractiveAsker::createObject($input, $output);
     }
     $autodetector = new AutoDetector($loader->getProjectState(), ProjectState::fromApps($registry), $asker);
     $changes = $autodetector->getChanges($loader->graph);
     if (empty($changes)) {
         $output->writeln('No changes were detected');
         return;
     }
     if ($input->getOption('dry-run')) {
         $output->writeln('<info>Migrations :</info>');
         /** @var $migration Migration */
         foreach ($changes as $migration) {
             $output->writeln('  -- ' . $migration->getName());
         }
         return;
     }
     $this->_writeMigrations($changes, $input, $output);
 }
Exemple #2
0
 public function handle(InputInterface $input, OutputInterface $output)
 {
     $name = $input->getArgument('migration_name');
     if ($input->getOption('fake')) {
         $fake = true;
     } else {
         $fake = false;
     }
     $connection = BaseOrm::getDbConnection();
     $registry = BaseOrm::getRegistry();
     $executor = Executor::createObject($connection);
     // target migrations to act on
     if (!empty($name)) {
         if ($name == 'zero') {
             $targets = [$name];
         } else {
             $targets = $executor->loader->getMigrationByPrefix($name);
         }
     } else {
         $targets = $executor->loader->graph->getLeafNodes();
     }
     // get migration plan
     $plan = $executor->getMigrationPlan($targets);
     BaseOrm::signalDispatch('powerorm.migration.pre_migrate', $this);
     $output->writeln('<comment>Running migrations:</comment>');
     if (empty($plan)) {
         $output->writeln('  No migrations to apply.');
         if ($input->getOption('no-interaction')) {
             $asker = NonInteractiveAsker::createObject($input, $output);
         } else {
             $asker = InteractiveAsker::createObject($input, $output);
         }
         //detect if we need to make migrations
         $auto_detector = new AutoDetector($executor->loader->getProjectState(), ProjectState::fromApps($registry), $asker);
         $changes = $auto_detector->getChanges($executor->loader->graph);
         if (!empty($changes)) {
             $output->writeln('<warning>  Your models have changes that are not yet reflected ' . "in a migration, and so won't be applied.</warning>");
             $output->writeln("<warning>  Run 'php pmanager.php makemigrations' to make new " . "migrations, and then re-run 'php pmanager.php migrate' to apply them.</warning>");
         }
     } else {
         // migrate
         $executor->migrate($targets, $plan, $fake);
     }
     BaseOrm::signalDispatch('powerorm.migration.post_migrate', $this);
 }