Skip to content

Commit 49d2e29

Browse files
committed
fix: Allow uuid as path source in materialized path strategy
- Fixes a path validation error when using an Uuid as primary key in an entity and also as TreePathSource in the MaterializedPath strategy - Added a test to confirm the regression if 'uuid' is removed from the allowed types list in Validator.php - chore: PHPCS fixes
1 parent 090ce9a commit 49d2e29

File tree

6 files changed

+398
-50
lines changed

6 files changed

+398
-50
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ a release.
2323

2424
### Fixed
2525
- Fix regression with `doctrine/dbal` >= 4.0 that caused MariaDB to improperly attempt LONGTEXT casting in `TranslationWalker` (issue #2887)
26+
- Tree: allow usage of UuidV7 as path source with the materialized path strategy
2627

2728
## [3.17.1] - 2024-10-07
2829
### Fixed

src/Tree/Document/MongoDB/Repository/AbstractTreeRepository.php

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,25 +72,25 @@ public function __construct(DocumentManager $em, UnitOfWork $uow, ClassMetadata
7272
}
7373

7474
/**
75-
* Sets the RepositoryUtilsInterface instance
75+
* Returns the RepositoryUtilsInterface instance
7676
*
77-
* @return $this
77+
* @return RepositoryUtilsInterface|null
7878
*/
79-
public function setRepoUtils(RepositoryUtilsInterface $repoUtils)
79+
public function getRepoUtils()
8080
{
81-
$this->repoUtils = $repoUtils;
82-
83-
return $this;
81+
return $this->repoUtils;
8482
}
8583

8684
/**
87-
* Returns the RepositoryUtilsInterface instance
85+
* Sets the RepositoryUtilsInterface instance
8886
*
89-
* @return RepositoryUtilsInterface|null
87+
* @return $this
9088
*/
91-
public function getRepoUtils()
89+
public function setRepoUtils(RepositoryUtilsInterface $repoUtils)
9290
{
93-
return $this->repoUtils;
91+
$this->repoUtils = $repoUtils;
92+
93+
return $this;
9494
}
9595

9696
public function childrenHierarchy($node = null, $direct = false, array $options = [], $includeNode = false)
@@ -104,15 +104,15 @@ public function buildTree(array $nodes, array $options = [])
104104
}
105105

106106
/**
107-
* @see \Gedmo\Tree\RepositoryUtilsInterface::setChildrenIndex
107+
* @see RepositoryUtilsInterface::setChildrenIndex
108108
*/
109109
public function setChildrenIndex($childrenIndex)
110110
{
111111
$this->repoUtils->setChildrenIndex($childrenIndex);
112112
}
113113

