/** * 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; }
/** * @inheritdoc */ public function fetchAll() { $definitions = $this->mapper->fetchAll(); $stored = array_map(function (DeltaId $id) { return $id->toString(); }, $this->storage->fetchAll()); $collection = new Collection(); foreach ($definitions as $definition) { /** @var DefinitionInterface $definition */ $migration = $definition->getMigration(); $id = $definition->getId(); $migrated = in_array($id->toString(), $stored); $version = new Delta($migration, $migrated, $id, $this->getMigrationBus()); $collection->add($version); } return $collection->sort($this->comparator); }