Skip to content

Commit

Permalink
fix: Allow uuid as path source in materialized path strategy
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
andreakeesys committed Nov 25, 2024
1 parent 090ce9a commit 49d2e29
Show file tree
Hide file tree
Showing 6 changed files with 398 additions and 50 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ a release.

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

## [3.17.1] - 2024-10-07
### Fixed
Expand Down
32 changes: 19 additions & 13 deletions src/Tree/Document/MongoDB/Repository/AbstractTreeRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,25 +72,25 @@ public function __construct(DocumentManager $em, UnitOfWork $uow, ClassMetadata
}

/**
* Sets the RepositoryUtilsInterface instance
* Returns the RepositoryUtilsInterface instance
*
* @return $this
* @return RepositoryUtilsInterface|null
*/
public function setRepoUtils(RepositoryUtilsInterface $repoUtils)
public function getRepoUtils()
{
$this->repoUtils = $repoUtils;

return $this;
return $this->repoUtils;
}

/**
* Returns the RepositoryUtilsInterface instance
* Sets the RepositoryUtilsInterface instance
*
* @return RepositoryUtilsInterface|null
* @return $this
*/
public function getRepoUtils()
public function setRepoUtils(RepositoryUtilsInterface $repoUtils)
{
return $this->repoUtils;
$this->repoUtils = $repoUtils;

return $this;
}

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

/**
* @see \Gedmo\Tree\RepositoryUtilsInterface::setChildrenIndex
* @see RepositoryUtilsInterface::setChildrenIndex
*/
public function setChildrenIndex($childrenIndex)
{
$this->repoUtils->setChildrenIndex($childrenIndex);
}

