Beispiel #1
0
 /**
  * Runs a collection of versions towards the specified goal and using the specified options
  *
  * @param DeltaInterface $target
  * @param OptionsInterface $options
  *
  * @return CollectionAfterEvent
  */
 public function run(DeltaInterface $target, OptionsInterface $options)
 {
     $current = 1;
     $collection = $this->getCollection();
     $context = CollectionContext::createWithProgress(max($collection->count(), 1), $current);
     $migrationRunner = $this->migrationRunner->withContext($context);
     $this->getPublisher()->publish(new CollectionBeforeEvent($target, $options, $collection));
     $modified = new Collection();
     $comparator = $collection->getComparator();
     // IMPROVE: add tests to see if rewind is necessary
     $collection->first();
     // rewind
     foreach ($collection as $version) {
         $context->getProgress()->update($current);
         $result = $migrationRunner->run($version, $options);
         if ($result) {
             $modified->add($version);
         }
         if ($comparator->compare($version, $target) >= 0) {
             break;
         }
         $current += 1;
     }
     $event = new CollectionAfterEvent($target, $options, $modified);
     $this->getPublisher()->publish($event);
     return $event;
 }
Beispiel #2
0
 /**
  * MigrationRunner constructor.
  *
  * @param PublisherInterface $publisher
  * @param CollectionContextInterface $context
  */
 public function __construct(PublisherInterface $publisher = null, CollectionContextInterface $context = null)
 {
     if (null === $context) {
         $context = CollectionContext::createWithProgress(1, 1);
     }
     $this->setContext($context);
     $this->setPublisher($publisher);
 }