/**
  * Constructs a new Release instance for the release being deployed and the Release currently deployed (when available) sets the instances on the event.
  *
  * @param PrepareDeployReleaseEvent $event
  * @param string                    $eventName
  * @param EventDispatcherInterface  $eventDispatcher
  *
  * @throws TaskRuntimeException when the version selected for deployment is not installed within the workspace.
  */
 public function onPrepareDeployReleaseConstructReleaseInstances(PrepareDeployReleaseEvent $event, $eventName, EventDispatcherInterface $eventDispatcher)
 {
     $workspace = $event->getWorkspace();
     $host = $workspace->getHost();
     $connection = $this->ensureConnection($host);
     $release = new Release($event->getVersion());
     $workspace->addRelease($release);
     if ($connection->isDirectory($release->getPath()) === false) {
         throw new TaskRuntimeException(sprintf('The release "%s" is not installed within the workspace.', $release->getVersion()), $this);
     }
     $event->setRelease($release);
     $currentRelease = null;
     $releasePath = $host->getPath() . '/' . $host->getStage();
     if ($connection->isLink($releasePath)) {
         $releaseRealPath = $connection->readLink($releasePath);
         if (strpos($releaseRealPath, $workspace->getReleasesDirectory()) === 0) {
             $currentRelease = new Release(substr($releaseRealPath, strlen($workspace->getReleasesDirectory())));
             $workspace->addRelease($currentRelease);
             $context = array('currentReleaseVersion' => $currentRelease->getVersion());
             $eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::INFO, 'Detected release version "{currentReleaseVersion}" currently deployed.', $eventName, $this, $context));
             $event->setCurrentRelease($currentRelease);
         }
     }
 }