/**
* @see \Gedmo\Tree\RepositoryUtilsInterface::getChildrenIndex
* @see RepositoryUtilsInterface::getChildrenIndex
*/
public function getChildrenIndex()
{
Expand Down Expand Up @@ -179,7 +179,13 @@ abstract public function getNodesHierarchyQuery($node = null, $direct = false, a
*
* @return Builder
*/
abstract public function getChildrenQueryBuilder($node = null, $direct = false, $sortByField = null, $direction = 'ASC', $includeNode = false);
abstract public function getChildrenQueryBuilder(
$node = null,
$direct = false,
$sortByField = null,
$direction = 'ASC',
$includeNode = false
);

/**
* Get list of children followed by given $node. This returns a Query
Expand Down
80 changes: 43 additions & 37 deletions src/Tree/Entity/Repository/AbstractTreeRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,25 +73,25 @@ public function __construct(EntityManagerInterface $em, ClassMetadata $class)
}

/**
* Sets the RepositoryUtilsInterface instance
* Returns the RepositoryUtilsInterface instance
*
* @return static
* @return RepositoryUtilsInterface|null
*/
public function setRepoUtils(RepositoryUtilsInterface $repoUtils)
public function getRepoUtils()
{
$this->repoUtils = $repoUtils;

return $this;
return $this->repoUtils;
}

/**
* Returns the RepositoryUtilsInterface instance
* Sets the RepositoryUtilsInterface instance
*
* @return RepositoryUtilsInterface|null
* @return static
*/
public function getRepoUtils()
public function setRepoUtils(RepositoryUtilsInterface $repoUtils)
{
return $this->repoUtils;
$this->repoUtils = $repoUtils;

return $this;
}

public function childCount($node = null, $direct = false)
Expand Down Expand Up @@ -131,39 +131,60 @@ public function childCount($node = null, $direct = false)
}

/**
* @see \Gedmo\Tree\RepositoryUtilsInterface::childrenHierarchy
* Get list of children followed by given $node. This returns a QueryBuilder object
*
* @param object|null $node If null, all tree nodes will be taken
* @param bool $direct True to take only direct children
* @param string|string[]|null $sortByField Field name or array of fields names to sort by
* @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
* @param bool $includeNode Include the root node in results?
*
* @return QueryBuilder QueryBuilder object
*
* @phpstan-param 'asc'|'desc'|'ASC'|'DESC'|array<int, 'asc'|'desc'|'ASC'|'DESC'> $direction
*/
abstract public function getChildrenQueryBuilder(
$node = null,
$direct = false,
$sortByField = null,
$direction = 'ASC',
$includeNode = false
);

/**
* @see RepositoryUtilsInterface::childrenHierarchy
*/
public function childrenHierarchy($node = null, $direct = false, array $options = [], $includeNode = false)
{
return $this->repoUtils->childrenHierarchy($node, $direct, $options, $includeNode);
}

/**
* @see \Gedmo\Tree\RepositoryUtilsInterface::buildTree
* @see RepositoryUtilsInterface::buildTree
*/
public function buildTree(array $nodes, array $options = [])
{
return $this->repoUtils->buildTree($nodes, $options);
}

/**
* @see \Gedmo\Tree\RepositoryUtilsInterface::buildTreeArray
* @see RepositoryUtilsInterface::buildTreeArray
*/
public function buildTreeArray(array $nodes)
{
return $this->repoUtils->buildTreeArray($nodes);
}

/**
* @see \Gedmo\Tree\RepositoryUtilsInterface::setChildrenIndex
* @see RepositoryUtilsInterface::setChildrenIndex
*/
public function setChildrenIndex($childrenIndex)
{
$this->repoUtils->setChildrenIndex($childrenIndex);
}

/**
* @see \Gedmo\Tree\RepositoryUtilsInterface::getChildrenIndex
* @see RepositoryUtilsInterface::getChildrenIndex
*/
public function getChildrenIndex()
{
Expand Down Expand Up @@ -215,34 +236,27 @@ abstract public function getNodesHierarchyQueryBuilder($node = null, $direct = f
abstract public function getNodesHierarchyQuery($node = null, $direct = false, array $options = [], $includeNode = false);

/**
* Get list of children followed by given $node. This returns a QueryBuilder object
* Get list of children followed by given $node. This returns a Query
*
* @param object|null $node If null, all tree nodes will be taken
* @param bool $direct True to take only direct children
* @param string|string[]|null $sortByField Field name or array of fields names to sort by
* @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
* @param bool $includeNode Include the root node in results?
*
* @return QueryBuilder QueryBuilder object
* @return Query Query object
*
* @phpstan-param 'asc'|'desc'|'ASC'|'DESC'|array<int, 'asc'|'desc'|'ASC'|'DESC'> $direction
*/
abstract public function getChildrenQueryBuilder($node = null, $direct = false, $sortByField = null, $direction = 'ASC', $includeNode = false);
abstract public function getChildrenQuery($node = null, $direct = false, $sortByField = null, $direction = 'ASC', $includeNode = false);

/**
* Get list of children followed by given $node. This returns a Query
*
* @param object|null $node If null, all tree nodes will be taken
* @param bool $direct True to take only direct children
* @param string|string[]|null $sortByField Field name or array of fields names to sort by
* @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
* @param bool $includeNode Include the root node in results?
*
* @return Query Query object
* Checks if current repository is right
* for currently used tree strategy
*
* @phpstan-param 'asc'|'desc'|'ASC'|'DESC'|array<int, 'asc'|'desc'|'ASC'|'DESC'> $direction
* @return bool
*/
abstract public function getChildrenQuery($node = null, $direct = false, $sortByField = null, $direction = 'ASC', $includeNode = false);
abstract protected function validate();

/**
* @return QueryBuilder
Expand All @@ -251,12 +265,4 @@ protected function getQueryBuilder()
{
return $this->getEntityManager()->createQueryBuilder();
}

/**
* Checks if current repository is right
* for currently used tree strategy
*
* @return bool
*/
abstract protected function validate();
}
1 change: 1 addition & 0 deletions src/Tree/Mapping/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class Validator
'string',
'int',
'float',
'uuid',
];

/**
Expand Down
Loading

0 comments on commit 49d2e29

Please sign in to comment.