Browse Source

Fix populateTree() wrong secondary using of variable $depth. Close #4

tags/v1.0.5 v1.0.5
PaulZi 8 years ago
parent
commit
2d5aaaec78
  1. 6
      NestedSetsBehavior.php
  2. 67
      composer.lock
  3. 4
      tests/NestedSetsBehaviorTestCase.php

6
NestedSetsBehavior.php

@ -226,8 +226,10 @@ class NestedSetsBehavior extends Behavior
$nodes = $this->getDescendants($depth)->all(); $nodes = $this->getDescendants($depth)->all();
} }
$key = $this->owner->getAttribute($this->leftAttribute);
$relates = []; $relates = [];
$parents = [$this->owner->getAttribute($this->leftAttribute)]; $relates[$key] = [];
$parents = [$key];
$prev = $this->owner->getAttribute($this->depthAttribute); $prev = $this->owner->getAttribute($this->depthAttribute);
foreach($nodes as $node) foreach($nodes as $node)
{ {
@ -251,8 +253,6 @@ class NestedSetsBehavior extends Behavior
$key = $node->getAttribute($this->leftAttribute); $key = $node->getAttribute($this->leftAttribute);
if (isset($relates[$key])) { if (isset($relates[$key])) {
$node->populateRelation('children', $relates[$key]); $node->populateRelation('children', $relates[$key]);
} elseif ($depth === null) {
$node->populateRelation('children', []);
} }
} }

