Skip to content

Commit

Permalink
Fix more usages
Browse files Browse the repository at this point in the history
  • Loading branch information
bwaidelich committed Apr 2, 2023
1 parent cfe3bdc commit 2ee183d
Show file tree
Hide file tree
Showing 60 changed files with 174 additions and 151 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ protected function removeRelationRecursivelyFromDatabaseIncludingNonReferencedNo
AND h.contentstreamid IS NULL
',
[
'anchorPointForNode' => (string)$ingoingRelation->childNodeAnchor,
'anchorPointForNode' => $ingoingRelation->childNodeAnchor->value,
]
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function __construct(
public function addToDatabase(Connection $databaseConnection, string $tableNamePrefix): void
{
$databaseConnection->insert($tableNamePrefix . '_node', [
'relationanchorpoint' => (string)$this->relationAnchorPoint,
'relationanchorpoint' => $this->relationAnchorPoint->value,
'nodeaggregateid' => $this->nodeAggregateId->value,
'origindimensionspacepoint' => json_encode($this->originDimensionSpacePoint),
'origindimensionspacepointhash' => $this->originDimensionSpacePointHash,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public function findRootNodeAggregates(

$parameters = [
'contentStreamId' => $contentStreamId->value,
'rootEdgeParentAnchorId' => (string)NodeRelationAnchorPoint::forRootEdge(),
'rootEdgeParentAnchorId' => NodeRelationAnchorPoint::forRootEdge()->value,
];

if ($filter->nodeTypeName !== null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public function getNodeByAnchorPoint(NodeRelationAnchorPoint $nodeRelationAnchor
'SELECT n.* FROM ' . $this->tableNamePrefix . '_node n
WHERE n.relationanchorpoint = :relationAnchorPoint',
[
'relationAnchorPoint' => (string)$nodeRelationAnchorPoint,
'relationAnchorPoint' => $nodeRelationAnchorPoint->value,
]
)->fetchAssociative();

Expand Down Expand Up @@ -257,7 +257,7 @@ public function determineHierarchyRelationPosition(
AND h.contentstreamid = :contentStreamId
AND h.dimensionspacepointhash = :dimensionSpacePointHash',
[
'succeedingSiblingAnchorPoint' => (string)$succeedingSiblingAnchorPoint,
'succeedingSiblingAnchorPoint' => $succeedingSiblingAnchorPoint->value,
'contentStreamId' => $contentStreamId->value,
'dimensionSpacePointHash' => $dimensionSpacePoint->hash
]
Expand Down Expand Up @@ -350,7 +350,7 @@ public function getOutgoingHierarchyRelationsForNodeAndSubgraph(
AND h.contentstreamid = :contentStreamId
AND h.dimensionspacepointhash = :dimensionSpacePointHash',
[
'parentAnchorPoint' => (string)$parentAnchorPoint,
'parentAnchorPoint' => $parentAnchorPoint->value,
'contentStreamId' => $contentStreamId->value,
'dimensionSpacePointHash' => $dimensionSpacePoint->hash
]
Expand Down Expand Up @@ -382,7 +382,7 @@ public function getIngoingHierarchyRelationsForNodeAndSubgraph(
AND h.contentstreamid = :contentStreamId
AND h.dimensionspacepointhash = :dimensionSpacePointHash',
[
'childAnchorPoint' => (string)$childAnchorPoint,
'childAnchorPoint' => $childAnchorPoint->value,
'contentStreamId' => $contentStreamId->value,
'dimensionSpacePointHash' => $dimensionSpacePoint->hash
]
Expand Down Expand Up @@ -411,7 +411,7 @@ public function findIngoingHierarchyRelationsForNode(
WHERE h.childnodeanchor = :childAnchorPoint
AND h.contentstreamid = :contentStreamId';
$parameters = [
'childAnchorPoint' => (string)$childAnchorPoint,
'childAnchorPoint' => $childAnchorPoint->value,
'contentStreamId' => $contentStreamId->value
];
$types = [];
Expand Down Expand Up @@ -449,7 +449,7 @@ public function findOutgoingHierarchyRelationsForNode(
WHERE h.parentnodeanchor = :parentAnchorPoint
AND h.contentstreamid = :contentStreamId';
$parameters = [
'parentAnchorPoint' => (string)$parentAnchorPoint,
'parentAnchorPoint' => $parentAnchorPoint->value,
'contentStreamId' => $contentStreamId->value
];
$types = [];
Expand Down Expand Up @@ -561,7 +561,7 @@ public function getAllContentStreamIdsAnchorPointIsContainedIn(
FROM ' . $this->tableNamePrefix . '_hierarchyrelation h
WHERE h.childnodeanchor = :nodeRelationAnchorPoint',
[
'nodeRelationAnchorPoint' => (string)$nodeRelationAnchorPoint,
'nodeRelationAnchorPoint' => $nodeRelationAnchorPoint->value,
]
)->fetchAllAssociative() as $row
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ protected function replaceNodeRelationAnchorPoint(
)';
$parameters = [
'contentStreamId' => $contentStreamId->value,
'newNodeRelationAnchorPoint' => (string)$newNodeRelationAnchorPoint,
'newNodeRelationAnchorPoint' => $newNodeRelationAnchorPoint->value,
'affectedNodeAggregateId' => $affectedNodeAggregateId->value
];
foreach ($affectedDimensionSpacePointSet as $affectedDimensionSpacePoint) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function replaceParentNodeAnchor(
$databaseConnection->update(
$tableNamePrefix . '_hierarchyhyperrelation',
[
'parentnodeanchor' => (string)$newParentNodeAnchor
'parentnodeanchor' => $newParentNodeAnchor->value
],
$this->getDatabaseIdentifier()
);
Expand Down Expand Up @@ -169,7 +169,7 @@ public function getDatabaseIdentifier(): array
{
return [
'contentstreamid' => $this->contentStreamId->value,
'parentnodeanchor' => (string)$this->parentNodeAnchor,
'parentnodeanchor' => $this->parentNodeAnchor->value,
'dimensionspacepointhash' => $this->dimensionSpacePoint->hash
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
namespace Neos\ContentGraph\PostgreSQLAdapter\Domain\Projection;

use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateIds
as NodeAggregateIdCollection;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateIds as NodeAggregateIdCollection;

/**
* The node aggregate identifier value object collection
*
* @internal
* @implements \IteratorAggregate<NodeAggregateId>
*/
final class NodeAggregateIds
final class NodeAggregateIds implements \IteratorAggregate
{
/**
* @var array<string,NodeAggregateId>
Expand Down Expand Up @@ -69,16 +69,6 @@ public static function fromCollection(
);
}

public static function fromDatabaseString(string $databaseString): self
{
return self::fromArray(\explode(',', \trim($databaseString, '{}')));
}

public function toDatabaseString(): string
{
return '{' . implode(',', $this->ids) . '}';
}

public function add(
NodeAggregateId $nodeAggregateId,
?NodeAggregateId $succeedingSibling = null
Expand Down Expand Up @@ -108,4 +98,9 @@ public function isEmpty(): bool
{
return count($this->ids) === 0;
}

public function getIterator(): \Traversable
{
return new \ArrayIterator($this->ids);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ public static function fromDatabaseRow(array $databaseRow): self
public function addToDatabase(Connection $databaseConnection, string $tableNamePrefix): void
{
$databaseConnection->insert($tableNamePrefix . '_node', [
'relationanchorpoint' => (string) $this->relationAnchorPoint,
'relationanchorpoint' => $this->relationAnchorPoint->value,
'origindimensionspacepoint' => json_encode($this->originDimensionSpacePoint),
'origindimensionspacepointhash' => $this->originDimensionSpacePoint->hash,
'nodeaggregateid' => $this->nodeAggregateId->value,
'nodetypename' => $this->nodeTypeName->value,
'classification' => $this->classification->value,
'properties' => json_encode($this->properties),
'nodename' => $this->nodeName->value
'nodename' => $this->nodeName?->value
]);
}

Expand All @@ -115,7 +115,7 @@ public function updateToDatabase(Connection $databaseConnection, string $tableNa
'nodetypename' => $this->nodeTypeName->value,
'classification' => $this->classification->value,
'properties' => json_encode($this->properties),
'nodename' => $this->nodeName->value,
'nodename' => $this->nodeName?->value,
],
[
'relationanchorpoint' => $this->relationAnchorPoint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function findNodeRecordByRelationAnchorPoint(
WHERE n.relationanchorpoint = :relationAnchorPoint';

$parameters = [
'relationAnchorPoint' => (string)$relationAnchorPoint
'relationAnchorPoint' => $relationAnchorPoint->value
];

$result = $this->getDatabaseConnection()->executeQuery($query, $parameters)->fetchAssociative();
Expand Down Expand Up @@ -215,7 +215,7 @@ public function findIngoingHierarchyHyperrelationRecords(
AND :childNodeAnchor = ANY(h.childnodeanchors)';
$parameters = [
'contentStreamId' => $contentStreamId->value,
'childNodeAnchor' => (string)$childNodeAnchor
'childNodeAnchor' => $childNodeAnchor->value
];
$types = [];

Expand Down Expand Up @@ -250,7 +250,7 @@ public function findOutgoingHierarchyHyperrelationRecords(
AND h.parentnodeanchor = :parentNodeAnchor';
$parameters = [
'contentStreamId' => $contentStreamId->value,
'parentNodeAnchor' => (string)$parentNodeAnchor
'parentNodeAnchor' => $parentNodeAnchor->value
];
$types = [];

Expand Down Expand Up @@ -282,7 +282,7 @@ public function findOutgoingReferenceHyperrelationRecords(
WHERE r.sourcenodeanchor = :sourceNodeAnchor';

$parameters = [
'sourceNodeAnchor' => (string)$sourceNodeAnchor
'sourceNodeAnchor' => $sourceNodeAnchor->value
];

$referenceHyperrelations = [];
Expand Down Expand Up @@ -312,7 +312,7 @@ public function findHierarchyHyperrelationRecordByParentNodeAnchor(
$parameters = [
'contentStreamId' => $contentStreamId->value,
'dimensionSpacePointHash' => $dimensionSpacePoint->hash,
'parentNodeAnchor' => (string)$parentNodeAnchor
'parentNodeAnchor' => $parentNodeAnchor->value
];

$result = $this->getDatabaseConnection()->executeQuery($query, $parameters)->fetchAssociative();
Expand All @@ -339,7 +339,7 @@ public function findHierarchyHyperrelationRecordByChildNodeAnchor(
$parameters = [
'contentStreamId' => $contentStreamId->value,
'dimensionSpacePointHash' => $dimensionSpacePoint->hash,
'childNodeAnchor' => (string)$childNodeAnchor
'childNodeAnchor' => $childNodeAnchor->value
];

$result = $this->getDatabaseConnection()->executeQuery($query, $parameters)->fetchAssociative();
Expand All @@ -361,7 +361,7 @@ public function findHierarchyHyperrelationRecordsByChildNodeAnchor(
WHERE :childNodeAnchor = ANY(h.childnodeanchors)';

$parameters = [
'childNodeAnchor' => (string)$childNodeAnchor
'childNodeAnchor' => $childNodeAnchor->value
];

$hierarchyRelationRecords = [];
Expand Down Expand Up @@ -420,7 +420,7 @@ public function findCoverageByNodeRelationAnchorPoint(
AND n.relationanchorpoint = :relationAnchorPoint';
$parameters = [
'contentStreamId' => $contentStreamId->value,
'relationanchorpoint' => (string)$nodeRelationAnchorPoint
'relationanchorpoint' => $nodeRelationAnchorPoint->value
];

$dimensionSpacePoints = [];
Expand Down Expand Up @@ -614,7 +614,7 @@ public function countContentStreamCoverage(NodeRelationAnchorPoint $anchorPoint)
WHERE :anchorPoint = ANY(childnodeanchors)';

$parameters = [
'anchorPoint' => (string)$anchorPoint
'anchorPoint' => $anchorPoint->value
];

return (int)$this->getDatabaseConnection()->executeQuery($query, $parameters)->rowCount();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static function fromDatabaseRow(array $databaseRow): self
public function addToDatabase(Connection $databaseConnection, string $tableNamePrefix): void
{
$databaseConnection->insert($tableNamePrefix . '_referencerelation', [
'sourcenodeanchor' => (string)$this->sourceNodeAnchor,
'sourcenodeanchor' => $this->sourceNodeAnchor->value,
'name' => $this->name->value,
'position' => $this->position,
'properties' => $this->properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static function fromDatabaseRow(array $databaseRow): self
ContentStreamId::fromString($databaseRow['contentstreamid']),
$databaseRow['dimensionspacepointhash'],
NodeAggregateId::fromString($databaseRow['originnodeaggregateid']),
NodeAggregateIds::fromDatabaseString($databaseRow['affectednodeaggregateids'])
self::nodeAggregateIdsFromDatabaseString($databaseRow['affectednodeaggregateids'])
);
}

Expand Down Expand Up @@ -113,7 +113,7 @@ public function addToDatabase(Connection $databaseConnection, string $tableNameP
$this->contentStreamId->value,
$this->dimensionSpacePointHash,
$this->originNodeAggregateId->value,
$this->affectedNodeAggregateIds->toDatabaseString()
self::nodeAggregateIdsToDatabaseString($this->affectedNodeAggregateIds),
]
);
}
Expand All @@ -129,7 +129,7 @@ private function updateAffectedNodeAggregateIds(
$databaseConnection->update(
$tableNamePrefix . '_restrictionhyperrelation',
[
'affectednodeaggregateids' => $affectedNodeAggregateIds->toDatabaseString()
'affectednodeaggregateids' => self::nodeAggregateIdsToDatabaseString($affectedNodeAggregateIds),
],
$this->getDatabaseIdentifier()
);
Expand All @@ -155,4 +155,14 @@ public function getDatabaseIdentifier(): array
'originnodeaggregateid' => $this->originNodeAggregateId->value
];
}

private static function nodeAggregateIdsFromDatabaseString(string $databaseString): NodeAggregateIds
{
return NodeAggregateIds::fromArray(\explode(',', \trim($databaseString, '{}')));
}

private static function nodeAggregateIdsToDatabaseString(NodeAggregateIds $ids): string
{
return '{' . implode(',', array_map(static fn (NodeAggregateId $id) => $id->value, iterator_to_array($ids))) . '}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct(
public static function graphProjectionTableNamePrefix(
ContentRepositoryId $contentRepositoryId
): string {
return sprintf('cr_%s_p_hypergraph', $contentRepositoryId);
return sprintf('cr_%s_p_hypergraph', $contentRepositoryId->value);
}

public function build(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public function __construct(
/**
* @var array<string,Dimension\ContentDimensionValueSpecializationDepth>
*/
public readonly array $weight
public readonly array $value
) {
foreach ($weight as $dimensionId => $specializationDepth) {
foreach ($value as $dimensionId => $specializationDepth) {
if (!$specializationDepth instanceof Dimension\ContentDimensionValueSpecializationDepth) {
throw new \InvalidArgumentException(
sprintf(
Expand All @@ -54,12 +54,12 @@ public function __construct(
public function getWeightInDimension(
Dimension\ContentDimensionId $dimensionId
): ?Dimension\ContentDimensionValueSpecializationDepth {
return $this->weight[$dimensionId->value] ?? null;
return $this->value[$dimensionId->value] ?? null;
}

public function canBeComparedTo(ContentSubgraphVariationWeight $other): bool
{
return array_keys($other->weight) === array_keys($this->weight);
return array_keys($other->value) === array_keys($this->value);
}

/**
Expand All @@ -71,7 +71,7 @@ public function decreaseBy(ContentSubgraphVariationWeight $other): ContentSubgra
throw Exception\ContentSubgraphVariationWeightsAreIncomparable::butWereAttemptedTo($this, $other);
}
$decreasedWeight = [];
foreach ($this->weight as $rawDimensionId => $weight) {
foreach ($this->value as $rawDimensionId => $weight) {
$dimensionId = new Dimension\ContentDimensionId($rawDimensionId);
/**
* @var Dimension\ContentDimensionValueSpecializationDepth $otherWeight
Expand All @@ -87,9 +87,10 @@ public function decreaseBy(ContentSubgraphVariationWeight $other): ContentSubgra
public function normalize(int $normalizationBase): int
{
$normalizedWeight = 0;
$exponent = count($this->weight) - 1;
foreach ($this->weight as $dimensionId => $specializationDepth) {
$normalizedWeight += pow($normalizationBase, $exponent) * $specializationDepth->depth;
$exponent = count($this->value) - 1;
/** @var Dimension\ContentDimensionValueSpecializationDepth $specializationDepth */
foreach ($this->value as $dimensionId => $specializationDepth) {
$normalizedWeight += pow($normalizationBase, $exponent) * $specializationDepth->value;
$exponent--;
}

Expand All @@ -101,7 +102,7 @@ public function normalize(int $normalizationBase): int
*/
public function jsonSerialize(): array
{
return $this->weight;
return $this->value;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static function butWereAttemptedTo(
ContentSubgraphVariationWeight $second
): self {
return new self(
'Weights ' . $first . ' and ' . $second . ' cannot be compared.',
'Weights ' . $first->toJson() . ' and ' . $second->toJson() . ' cannot be compared.',
1517474233
);
}
Expand Down
Loading

0 comments on commit 2ee183d

Please sign in to comment.