Skip to content

Commit

Permalink
Merge branch 'hotfix/v2.1.16'
Browse files Browse the repository at this point in the history
  • Loading branch information
ambroisemaupate committed Jun 1, 2023
2 parents 3caa051 + 67b3ea4 commit 4e0f81b
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 25 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## [v2.1.16](https://github.com/roadiz/core-bundle-dev-app/compare/v2.1.15...v2.1.16) (2023-06-01)


### Bug Fixes

* Do not prevent setting parent with not the same class ([3b5996d](https://github.com/roadiz/core-bundle-dev-app/commit/3b5996dc804510bed29b5f20ef542e933f101561))
* **LeafInterface:** Do not test exact class when setting LeafInterface parent to allow doctrine proxies. ([56ed76d](https://github.com/roadiz/core-bundle-dev-app/commit/56ed76d401fee87813e0cbb86ac92ec130a46752))

## [v2.1.15](https://github.com/roadiz/core-bundle-dev-app/compare/v2.1.14...v2.1.15) (2023-05-24)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function getParent(): ?LeafInterface;
public function getParents(): array;

/**
* @param static|null $parent
* @param LeafInterface|null $parent
* @return $this
*/
public function setParent(?LeafInterface $parent = null): static;
Expand Down
23 changes: 2 additions & 21 deletions lib/Models/src/Roadiz/Core/AbstractEntities/LeafTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function addChild(LeafInterface $child): static
return $this;
}
/**
* @param static $child
* @param LeafInterface $child
* @return $this
*/
public function removeChild(LeafInterface $child): static
Expand All @@ -65,26 +65,7 @@ public function getParent(): ?LeafInterface
}

/**
* @param static|null $parent
* @return $this
*/
public function setParent(?LeafInterface $parent = null): static
{
if ($parent === $this) {
throw new \InvalidArgumentException('An entity cannot have itself as a parent.');
}
if (get_class($parent) !== get_class($this)) {
throw new \InvalidArgumentException('Parent must be the same class as the current entity.');
}

$this->parent = $parent;
$this->parent?->addChild($this);

return $this;
}

/**
* @return static[]
* @return LeafInterface[]
*/
public function getParents(): array
{
Expand Down
2 changes: 1 addition & 1 deletion lib/RoadizCoreBundle/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ services:
autowire: true # Automatically injects dependencies in your services.
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
bind:
$cmsVersion: '2.1.15'
$cmsVersion: '2.1.16'
$appVersion: '%roadiz_core.app_version%'
$cmsVersionPrefix: 'main'
$staticDomain: '%roadiz_core.static_domain_name%'
Expand Down
18 changes: 17 additions & 1 deletion lib/RoadizCoreBundle/src/Entity/Folder.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,11 +339,27 @@ public function getFullPath(): string
$path = [];

foreach ($parents as $parent) {
$path[] = $parent->getFolderName();
if ($parent instanceof FolderInterface) {
$path[] = $parent->getFolderName();
}
}

$path[] = $this->getFolderName();

return implode('/', $path);
}

public function setParent(?LeafInterface $parent = null): static
{
if ($parent === $this) {
throw new \InvalidArgumentException('An entity cannot have itself as a parent.');
}
if (null !== $parent && !$parent instanceof Folder) {
throw new \InvalidArgumentException('A folder can only have a folder as a parent.');
}
$this->parent = $parent;
$this->parent?->addChild($this);

return $this;
}
}
14 changes: 14 additions & 0 deletions lib/RoadizCoreBundle/src/Entity/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,20 @@ public function __clone()
}
}

public function setParent(?LeafInterface $parent = null): static
{
if ($parent === $this) {
throw new \InvalidArgumentException('An entity cannot have itself as a parent.');
}
if (null !== $parent && !($parent instanceof Node)) {
throw new \InvalidArgumentException('A node can only have a Node as a parent.');
}
$this->parent = $parent;
$this->parent?->addChild($this);

return $this;
}

/**
* @return string
*/
Expand Down
18 changes: 17 additions & 1 deletion lib/RoadizCoreBundle/src/Entity/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,9 @@ public function getFullPath(): string
$path = [];

foreach ($parents as $parent) {
$path[] = $parent->getTagName();
if ($parent instanceof Tag) {
$path[] = $parent->getTagName();
}
}

$path[] = $this->getTagName();
Expand Down Expand Up @@ -446,4 +448,18 @@ public function getDocuments(): array
$this->getTranslatedTags()->first()->getDocuments() :
[];
}

public function setParent(?LeafInterface $parent = null): static
{
if ($parent === $this) {
throw new \InvalidArgumentException('An entity cannot have itself as a parent.');
}
if (null !== $parent && !$parent instanceof Tag) {
throw new \InvalidArgumentException('A tag can only have a Tag entity as a parent');
}
$this->parent = $parent;
$this->parent?->addChild($this);

return $this;
}
}

0 comments on commit 4e0f81b

Please sign in to comment.