/**
  * Helper method for creating a new node.
  *
  * @param NodeInterface $referenceNode
  * @param array $nodeData
  * @param string $position
  * @return NodeInterface
  * @throws \InvalidArgumentException
  */
 public function create(NodeInterface $referenceNode, array $nodeData, $position)
 {
     if (!in_array($position, array('before', 'into', 'after'), true)) {
         throw new \InvalidArgumentException('The position should be one of the following: "before", "into", "after".', 1347133640);
     }
     $nodeType = $this->nodeTypeManager->getNodeType($nodeData['nodeType']);
     if ($nodeType->isOfType('Neos.Neos:Document') && !isset($nodeData['properties']['uriPathSegment']) && isset($nodeData['properties']['title'])) {
         $nodeData['properties']['uriPathSegment'] = $this->nodeUriPathSegmentGenerator->generateUriPathSegment($referenceNode, $nodeData['properties']['title']);
     }
     $proposedNodeName = isset($nodeData['nodeName']) ? $nodeData['nodeName'] : null;
     $nodeData['nodeName'] = $this->nodeService->generateUniqueNodeName($this->getDesignatedParentNode($referenceNode, $position)->getPath(), $proposedNodeName);
     if ($position === 'into') {
         $newNode = $referenceNode->createNode($nodeData['nodeName'], $nodeType);
     } else {
         $parentNode = $referenceNode->getParent();
         $newNode = $parentNode->createNode($nodeData['nodeName'], $nodeType);
         if ($position === 'before') {
             $newNode->moveBefore($referenceNode);
         } else {
             $newNode->moveAfter($referenceNode);
         }
     }
     if (isset($nodeData['properties']) && is_array($nodeData['properties'])) {
         foreach ($nodeData['properties'] as $propertyName => $propertyValue) {
             $newNode->setProperty($propertyName, $propertyValue);
         }
     }
     return $newNode;
 }
 /**
  * Traverses through the tree starting at the given root node and sets the uriPathSegment property derived from
  * the node label.
  *
  * @param NodeInterface $node The node where the traversal starts
  * @param boolean $dryRun
  * @return void
  */
 protected function generateUriPathSegmentsForNode(NodeInterface $node, $dryRun)
 {
     if ((string) $node->getProperty('uriPathSegment') === '') {
         $name = $node->getLabel() ?: $node->getName();
         $uriPathSegment = $this->nodeUriPathSegmentGenerator->generateUriPathSegment($node);
         if ($dryRun === false) {
             $node->setProperty('uriPathSegment', $uriPathSegment);
             $this->output->outputLine('Added missing URI path segment for "%s" (%s) => %s', array($node->getPath(), $name, $uriPathSegment));
         } else {
             $this->output->outputLine('Found missing URI path segment for "%s" (%s) => %s', array($node->getPath(), $name, $uriPathSegment));
         }
     }
     foreach ($node->getChildNodes('Neos.Neos:Document') as $childNode) {
         $this->generateUriPathSegmentsForNode($childNode, $dryRun);
     }
 }
 /**
  * @param Bootstrap $bootstrap The current bootstrap
  * @return void
  */
 public function boot(Bootstrap $bootstrap)
 {
     $dispatcher = $bootstrap->getSignalSlotDispatcher();
     $flushConfigurationCache = function () use($bootstrap) {
         $cacheManager = $bootstrap->getEarlyInstance(CacheManager::class);
         $cacheManager->getCache('TYPO3_Neos_Configuration_Version')->flush();
     };
     $flushXliffServiceCache = function () use($bootstrap) {
         $cacheManager = $bootstrap->getEarlyInstance(CacheManager::class);
         $cacheManager->getCache('TYPO3_Neos_XliffToJsonTranslations')->flush();
     };
     $dispatcher->connect(FileMonitor::class, 'filesHaveChanged', function ($fileMonitorIdentifier, array $changedFiles) use($flushConfigurationCache, $flushXliffServiceCache) {
         switch ($fileMonitorIdentifier) {
             case 'TYPO3CR_NodeTypesConfiguration':
             case 'Flow_ConfigurationFiles':
                 $flushConfigurationCache();
                 break;
             case 'Flow_TranslationFiles':
                 $flushConfigurationCache();
                 $flushXliffServiceCache();
         }
     });
     $dispatcher->connect(Site::class, 'siteChanged', $flushConfigurationCache);
     $dispatcher->connect(Site::class, 'siteChanged', RouterCachingService::class, 'flushCaches');
     $dispatcher->connect(Node::class, 'nodeUpdated', ContentCacheFlusher::class, 'registerNodeChange');
     $dispatcher->connect(Node::class, 'nodeAdded', ContentCacheFlusher::class, 'registerNodeChange');
     $dispatcher->connect(Node::class, 'nodeRemoved', ContentCacheFlusher::class, 'registerNodeChange');
     $dispatcher->connect(Node::class, 'beforeNodeMove', ContentCacheFlusher::class, 'registerNodeChange');
     $dispatcher->connect(AssetService::class, 'assetResourceReplaced', ContentCacheFlusher::class, 'registerAssetResourceChange');
     $dispatcher->connect(Node::class, 'nodeAdded', NodeUriPathSegmentGenerator::class, '::setUniqueUriPathSegment');
     $dispatcher->connect(Node::class, 'nodePropertyChanged', Service\ImageVariantGarbageCollector::class, 'removeUnusedImageVariant');
     $dispatcher->connect(Node::class, 'nodePropertyChanged', function (NodeInterface $node, $propertyName) use($bootstrap) {
         if ($propertyName === 'uriPathSegment') {
             NodeUriPathSegmentGenerator::setUniqueUriPathSegment($node);
             $bootstrap->getObjectManager()->get(RouteCacheFlusher::class)->registerNodeChange($node);
         }
     });
     $dispatcher->connect(Node::class, 'nodePathChanged', function (NodeInterface $node, $oldPath, $newPath, $recursion) {
         if (!$recursion) {
             NodeUriPathSegmentGenerator::setUniqueUriPathSegment($node);
         }
     });
     $dispatcher->connect(PublishingService::class, 'nodePublished', ContentCacheFlusher::class, 'registerNodeChange');
     $dispatcher->connect(PublishingService::class, 'nodeDiscarded', ContentCacheFlusher::class, 'registerNodeChange');
     $dispatcher->connect(Node::class, 'nodePathChanged', RouteCacheFlusher::class, 'registerNodeChange');
     $dispatcher->connect(Node::class, 'nodeRemoved', RouteCacheFlusher::class, 'registerNodeChange');
     $dispatcher->connect(PublishingService::class, 'nodeDiscarded', RouteCacheFlusher::class, 'registerNodeChange');
     $dispatcher->connect(PublishingService::class, 'nodePublished', RouteCacheFlusher::class, 'registerNodeChange');
     $dispatcher->connect(PublishingService::class, 'nodePublished', function ($node, $targetWorkspace) use($bootstrap) {
         $cacheManager = $bootstrap->getObjectManager()->get(CacheManager::class);
         if ($cacheManager->hasCache('Flow_Persistence_Doctrine')) {
             $cacheManager->getCache('Flow_Persistence_Doctrine')->flush();
         }
     });
     $dispatcher->connect(PersistenceManager::class, 'allObjectsPersisted', RouteCacheFlusher::class, 'commit');
     $dispatcher->connect(SiteService::class, 'sitePruned', ContentCache::class, 'flush');
     $dispatcher->connect(SiteService::class, 'sitePruned', RouterCachingService::class, 'flushCaches');
     $dispatcher->connect(SiteImportService::class, 'siteImported', ContentCache::class, 'flush');
     $dispatcher->connect(SiteImportService::class, 'siteImported', RouterCachingService::class, 'flushCaches');
     // Eventlog
     $dispatcher->connect(Node::class, 'beforeNodeCreate', ContentRepositoryIntegrationService::class, 'beforeNodeCreate');
     $dispatcher->connect(Node::class, 'afterNodeCreate', ContentRepositoryIntegrationService::class, 'afterNodeCreate');
     $dispatcher->connect(Node::class, 'nodeUpdated', ContentRepositoryIntegrationService::class, 'nodeUpdated');
     $dispatcher->connect(Node::class, 'nodeRemoved', ContentRepositoryIntegrationService::class, 'nodeRemoved');
     $dispatcher->connect(Node::class, 'beforeNodePropertyChange', ContentRepositoryIntegrationService::class, 'beforeNodePropertyChange');
     $dispatcher->connect(Node::class, 'nodePropertyChanged', ContentRepositoryIntegrationService::class, 'nodePropertyChanged');
     $dispatcher->connect(Node::class, 'beforeNodeCopy', ContentRepositoryIntegrationService::class, 'beforeNodeCopy');
     $dispatcher->connect(Node::class, 'afterNodeCopy', ContentRepositoryIntegrationService::class, 'afterNodeCopy');
     $dispatcher->connect(Node::class, 'beforeNodeMove', ContentRepositoryIntegrationService::class, 'beforeNodeMove');
     $dispatcher->connect(Node::class, 'afterNodeMove', ContentRepositoryIntegrationService::class, 'afterNodeMove');
     $dispatcher->connect(Context::class, 'beforeAdoptNode', ContentRepositoryIntegrationService::class, 'beforeAdoptNode');
     $dispatcher->connect(Context::class, 'afterAdoptNode', ContentRepositoryIntegrationService::class, 'afterAdoptNode');
     $dispatcher->connect(Workspace::class, 'beforeNodePublishing', ContentRepositoryIntegrationService::class, 'beforeNodePublishing');
     $dispatcher->connect(Workspace::class, 'afterNodePublishing', ContentRepositoryIntegrationService::class, 'afterNodePublishing');
     $dispatcher->connect(PersistenceManager::class, 'allObjectsPersisted', ContentRepositoryIntegrationService::class, 'updateEventsAfterPublish');
     $dispatcher->connect(NodeDataRepository::class, 'repositoryObjectsPersisted', ContentRepositoryIntegrationService::class, 'updateEventsAfterPublish');
 }