protected function computeSiteChanges(Workspace $selectedWorkspace)
{
$siteChanges = [];
foreach ($this->publishingService->getUnpublishedNodes($selectedWorkspace) as $node) {
/** @var NodeInterface $node */
if (!$node->getNodeType()->isOfType('Neos.Neos:ContentCollection')) {
$pathParts = explode('/', $node->getPath());
if (count($pathParts) > 2) {
$siteNodeName = $pathParts[2];
$q = new FlowQuery([$node]);
$document = $q->closest('[instanceof Neos.Neos:Document]')->get(0);
// $document will be null if we have a broken root line for this node. This actually should never happen, but currently can in some scenarios.
if ($document !== null) {
$documentPath = implode('/', array_slice(explode('/', $document->getPath()), 3));
$relativePath = str_replace(sprintf(SiteService::SITES_ROOT_PATH . '/%s/%s', $siteNodeName, $documentPath), '', $node->getPath());
if (!isset($siteChanges[$siteNodeName]['siteNode'])) {
$siteChanges[$siteNodeName]['siteNode'] = $this->siteRepository->findOneByNodeName($siteNodeName);
}
$siteChanges[$siteNodeName]['documents'][$documentPath]['documentNode'] = $document;
$change = ['node' => $node, 'contentChanges' => $this->renderContentChanges($node)];
if ($node->getNodeType()->isOfType('Neos.Neos:Node')) {
$change['configuration'] = $node->getNodeType()->getFullConfiguration();
}
$siteChanges[$siteNodeName]['documents'][$documentPath]['changes'][$relativePath] = $change;
}
}
}
}
$liveContext = $this->contextFactory->create(['workspaceName' => 'live']);
ksort($siteChanges);
foreach ($siteChanges as $siteKey => $site) {
foreach ($site['documents'] as $documentKey => $document) {
$liveDocumentNode = $liveContext->getNodeByIdentifier($document['documentNode']->getIdentifier());
$siteChanges[$siteKey]['documents'][$documentKey]['isMoved'] = $liveDocumentNode && $document['documentNode']->getPath() !== $liveDocumentNode->getPath();
$siteChanges[$siteKey]['documents'][$documentKey]['isNew'] = $liveDocumentNode === null;
foreach ($document['changes'] as $changeKey => $change) {
$liveNode = $liveContext->getNodeByIdentifier($change['node']->getIdentifier());
$siteChanges[$siteKey]['documents'][$documentKey]['changes'][$changeKey]['isNew'] = is_null($liveNode);
$siteChanges[$siteKey]['documents'][$documentKey]['changes'][$changeKey]['isMoved'] = $liveNode && $change['node']->getPath() !== $liveNode->getPath();
}
}
ksort($siteChanges[$siteKey]['documents']);
}
return $siteChanges;
}