Skip to content

Commit

Permalink
Merge pull request #3986 from pKallert/feature/add-workspace-dimensio…
Browse files Browse the repository at this point in the history
…n-handling

BUGFIX: Add dimensions to Workspace module
  • Loading branch information
markusguenther authored Jan 17, 2024
2 parents d35a7da + 47b468f commit d50ea72
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -470,16 +470,18 @@ protected function computeChangesCount(Workspace $selectedWorkspace)
{
$changesCount = ['new' => 0, 'changed' => 0, 'removed' => 0, 'total' => 0];
foreach ($this->computeSiteChanges($selectedWorkspace) as $siteChanges) {
foreach ($siteChanges['documents'] as $documentChanges) {
foreach ($documentChanges['changes'] as $change) {
if ($change['node']->isRemoved()) {
$changesCount['removed']++;
} elseif ($change['isNew']) {
$changesCount['new']++;
} else {
$changesCount['changed']++;
};
$changesCount['total']++;
foreach ($siteChanges['documents'] as $dimensions) {
foreach ($dimensions as $documentChanges) {
foreach ($documentChanges['changes'] as $change) {
if ($change['node']->isRemoved()) {
$changesCount['removed']++;
} elseif ($change['isNew']) {
$changesCount['new']++;
} else {
$changesCount['changed']++;
};
$changesCount['total']++;
}
}
}
}
Expand Down Expand Up @@ -509,11 +511,15 @@ protected function computeSiteChanges(Workspace $selectedWorkspace)
// $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));

$dimensionValues = $document->getDimensions();
$documentDimension = Utility::sortDimensionValueArrayAndReturnDimensionsHash($dimensionValues);

$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;
$siteChanges[$siteNodeName]['documents'][$documentDimension][$documentPath]['documentNode'] = $document;

$change = [
'node' => $node,
Expand All @@ -522,7 +528,7 @@ protected function computeSiteChanges(Workspace $selectedWorkspace)
if ($node->getNodeType()->isOfType('Neos.Neos:Node')) {
$change['configuration'] = $node->getNodeType()->getFullConfiguration();
}
$siteChanges[$siteNodeName]['documents'][$documentPath]['changes'][$relativePath] = $change;
$siteChanges[$siteNodeName]['documents'][$documentDimension][$documentPath]['changes'][$relativePath] = $change;
}
}
}
Expand All @@ -534,17 +540,21 @@ protected function computeSiteChanges(Workspace $selectedWorkspace)

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();
foreach ($site['documents'] as $documentDimension => $documentsPerDimension) {
foreach ($documentsPerDimension as $documentKey => $document) {
$liveDocumentNode = $liveContext->getNodeByIdentifier($document['documentNode']->getIdentifier());
$siteChanges[$siteKey]['documents'][$documentDimension][$documentKey]['isMoved'] = $liveDocumentNode && $document['documentNode']->getPath() !== $liveDocumentNode->getPath();
$siteChanges[$siteKey]['documents'][$documentDimension][$documentKey]['isNew'] = $liveDocumentNode === null;
foreach ($document['changes'] as $changeKey => $change) {
$liveNode = $liveContext->getNodeByIdentifier($change['node']->getIdentifier());
$siteChanges[$siteKey]['documents'][$documentDimension][$documentKey]['changes'][$changeKey]['isNew'] = is_null($liveNode);
$siteChanges[$siteKey]['documents'][$documentDimension][$documentKey]['changes'][$changeKey]['isMoved'] = $liveNode && $change['node']->getPath() !== $liveNode->getPath();
}
}
}
ksort($siteChanges[$siteKey]['documents']);
foreach ($siteChanges[$siteKey]['documents'] as $key => $document) {
ksort($siteChanges[$siteKey]['documents'][$key]);
}
}
return $siteChanges;
}
Expand Down
Loading

0 comments on commit d50ea72

Please sign in to comment.