/** * 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); } } }
/** * Links the maintenance page to the stage being deployed. * * @param PrepareDeployReleaseEvent $event * @param string $eventName * @param EventDispatcherInterface $eventDispatcher * * @throws TaskRuntimeException when not able to link the maintenance page. */ public function onPrepareDeployReleaseLinkMaintenancePageToStage(PrepareDeployReleaseEvent $event, $eventName, EventDispatcherInterface $eventDispatcher) { if (VersionCategoryComparator::matchesStrategy($this->strategy, $event->getRelease(), $event->getCurrentRelease()) === false) { $eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::INFO, 'Skipped linking maintenance page according to strategy.', $eventName, $this)); return; } $host = $event->getWorkspace()->getHost(); $connection = $this->ensureConnection($host); $linkSource = $host->getPath() . '/maintenance/'; $linkTarget = $host->getPath() . '/' . $host->getStage(); $context = array('linkTarget' => $linkTarget); if ($connection->isLink($linkTarget) && $connection->delete($linkTarget, false) === false) { $eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::WARNING, 'Failed to remove existing "{linkTarget}" link.', $eventName, $this, $context)); } $context['event.task.action'] = TaskInterface::ACTION_IN_PROGRESS; $eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::INFO, 'Linking "{linkTarget}" to maintenance page.', $eventName, $this, $context)); if ($connection->link($linkSource, $linkTarget)) { $context['event.task.action'] = TaskInterface::ACTION_COMPLETED; $context['output.resetLine'] = true; $eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::INFO, 'Linked "{linkTarget}" to maintenance page.', $eventName, $this, $context)); } else { $context['event.task.action'] = TaskInterface::ACTION_FAILED; $context['output.resetLine'] = true; $eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::INFO, 'Linking "{linkTarget}" to maintenance page failed.', $eventName, $this, $context)); throw new TaskRuntimeException(sprintf('Linking "%s" to maintenance page failed.', $context['linkTarget']), $this); } }