/**
  * converge (v): come together from different directions so as eventually to meet.
  *
  * @param ConvergeCommand $command
  *
  * @return \Baleen\Migrations\Common\Collection\CollectionInterface
  */
 public function handle(ConvergeCommand $command)
 {
     $collection = $command->getCollection();
     $targetUp = $command->getTarget();
     $options = $command->getOptions();
     $domainBus = $command->getDomainBus();
     $position = $collection->getPosition($targetUp);
     $targetDown = $collection->getByPosition($position + 1);
     $changed = clone $collection;
     $changed->clear();
     $upCommand = new CollectionCommand($collection, $targetUp, $options->withDirection(Direction::up()), $command->getVersionRepository());
     $upChanges = $domainBus->handle($upCommand);
     if (!empty($upChanges)) {
         $changed->merge($upChanges);
     }
     // if we're not yet at the end of the queue (where no migrations can go down)
     if (null !== $targetDown) {
         $downCommand = new CollectionCommand($collection, $targetDown, $options->withDirection(Direction::down()), $command->getVersionRepository());
         $downChanges = $domainBus->handle($downCommand);
         if (!empty($downChanges)) {
             $changed->merge($downChanges);
         }
     }
     return $changed->sort();
 }
Exemple #2
0
 /**
  * @param $direction
  * @param bool $forced
  * @param bool $dryRun
  * @param bool $exceptionOnSkip
  * @param array $custom
  *
  * @throws InvalidArgumentException
  */
 public function __construct(Direction $direction = null, $forced = false, $dryRun = false, $exceptionOnSkip = true, array $custom = [])
 {
     if (null === $direction) {
         $direction = Direction::up();
     }
     $this->direction = $direction;
     $this->forced = (bool) $forced;
     $this->dryRun = (bool) $dryRun;
     $this->exceptionOnSkip = (bool) $exceptionOnSkip;
     $this->custom = $custom;
 }