コード例 #1
0
ファイル: Migrate.php プロジェクト: eddmash/powerorm
 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);
 }