114114
/**
115-
* @see \Gedmo\Tree\RepositoryUtilsInterface::getChildrenIndex
115+
* @see RepositoryUtilsInterface::getChildrenIndex
116116
*/
117117
public function getChildrenIndex()
118118
{
@@ -179,7 +179,13 @@ abstract public function getNodesHierarchyQuery($node = null, $direct = false, a
179179
*
180180
* @return Builder
181181
*/
182-
abstract public function getChildrenQueryBuilder($node = null, $direct = false, $sortByField = null, $direction = 'ASC', $includeNode = false);
182+
abstract public function getChildrenQueryBuilder(
183+
$node = null,
184+
$direct = false,
185+
$sortByField = null,
186+
$direction = 'ASC',
187+
$includeNode = false
188+
);
183189

184190
/**
185191
* Get list of children followed by given $node. This returns a Query

src/Tree/Entity/Repository/AbstractTreeRepository.php

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -73,25 +73,25 @@ public function __construct(EntityManagerInterface $em, ClassMetadata $class)
7373
}
7474

7575
/**
76-
* Sets the RepositoryUtilsInterface instance
76+
* Returns the RepositoryUtilsInterface instance
7777
*
78-
* @return static
78+
* @return RepositoryUtilsInterface|null
7979
*/
80-
public function setRepoUtils(RepositoryUtilsInterface $repoUtils)
80+
public function getRepoUtils()
8181
{
82-
$this->repoUtils = $repoUtils;
83-
84-
return $this;
82+
return $this->repoUtils;
8583
}
8684

8785
/**
88-
* Returns the RepositoryUtilsInterface instance
86+
* Sets the RepositoryUtilsInterface instance
8987
*
90-
* @return RepositoryUtilsInterface|null
88+
* @return static
9189
*/
92-
public function getRepoUtils()
90+
public function setRepoUtils(RepositoryUtilsInterface $repoUtils)
9391
{
94-
return $this->repoUtils;
92+
$this->repoUtils = $repoUtils;
93+
94+
return $this;
9595
}
9696

9797
public function childCount($node = null, $direct = false)
@@ -131,39 +131,60 @@ public function childCount($node = null, $direct = false)
131131
}
132132

133133
/**
134-
* @see \Gedmo\Tree\RepositoryUtilsInterface::childrenHierarchy
134+
* Get list of children followed by given $node. This returns a QueryBuilder object
135+
*
136+
* @param object|null $node If null, all tree nodes will be taken
137+
* @param bool $direct True to take only direct children
138+
* @param string|string[]|null $sortByField Field name or array of fields names to sort by
139+
* @param string|string[] $direction Sort order ('asc'|'desc'|'ASC'|'DESC'). If $sortByField is an array, this may also be an array with matching number of elements
140+
* @param bool $includeNode Include the root node in results?
141+
*
142+
* @return QueryBuilder QueryBuilder object
143+
*
144+
* @phpstan-param 'asc'|'desc'|'ASC'|'DESC'|array<int, 'asc'|'desc'|'ASC'|'DESC'> $direction
145+
*/
146+
abstract public function getChildrenQueryBuilder(
147+
$node = null,
148+
$direct = false,
149+
$sortByField = null,
150+
$direction = 'ASC',
151+
$includeNode = false
152+
);
153+
154+
/**
155+
* @see RepositoryUtilsInterface::childrenHierarchy
135156
*/
136157
public function childrenHierarchy($node = null, $direct = false, array $options = [], $includeNode = false)
137158
{
138159
return $this->repoUtils->childrenHierarchy($node, $direct, $options, $includeNode);
139160
}
140161

141162
/**
142-
* @see \Gedmo\Tree\RepositoryUtilsInterface::buildTree
163+
* @see RepositoryUtilsInterface::buildTree
143164
*/
144165
public function buildTree(array $nodes, array $options = [])
145166
{
146167
return $this->repoUtils->buildTree($nodes, $options);
147168
}
148169

149170
/**
150-
* @see \Gedmo\Tree\RepositoryUtilsInterface::buildTreeArray
171+
* @see RepositoryUtilsInterface::buildTreeArray
151172
*/
152173
public function buildTreeArray(array $nodes)
153174
{
154175
return $this->repoUtils->buildTreeArray($nodes);
155176
}
156177

157178
/**
158-
* @see \Gedmo\Tree\RepositoryUtilsInterface::setChildrenIndex
179+
* @see RepositoryUtilsInterface::setChildrenIndex
159180
*/
160181
public function setChildrenIndex($childrenIndex)
161182
{
162183
$this->repoUtils->setChildrenIndex($childrenIndex);
163184
}
164185

165186
/**
166-
* @see \Gedmo\Tree\RepositoryUtilsInterface::getChildrenIndex
187+
* @see RepositoryUtilsInterface::getChildrenIndex
167188
*/
168189
public function getChildrenIndex()
169190
{
@@ -215,34 +236,27 @@ abstract public function getNodesHierarchyQueryBuilder($node = null, $direct = f
215236
abstract public function getNodesHierarchyQuery($node = null, $direct = false, array $options = [], $includeNode = false);
216237

217238
/**
218-
* Get list of children followed by given $node. This returns a QueryBuilder object
239+
* Get list of children followed by given $node. This returns a Query
219240
*
220241
* @param object|null $node If null, all tree nodes will be taken
221242
* @param bool $direct True to take only direct children
222243
* @param string|string[]|null $sortByField Field name or array of fields names to sort by
223244
* @param string|string[] $direction Sort order ('asc'|'desc'|'ASC'|'DESC'). If $sortByField is an array, this may also be an array with matching number of elements
224245
* @param bool $includeNode Include the root node in results?
225246
*
226-
* @return QueryBuilder QueryBuilder object
247+
* @return Query Query object
227248
*
228249
* @phpstan-param 'asc'|'desc'|'ASC'|'DESC'|array<int, 'asc'|'desc'|'ASC'|'DESC'> $direction
229250
*/
230-
abstract public function getChildrenQueryBuilder($node = null, $direct = false, $sortByField = null, $direction = 'ASC', $includeNode = false);
251+
abstract public function getChildrenQuery($node = null, $direct = false, $sortByField = null, $direction = 'ASC', $includeNode = false);
231252

232253
/**
233-
* Get list of children followed by given $node. This returns a Query
234-
*
235-
* @param object|null $node If null, all tree nodes will be taken
236-
* @param bool $direct True to take only direct children
237-
* @param string|string[]|null $sortByField Field name or array of fields names to sort by
238-
* @param string|string[] $direction Sort order ('asc'|'desc'|'ASC'|'DESC'). If $sortByField is an array, this may also be an array with matching number of elements
239-
* @param bool $includeNode Include the root node in results?
240-
*
241-
* @return Query Query object
254+
* Checks if current repository is right
255+
* for currently used tree strategy
242256
*
243-
* @phpstan-param 'asc'|'desc'|'ASC'|'DESC'|array<int, 'asc'|'desc'|'ASC'|'DESC'> $direction
257+
* @return bool
244258
*/
245-
abstract public function getChildrenQuery($node = null, $direct = false, $sortByField = null, $direction = 'ASC', $includeNode = false);
259+
abstract protected function validate();
246260

247261
/**
248262
* @return QueryBuilder
@@ -251,12 +265,4 @@ protected function getQueryBuilder()
251265
{
252266
return $this->getEntityManager()->createQueryBuilder();
253267
}
254-
255-
/**
256-
* Checks if current repository is right
257-
* for currently used tree strategy
258-
*
259-
* @return bool
260-
*/
261-
abstract protected function validate();
262268
}

src/Tree/Mapping/Validator.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class Validator
6060
'string',
6161
'int',
6262
'float',
63+
'uuid',
6364
];
6465

6566
/**

0 commit comments

Comments
 (0)