67
composer.lock generated

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"hash": "313a11363bcb8d1cc8b43c73b052d404", "hash": "a4a6cd529883c816c9665d9c3361c66b",
"content-hash": "c2618cb72efb684ac68b4e708a48ecb4", "content-hash": "c2618cb72efb684ac68b4e708a48ecb4",
"packages": [ "packages": [
{ {
@ -43,12 +43,12 @@
"version": "3.2.7", "version": "3.2.7",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/RobinHerbots/jquery.inputmask.git", "url": "https://github.com/RobinHerbots/Inputmask.git",
"reference": "5a72c563b502b8e05958a524cdfffafe9987be38" "reference": "5a72c563b502b8e05958a524cdfffafe9987be38"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/RobinHerbots/jquery.inputmask/zipball/5a72c563b502b8e05958a524cdfffafe9987be38", "url": "https://api.github.com/repos/RobinHerbots/Inputmask/zipball/5a72c563b502b8e05958a524cdfffafe9987be38",
"reference": "5a72c563b502b8e05958a524cdfffafe9987be38", "reference": "5a72c563b502b8e05958a524cdfffafe9987be38",
"shasum": "" "shasum": ""
}, },
@ -148,16 +148,16 @@
}, },
{ {
"name": "cebe/markdown", "name": "cebe/markdown",
"version": "1.1.0", "version": "1.1.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/cebe/markdown.git", "url": "https://github.com/cebe/markdown.git",
"reference": "54a2c49de31cc44e864ebf0500a35ef21d0010b2" "reference": "c30eb5e01fe021cc5bba2f9ee0eeef96d4931166"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/cebe/markdown/zipball/54a2c49de31cc44e864ebf0500a35ef21d0010b2", "url": "https://api.github.com/repos/cebe/markdown/zipball/c30eb5e01fe021cc5bba2f9ee0eeef96d4931166",
"reference": "54a2c49de31cc44e864ebf0500a35ef21d0010b2", "reference": "c30eb5e01fe021cc5bba2f9ee0eeef96d4931166",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -204,7 +204,7 @@
"markdown", "markdown",
"markdown-extra" "markdown-extra"
], ],
"time": "2015-03-06 05:28:07" "time": "2016-09-14 20:40:20"
}, },
{ {
"name": "ezyang/htmlpurifier", "name": "ezyang/htmlpurifier",
@ -503,16 +503,16 @@
}, },
{ {
"name": "phpdocumentor/reflection-docblock", "name": "phpdocumentor/reflection-docblock",
"version": "3.1.0", "version": "3.1.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git",
"reference": "9270140b940ff02e58ec577c237274e92cd40cdd" "reference": "8331b5efe816ae05461b7ca1e721c01b46bafb3e"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/9270140b940ff02e58ec577c237274e92cd40cdd", "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/8331b5efe816ae05461b7ca1e721c01b46bafb3e",
"reference": "9270140b940ff02e58ec577c237274e92cd40cdd", "reference": "8331b5efe816ae05461b7ca1e721c01b46bafb3e",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -544,7 +544,7 @@
} }
], ],
"description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.",
"time": "2016-06-10 09:48:41" "time": "2016-09-30 07:12:33"
}, },
{ {
"name": "phpdocumentor/type-resolver", "name": "phpdocumentor/type-resolver",
@ -1203,23 +1203,23 @@
}, },
{ {
"name": "sebastian/environment", "name": "sebastian/environment",
"version": "1.3.7", "version": "1.3.8",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/sebastianbergmann/environment.git", "url": "https://github.com/sebastianbergmann/environment.git",
"reference": "4e8f0da10ac5802913afc151413bc8c53b6c2716" "reference": "be2c607e43ce4c89ecd60e75c6a85c126e754aea"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/4e8f0da10ac5802913afc151413bc8c53b6c2716", "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/be2c607e43ce4c89ecd60e75c6a85c126e754aea",
"reference": "4e8f0da10ac5802913afc151413bc8c53b6c2716", "reference": "be2c607e43ce4c89ecd60e75c6a85c126e754aea",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": ">=5.3.3" "php": "^5.3.3 || ^7.0"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "~4.4" "phpunit/phpunit": "^4.8 || ^5.0"
}, },
"type": "library", "type": "library",
"extra": { "extra": {
@ -1249,7 +1249,7 @@
"environment", "environment",
"hhvm" "hhvm"
], ],
"time": "2016-05-17 03:18:57" "time": "2016-08-18 05:49:44"
}, },
{ {
"name": "sebastian/exporter", "name": "sebastian/exporter",
@ -1459,16 +1459,16 @@
}, },
{ {
"name": "symfony/yaml", "name": "symfony/yaml",
"version": "v3.1.2", "version": "v3.1.5",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/yaml.git", "url": "https://github.com/symfony/yaml.git",
"reference": "2884c26ce4c1d61aebf423a8b912950fe7c764de" "reference": "368b9738d4033c8b93454cb0dbd45d305135a6d3"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/yaml/zipball/2884c26ce4c1d61aebf423a8b912950fe7c764de", "url": "https://api.github.com/repos/symfony/yaml/zipball/368b9738d4033c8b93454cb0dbd45d305135a6d3",
"reference": "2884c26ce4c1d61aebf423a8b912950fe7c764de", "reference": "368b9738d4033c8b93454cb0dbd45d305135a6d3",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1504,32 +1504,33 @@
], ],
"description": "Symfony Yaml Component", "description": "Symfony Yaml Component",
"homepage": "https://symfony.com", "homepage": "https://symfony.com",
"time": "2016-06-29 05:41:56" "time": "2016-09-25 08:27:07"
}, },
{ {
"name": "webmozart/assert", "name": "webmozart/assert",
"version": "1.0.2", "version": "1.1.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/webmozart/assert.git", "url": "https://github.com/webmozart/assert.git",
"reference": "30eed06dd6bc88410a4ff7f77b6d22f3ce13dbde" "reference": "bb2d123231c095735130cc8f6d31385a44c7b308"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/webmozart/assert/zipball/30eed06dd6bc88410a4ff7f77b6d22f3ce13dbde", "url": "https://api.github.com/repos/webmozart/assert/zipball/bb2d123231c095735130cc8f6d31385a44c7b308",
"reference": "30eed06dd6bc88410a4ff7f77b6d22f3ce13dbde", "reference": "bb2d123231c095735130cc8f6d31385a44c7b308",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": ">=5.3.3" "php": "^5.3.3|^7.0"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^4.6" "phpunit/phpunit": "^4.6",
"sebastian/version": "^1.0.1"
}, },
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "1.0-dev" "dev-master": "1.2-dev"
} }
}, },
"autoload": { "autoload": {
@ -1553,7 +1554,7 @@
"check", "check",
"validate" "validate"
], ],
"time": "2015-08-24 13:29:44" "time": "2016-08-09 15:02:57"
} }
], ],
"aliases": [], "aliases": [],

4
tests/NestedSetsBehaviorTestCase.php

@ -132,6 +132,10 @@ class NestedSetsBehaviorTestCase extends BaseTestCase
$node = Node::findOne(19); $node = Node::findOne(19);
$node->populateTree(); $node->populateTree();
$this->assertEquals(true, $node->isRelationPopulated('children')); $this->assertEquals(true, $node->isRelationPopulated('children'));
$node = Node::findOne(19);
$node->populateTree(1);
$this->assertEquals(true, $node->isRelationPopulated('children'));
} }
public function testIsRoot() public function testIsRoot()

Loading…
Cancel
Save