Skip to content

Commit

Permalink
1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
bupy7 committed Jul 19, 2019
1 parent e8dea36 commit 28c1702
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
doctrine-nested-set
===================

X.X.X [XXXX-XX-XX]
1.0.1 [2019-07-20]
------------------

- Fix: The "rightKey select" bug.
- Fix: The documentation mistakes. (nepster-web)

1.0.0 [2019-06-04]
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "bupy7/doctrine-nested-set",
"description": "Nested sets for Doctrine ORM",
"version": "1.0.0",
"version": "1.0.1",
"license": "BSD-3-Clause",
"keywords": [
"doctrine",
Expand Down
29 changes: 19 additions & 10 deletions src/NestedSetService.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,16 @@ private function addAsChild(NestedSetInterface $child, NestedSetInterface $paren
->setLeftKey($parent->getRightKey())
->setRightKey($child->getLeftKey() + 1);

$entities = $this->repository->findGreatestByKeysValue($parent->getRightKey());
$rightKey = $parent->getRightKey();

$entities = $this->repository->findGreatestByKeysValue($rightKey);

foreach ($entities as $entity) {
if ($entity->getLeftKey() >= $parent->getRightKey()) {
if ($entity->getLeftKey() >= $rightKey) {
$entity->setLeftKey($entity->getLeftKey() + 2);
}

if ($entity->getRightKey() >= $parent->getRightKey()) {
if ($entity->getRightKey() >= $rightKey) {
$entity->setRightKey($entity->getRightKey() + 2);
}
}
Expand All @@ -130,13 +133,16 @@ private function addAsChild(NestedSetInterface $child, NestedSetInterface $paren
*/
private function removeOne(NestedSetInterface $child): void
{
$entities = $this->repository->findGreatestByKeysValue($child->getRightKey());
$rightKey = $child->getRightKey();

$entities = $this->repository->findGreatestByKeysValue($rightKey);

foreach ($entities as $entity) {
if ($entity->getLeftKey() >= $child->getRightKey()) {
if ($entity->getLeftKey() >= $rightKey) {
$entity->setLeftKey($entity->getLeftKey() - 2);
}

if ($entity->getRightKey() >= $child->getRightKey()) {
if ($entity->getRightKey() >= $rightKey) {
$entity->setRightKey($entity->getRightKey() - 2);
}
}
Expand All @@ -157,14 +163,17 @@ private function removeWithDescendants(NestedSetInterface $child): void
$this->em->remove($entity);
}

$entities = $this->repository->findGreatestByKeysValue($child->getRightKey());
$diff = $child->getRightKey() - $child->getLeftKey() + 1;
$rightKey = $child->getRightKey();
$diff = $rightKey - $child->getLeftKey() + 1;

$entities = $this->repository->findGreatestByKeysValue($rightKey);

foreach ($entities as $entity) {
if ($entity->getLeftKey() >= $child->getRightKey()) {
if ($entity->getLeftKey() >= $rightKey) {
$entity->setLeftKey($entity->getLeftKey() - $diff);
}

if ($entity->getRightKey() >= $child->getRightKey()) {
if ($entity->getRightKey() >= $rightKey) {
$entity->setRightKey($entity->getRightKey() - $diff);
}
}
Expand Down

0 comments on commit 28c1702

Please sign in to comment.