/** * 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); } }