-
-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5258 from dlubitz/90/feature/asset-usage-again
FEATURE: AssetUsage as CatchUpHook
- Loading branch information
Showing
55 changed files
with
3,823 additions
and
974 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
Neos.Neos/Classes/AssetUsage/AssetUsageIndexingProcessor.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Neos\Neos\AssetUsage; | ||
|
||
use Neos\ContentRepository\Core\ContentRepository; | ||
use Neos\ContentRepository\Core\NodeType\NodeTypeName; | ||
use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\FindChildNodesFilter; | ||
use Neos\ContentRepository\Core\Projection\ContentGraph\Node; | ||
use Neos\ContentRepository\Core\Projection\ContentGraph\VisibilityConstraints; | ||
use Neos\ContentRepository\Core\SharedModel\Exception\NodeAggregateCurrentlyDoesNotExist; | ||
use Neos\ContentRepository\Core\SharedModel\Exception\WorkspaceDoesNotExist; | ||
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName; | ||
use Neos\Neos\AssetUsage\Service\AssetUsageIndexingService; | ||
|
||
readonly class AssetUsageIndexingProcessor | ||
{ | ||
public function __construct( | ||
private AssetUsageIndexingService $assetUsageIndexingService | ||
) { | ||
} | ||
|
||
/** | ||
* @param callable(string $message):void|null $callback | ||
*/ | ||
public function buildIndex(ContentRepository $contentRepository, NodeTypeName $nodeTypeName, callable $callback = null): void | ||
{ | ||
$variationGraph = $contentRepository->getVariationGraph(); | ||
|
||
$workspaceFinder = $contentRepository->getWorkspaceFinder(); | ||
$liveWorkspace = $workspaceFinder->findOneByName(WorkspaceName::forLive()); | ||
if ($liveWorkspace === null) { | ||
throw WorkspaceDoesNotExist::butWasSupposedTo(WorkspaceName::forLive()); | ||
} | ||
|
||
$this->assetUsageIndexingService->pruneIndex($contentRepository->id); | ||
|
||
$workspaces = [$liveWorkspace]; | ||
|
||
$this->dispatchMessage($callback, sprintf('ContentRepository "%s"', $contentRepository->id->value)); | ||
while ($workspaces !== []) { | ||
$workspace = array_shift($workspaces); | ||
|
||
$contentGraph = $contentRepository->getContentGraph($workspace->workspaceName); | ||
$this->dispatchMessage($callback, sprintf(' Workspace: %s', $contentGraph->getWorkspaceName()->value)); | ||
|
||
$dimensionSpacePoints = $variationGraph->getDimensionSpacePoints(); | ||
|
||
$rootNodeAggregate = $contentGraph->findRootNodeAggregateByType( | ||
$nodeTypeName | ||
); | ||
if ($rootNodeAggregate === null) { | ||
$this->dispatchMessage($callback, sprintf(' ERROR: %s', "Root node aggregate was not found.")); | ||
continue; | ||
} | ||
$rootNodeAggregateId = $rootNodeAggregate->nodeAggregateId; | ||
|
||
foreach ($dimensionSpacePoints as $dimensionSpacePoint) { | ||
$this->dispatchMessage($callback, sprintf(' DimensionSpacePoint: %s', $dimensionSpacePoint->toJson())); | ||
|
||
$subgraph = $contentGraph->getSubgraph($dimensionSpacePoint, VisibilityConstraints::withoutRestrictions()); | ||
$childNodes = iterator_to_array($subgraph->findChildNodes($rootNodeAggregateId, FindChildNodesFilter::create())); | ||
|
||
while ($childNodes !== []) { | ||
/** @var Node $childNode */ | ||
$childNode = array_shift($childNodes); | ||
if (!$childNode->originDimensionSpacePoint->equals($childNode->dimensionSpacePoint)) { | ||
continue; | ||
} | ||
$this->assetUsageIndexingService->updateIndex($contentRepository->id, $childNode); | ||
array_push($childNodes, ...iterator_to_array($subgraph->findChildNodes($childNode->aggregateId, FindChildNodesFilter::create()))); | ||
} | ||
} | ||
|
||
array_push($workspaces, ...array_values($workspaceFinder->findByBaseWorkspace($workspace->workspaceName))); | ||
} | ||
} | ||
|
||
private function dispatchMessage(?callable $callback, string $value): void | ||
{ | ||
if ($callback === null) { | ||
return; | ||
} | ||
|
||
$callback($value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Neos\Neos\AssetUsage; | ||
|
||
use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId; | ||
use Neos\Flow\Annotations as Flow; | ||
use Neos\Neos\AssetUsage\Domain\AssetUsageRepository; | ||
use Neos\Neos\AssetUsage\Dto\AssetUsageFilter; | ||
use Neos\Neos\AssetUsage\Dto\AssetUsages; | ||
|
||
/** | ||
* Central authority to look up or remove asset usages in specific a ContentRepository | ||
*/ | ||
#[Flow\Scope('singleton')] | ||
class AssetUsageService | ||
{ | ||
public function __construct( | ||
private readonly AssetUsageRepository $assetUsageRepository, | ||
) { | ||
} | ||
|
||
public function findByFilter(ContentRepositoryId $contentRepositoryId, AssetUsageFilter $filter): AssetUsages | ||
{ | ||
return $this->assetUsageRepository->findUsages($contentRepositoryId, $filter); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.