/**
  * Save the aggregate history.
  *
  * @param EventSourcedAggregateRootInterface $aggregateRoot
  */
 protected function saveHistory(EventSourcedAggregateRootInterface $aggregateRoot)
 {
     $recordedEvents = $aggregateRoot->recordedEvents();
     if (count($recordedEvents) > 0) {
         DomainEventPublisher::publish(new PrePersistEvent($aggregateRoot));
         // clear events
         $aggregateRoot->clearEvents();
         // create the eventStream and persist it
         $applicationVersion = VersionManager::currentApplicationVersion();
         $eventStream = new EventStream($this->streamName(), $aggregateRoot->id(), $recordedEvents);
         $this->eventStore->persist($eventStream, $aggregateRoot->version(), $applicationVersion);
         DomainEventPublisher::publish(new PostPersistEvent($aggregateRoot));
     }
 }
Exemple #2
0
 /**
  * @param string      $aggregateClassName
  * @param EventStream $eventStream
  * @param Version     $aggregateVersion
  * @param Version     $applicationVersion
  */
 protected function migrateAggregateRoot($aggregateClassName, EventStream $eventStream, Version $aggregateVersion, Version $applicationVersion)
 {
     // this will persist the eventstream in a new flow, because the
     // currentApplicationVersion is set to the target migration
     $this->eventStore->persist($eventStream, $aggregateVersion, $applicationVersion);
 }