From 927fd8f00953d6dee70abb8ff451bc80e34ff545 Mon Sep 17 00:00:00 2001 From: SlyDeath Date: Tue, 16 May 2017 14:11:42 +0300 Subject: [PATCH 01/51] Fixes the join problem When SQL error "key" is ambiguous --- src/QueryBuilder.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/QueryBuilder.php b/src/QueryBuilder.php index 4baa70a..d629c83 100644 --- a/src/QueryBuilder.php +++ b/src/QueryBuilder.php @@ -86,7 +86,7 @@ public function whereIsRoot() */ public function whereAncestorOf($id, $andSelf = false, $boolean = 'and') { - $keyName = $this->model->getKeyName(); + $keyName = $this->model->getQualifiedKeyName(); if (NestedSet::isNode($id)) { $value = '?'; @@ -108,13 +108,13 @@ public function whereAncestorOf($id, $andSelf = false, $boolean = 'and') $value = '('.$valueQuery->toSql().')'; } - $this->query->whereNested(function ($inner) use ($value, $andSelf, $id) { + $this->query->whereNested(function ($inner) use ($value, $andSelf, $id, $keyName) { list($lft, $rgt) = $this->wrappedColumns(); $inner->whereRaw("{$value} between {$lft} and {$rgt}"); if ( ! $andSelf) { - $inner->where($this->model->getKeyName(), '<>', $id); + $inner->where($keyName, '<>', $id); } }, $boolean); From b0a05e0d687e3435eed8ba42a334657cb8a106db Mon Sep 17 00:00:00 2001 From: SlyDeath Date: Mon, 22 May 2017 11:02:37 +0300 Subject: [PATCH 02/51] Update QueryBuilder.php --- src/QueryBuilder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/QueryBuilder.php b/src/QueryBuilder.php index d629c83..5029767 100644 --- a/src/QueryBuilder.php +++ b/src/QueryBuilder.php @@ -86,7 +86,7 @@ public function whereIsRoot() */ public function whereAncestorOf($id, $andSelf = false, $boolean = 'and') { - $keyName = $this->model->getQualifiedKeyName(); + $keyName = $this->model->getTable() . '.' . $this->model->getKeyName(); if (NestedSet::isNode($id)) { $value = '?'; From 85131b2c984f2ceeb57b9a4175fcb2d782777908 Mon Sep 17 00:00:00 2001 From: SlyDeath Date: Tue, 4 Jul 2017 13:30:18 +0300 Subject: [PATCH 03/51] Update QueryBuilder.php --- src/QueryBuilder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/QueryBuilder.php b/src/QueryBuilder.php index 5029767..d2d2831 100644 --- a/src/QueryBuilder.php +++ b/src/QueryBuilder.php @@ -100,7 +100,7 @@ public function whereAncestorOf($id, $andSelf = false, $boolean = 'and') ->toBase() ->select("_.".$this->model->getRgtName()) ->from($this->model->getTable().' as _') - ->where($keyName, '=', $id) + ->where($this->model->getKeyName(), '=', $id) ->limit(1); $this->query->mergeBindings($valueQuery); From c739a2d0f27b5d78954b3127c3d683977e69609f Mon Sep 17 00:00:00 2001 From: Alexander Kalnoy Date: Wed, 30 Aug 2017 22:13:38 +0300 Subject: [PATCH 04/51] Minimum stability --- composer.json | 2 -- 1 file changed, 2 deletions(-) diff --git a/composer.json b/composer.json index efa2656..ee536c3 100644 --- a/composer.json +++ b/composer.json @@ -28,8 +28,6 @@ "phpunit/phpunit": "4.8.*" }, - "minimum-stability": "dev", - "extra": { "branch-alias": { "dev-master": "v4.2.x-dev" From 0adbe74307fe614eb71b4f67caccf6f3758715a9 Mon Sep 17 00:00:00 2001 From: Alexander Kalnoy Date: Wed, 30 Aug 2017 22:16:05 +0300 Subject: [PATCH 05/51] Bump minor version --- CHANGELOG.markdown | 2 +- README.markdown | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.markdown b/CHANGELOG.markdown index e1d837b..1352a97 100644 --- a/CHANGELOG.markdown +++ b/CHANGELOG.markdown @@ -1,4 +1,4 @@ -### 4.2.8 +### 4.3.0 * Support Laravel 5.5 * Added `fixSubtree` and `rebuildSubtree` methods * Increased performance of tree rebuilding diff --git a/README.markdown b/README.markdown index 06ba4d7..d3fcfe0 100644 --- a/README.markdown +++ b/README.markdown @@ -6,7 +6,8 @@ This is a Laravel 4-5 package for working with trees in relational databases. -* **Laravel 5.2, 5.3, 5.4, 5.5** is supported since v4 +* **Laravel 5.5** is supported since v4.3 +* **Laravel 5.2, 5.3, 5.4** is supported since v4 * **Laravel 5.1** is supported in v3 * **Laravel 4** is supported in v2 From 892b9a730fbb70d16a66f58f8eb2a46164cb3609 Mon Sep 17 00:00:00 2001 From: Alexander Kalnoy Date: Sun, 26 Nov 2017 10:18:24 +0300 Subject: [PATCH 06/51] Fixed #252: nested eagers for ancestors and descendants are now loaded --- README.markdown | 15 ++++++++------- src/BaseRelation.php | 4 ---- tests/NodeTest.php | 2 -- tests/ScopedNodeTest.php | 9 ++++++++- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/README.markdown b/README.markdown index d3fcfe0..927eb61 100644 --- a/README.markdown +++ b/README.markdown @@ -572,17 +572,17 @@ protected function getScopeAttributes() } ``` -But now in order to execute some custom query, you need to provide attributes +But now, in order to execute some custom query, you need to provide attributes that are used for scoping: ```php MenuItem::scoped([ 'menu_id' => 5 ])->withDepth()->get(); // OK MenuItem::descendantsOf($id)->get(); // WRONG: returns nodes from other scope -MenuItem::scoped([ 'menu_id' => 5 ])->fixTree(); +MenuItem::scoped([ 'menu_id' => 5 ])->fixTree(); // OK ``` When requesting nodes using model instance, scopes applied automatically based -on the attributes of that model. See examples: +on the attributes of that model: ```php $node = MenuItem::findOrFail($id); @@ -596,12 +596,13 @@ To get scoped query builder using instance: $node->newScopedQuery(); ``` -Note, that scoping is not required when retrieving model by primary key -(since the key is unique): +#### Scoping and eager loading + +Always use scoped query when eager loading: ```php -$node = MenuItem::findOrFail($id); // OK -$node = MenuItem::scoped([ 'menu_id' => 5 ])->findOrFail(); // OK, but redundant +MenuItem::scoped([ 'menu_id' => 5])->with('descendants')->findOrFail($id); // OK +MenuItem::with('descendants')->findOrFail($id); // WRONG ``` Requirements diff --git a/src/BaseRelation.php b/src/BaseRelation.php index b09e031..6dbc064 100644 --- a/src/BaseRelation.php +++ b/src/BaseRelation.php @@ -154,10 +154,6 @@ public function getResults() */ public function addEagerConstraints(array $models) { - $model = reset($models); - - $this->query = $model->newScopedQuery(); - $this->query->whereNested(function (Builder $inner) use ($models) { // We will use this query in order to apply constraints to the // base query builder diff --git a/tests/NodeTest.php b/tests/NodeTest.php index 3f7bad0..6e23663 100644 --- a/tests/NodeTest.php +++ b/tests/NodeTest.php @@ -827,8 +827,6 @@ public function testRebuildSubtree() [ 'id' => '8' ], ]); - echo PHP_EOL.$fixed.PHP_EOL; - $this->assertTrue($fixed > 0); $this->assertTreeNotBroken(); diff --git a/tests/ScopedNodeTest.php b/tests/ScopedNodeTest.php index 0584ca7..dc7ea4f 100644 --- a/tests/ScopedNodeTest.php +++ b/tests/ScopedNodeTest.php @@ -98,6 +98,13 @@ public function testDescendants() $this->assertEquals(1, $result->count()); $this->assertEquals(5, $result->first()->getKey()); + + $node = MenuItem::scoped([ 'menu_id' => 1 ])->with('descendants')->find(2); + + $result = $node->descendants; + + $this->assertEquals(1, $result->count()); + $this->assertEquals(5, $result->first()->getKey()); } public function testAncestors() @@ -109,7 +116,7 @@ public function testAncestors() $this->assertEquals(1, $result->count()); $this->assertEquals(2, $result->first()->getKey()); - $node = MenuItem::with('ancestors')->find(5); + $node = MenuItem::scoped([ 'menu_id' => 1 ])->with('ancestors')->find(5); $result = $node->ancestors; From 9092b43d1c205f0209abce54ca79e6daebadc793 Mon Sep 17 00:00:00 2001 From: Martin Gelder Date: Wed, 31 Jan 2018 23:50:23 +0100 Subject: [PATCH 07/51] Remove hardcoded refs to "id" as PK @getDuplicatesQuery used "id" directly as primary key for the model. Changed to "{keyName}" notation. :-) --- src/QueryBuilder.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/QueryBuilder.php b/src/QueryBuilder.php index e75ed43..8f733ef 100644 --- a/src/QueryBuilder.php +++ b/src/QueryBuilder.php @@ -715,6 +715,7 @@ protected function getOdnessQuery() protected function getDuplicatesQuery() { $table = $this->wrappedTable(); + $keyName = $this->wrappedKey(); $firstAlias = 'c1'; $secondAlias = 'c2'; @@ -726,7 +727,7 @@ protected function getDuplicatesQuery() ->newNestedSetQuery($firstAlias) ->toBase() ->from($this->query->raw("{$table} as {$waFirst}, {$table} {$waSecond}")) - ->whereRaw("{$waFirst}.id < {$waSecond}.id") + ->whereRaw("{$waFirst}.{$keyName} < {$waSecond}.{$keyName}") ->whereNested(function (BaseQueryBuilder $inner) use ($waFirst, $waSecond) { list($lft, $rgt) = $this->wrappedColumns(); From 6151674d361dfa9b0801f57b8353bd0f4720888f Mon Sep 17 00:00:00 2001 From: Alexander Kalnoy Date: Sun, 4 Feb 2018 11:12:06 +0300 Subject: [PATCH 08/51] Bump version --- composer.json | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index ee536c3..986c8df 100644 --- a/composer.json +++ b/composer.json @@ -13,9 +13,9 @@ "require": { "php": ">=5.5.9", - "illuminate/support": "5.2 - 5.5", - "illuminate/database": "5.2 - 5.5", - "illuminate/events": "5.2 - 5.5" + "illuminate/support": "5.2 - 5.6", + "illuminate/database": "5.2 - 5.6", + "illuminate/events": "5.2 - 5.6" }, "autoload": { @@ -28,6 +28,9 @@ "phpunit/phpunit": "4.8.*" }, + "minimum-stability": "dev", + "prefer-stable": true, + "extra": { "branch-alias": { "dev-master": "v4.2.x-dev" From 65b08fb5ba757d063676f2c386fe9165afaf0d52 Mon Sep 17 00:00:00 2001 From: Alexander Kalnoy Date: Sun, 4 Feb 2018 11:23:42 +0300 Subject: [PATCH 09/51] Add blueprint macros --- CHANGELOG.markdown | 4 ++++ README.markdown | 18 ++++++++++++++++-- composer.json | 6 ++++++ src/NestedSetServiceProvider.php | 20 ++++++++++++++++++++ 4 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 src/NestedSetServiceProvider.php diff --git a/CHANGELOG.markdown b/CHANGELOG.markdown index 1352a97..36b8054 100644 --- a/CHANGELOG.markdown +++ b/CHANGELOG.markdown @@ -1,3 +1,7 @@ +### 4.3.1 +* Support Laravel 5.6 +* Added `nestedSet` and `dropNestedSet` blueprint macros + ### 4.3.0 * Support Laravel 5.5 * Added `fixSubtree` and `rebuildSubtree` methods diff --git a/README.markdown b/README.markdown index 927eb61..26041b7 100644 --- a/README.markdown +++ b/README.markdown @@ -6,7 +6,7 @@ This is a Laravel 4-5 package for working with trees in relational databases. -* **Laravel 5.5** is supported since v4.3 +* **Laravel 5.5, 5.6** is supported since v4.3 * **Laravel 5.2, 5.3, 5.4** is supported since v4 * **Laravel 5.1** is supported in v3 * **Laravel 4** is supported in v2 @@ -627,7 +627,21 @@ composer require kalnoy/nestedset #### The schema -You can use a method to add needed columns with default names: +For Laravel 5.5 and above users: + +```php +Schema::create('table', function (Blueprint $table) { + ... + $table->nestedSet(); +}); + +// To drop columns +Schema::table('table', function (Blueprint $table) { + $table->dropNestedSet(); +}); +``` + +For prior Laravel versions: ```php ... diff --git a/composer.json b/composer.json index 986c8df..ca3d6c6 100644 --- a/composer.json +++ b/composer.json @@ -34,6 +34,12 @@ "extra": { "branch-alias": { "dev-master": "v4.2.x-dev" + }, + + "laravel": { + "providers": [ + "Kalnoy\\Nestedset\\NestedSetServiceProvider" + ] } } } diff --git a/src/NestedSetServiceProvider.php b/src/NestedSetServiceProvider.php new file mode 100644 index 0000000..b4516f7 --- /dev/null +++ b/src/NestedSetServiceProvider.php @@ -0,0 +1,20 @@ + Date: Sun, 4 Feb 2018 11:47:28 +0300 Subject: [PATCH 10/51] Update --- README.markdown | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.markdown b/README.markdown index 26041b7..99ea692 100644 --- a/README.markdown +++ b/README.markdown @@ -385,6 +385,9 @@ position. Various constraints that can be applied to the query builder: - __whereIsRoot()__ to get only root nodes; +- __hasParent()__ to get non-root nodes; +- __whereIsLeaf()__ to get only leaves; +- __hasChildren()__ to get non-leave nodes; - __whereIsAfter($id)__ to get every node (not just siblings) that are after a node with specified id; - __whereIsBefore($id)__ to get every node that is before a node with specified id. From 3265da51ef71238fc2d086b54eef7a75dd15c665 Mon Sep 17 00:00:00 2001 From: Alexander Kalnoy Date: Sun, 4 Feb 2018 11:47:55 +0300 Subject: [PATCH 11/51] Update --- CHANGELOG.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.markdown b/CHANGELOG.markdown index 36b8054..ecae438 100644 --- a/CHANGELOG.markdown +++ b/CHANGELOG.markdown @@ -1,4 +1,4 @@ -### 4.3.1 +### 4.3.2 * Support Laravel 5.6 * Added `nestedSet` and `dropNestedSet` blueprint macros From e8b6883e39ff3fe51efff626665726b232e4f26a Mon Sep 17 00:00:00 2001 From: Alexander Kalnoy Date: Tue, 8 May 2018 11:17:53 +0300 Subject: [PATCH 12/51] Update README.markdown --- README.markdown | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.markdown b/README.markdown index 99ea692..30c7e71 100644 --- a/README.markdown +++ b/README.markdown @@ -13,8 +13,7 @@ This is a Laravel 4-5 package for working with trees in relational databases. Although this project is completely free for use, I appreciate any support! -- __[Donate via PayPal](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=5TJUM7FYU5VR2)__ -- My Visa: 4276 0700 1073 4244 +- __[Donate via PayPal](https://www.paypal.me/lazychaser)__ __Contents:__ From 82c543bb40affb5445db5d44ccafdeede3b15560 Mon Sep 17 00:00:00 2001 From: Marek Szymczuk Date: Tue, 4 Sep 2018 16:40:02 +0200 Subject: [PATCH 13/51] Support Laravel 5.7 --- CHANGELOG.markdown | 3 +++ README.markdown | 2 +- composer.json | 6 +++--- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.markdown b/CHANGELOG.markdown index ecae438..4463a38 100644 --- a/CHANGELOG.markdown +++ b/CHANGELOG.markdown @@ -1,3 +1,6 @@ +### 4.3.3 +* Support Laravel 5.7 + ### 4.3.2 * Support Laravel 5.6 * Added `nestedSet` and `dropNestedSet` blueprint macros diff --git a/README.markdown b/README.markdown index 30c7e71..d06553c 100644 --- a/README.markdown +++ b/README.markdown @@ -6,7 +6,7 @@ This is a Laravel 4-5 package for working with trees in relational databases. -* **Laravel 5.5, 5.6** is supported since v4.3 +* **Laravel 5.5, 5.6, 5.7** is supported since v4.3 * **Laravel 5.2, 5.3, 5.4** is supported since v4 * **Laravel 5.1** is supported in v3 * **Laravel 4** is supported in v2 diff --git a/composer.json b/composer.json index ca3d6c6..40c7aad 100644 --- a/composer.json +++ b/composer.json @@ -13,9 +13,9 @@ "require": { "php": ">=5.5.9", - "illuminate/support": "5.2 - 5.6", - "illuminate/database": "5.2 - 5.6", - "illuminate/events": "5.2 - 5.6" + "illuminate/support": "5.2 - 5.7", + "illuminate/database": "5.2 - 5.7", + "illuminate/events": "5.2 - 5.7" }, "autoload": { From dd9434d697ec0ce73831d1566ad23a444739d2b0 Mon Sep 17 00:00:00 2001 From: Killian Thomas Date: Tue, 25 Sep 2018 08:02:37 +0200 Subject: [PATCH 14/51] Fix "ambiguous column" issue when using whereAncestorOr or whereDescendantOf with additional join(s) If joins are made between the table using the NodeTrait and the table itself, using conditions whereDescendantOf or whereAncestorOf would throw an Integrity Constraint Violation error on columns _lft and/or _rgt. --- src/QueryBuilder.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/QueryBuilder.php b/src/QueryBuilder.php index b406c48..61aba6a 100644 --- a/src/QueryBuilder.php +++ b/src/QueryBuilder.php @@ -110,8 +110,9 @@ public function whereAncestorOf($id, $andSelf = false, $boolean = 'and') $this->query->whereNested(function ($inner) use ($value, $andSelf, $id, $keyName) { list($lft, $rgt) = $this->wrappedColumns(); + $wrappedTable = $this->query->getGrammar()->wrapTable($this->model->getTable()); - $inner->whereRaw("{$value} between {$lft} and {$rgt}"); + $inner->whereRaw("{$value} between {$wrappedTable}.{$lft} and {$wrappedTable}.{$rgt}"); if ( ! $andSelf) { $inner->where($keyName, '<>', $id); @@ -182,7 +183,7 @@ public function ancestorsAndSelf($id, array $columns = [ '*' ]) */ public function whereNodeBetween($values, $boolean = 'and', $not = false) { - $this->query->whereBetween($this->model->getLftName(), $values, $boolean, $not); + $this->query->whereBetween($this->model->getTable() . '.' . $this->model->getLftName(), $values, $boolean, $not); return $this; } From 0865b9cfc201f9231273f150a5689a58fb045f26 Mon Sep 17 00:00:00 2001 From: Bill Riess Date: Tue, 26 Feb 2019 15:08:34 -0500 Subject: [PATCH 15/51] Support Laravel 5.8 --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 40c7aad..c56fea5 100644 --- a/composer.json +++ b/composer.json @@ -13,9 +13,9 @@ "require": { "php": ">=5.5.9", - "illuminate/support": "5.2 - 5.7", - "illuminate/database": "5.2 - 5.7", - "illuminate/events": "5.2 - 5.7" + "illuminate/support": "5.2 - 5.8", + "illuminate/database": "5.2 - 5.8", + "illuminate/events": "5.2 - 5.8" }, "autoload": { From d4945f69b3e69dcd86d215cd7892f0d3ac50e849 Mon Sep 17 00:00:00 2001 From: Bill Riess Date: Tue, 26 Feb 2019 15:09:30 -0500 Subject: [PATCH 16/51] Support Laravel 5.8 --- README.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index d06553c..8a3f253 100644 --- a/README.markdown +++ b/README.markdown @@ -6,7 +6,7 @@ This is a Laravel 4-5 package for working with trees in relational databases. -* **Laravel 5.5, 5.6, 5.7** is supported since v4.3 +* **Laravel 5.5, 5.6, 5.7, 5.8** is supported since v4.3 * **Laravel 5.2, 5.3, 5.4** is supported since v4 * **Laravel 5.1** is supported in v3 * **Laravel 4** is supported in v2 From 1b3f916c845871c51a646758c818cca62e1f0227 Mon Sep 17 00:00:00 2001 From: Bill Riess Date: Tue, 26 Feb 2019 15:10:07 -0500 Subject: [PATCH 17/51] Support Laravel 5.8 --- CHANGELOG.markdown | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.markdown b/CHANGELOG.markdown index 4463a38..dcb7bb0 100644 --- a/CHANGELOG.markdown +++ b/CHANGELOG.markdown @@ -1,3 +1,6 @@ +### 4.3.4 +* Support Laravel 5.8 + ### 4.3.3 * Support Laravel 5.7 @@ -111,4 +114,4 @@ ### 1.1.0 * `Collection::toDictionary` is now obsolete. Use `Collection::groupBy`. -* Laravel 4.2 is required \ No newline at end of file +* Laravel 4.2 is required From bed43e0ca7940ff2e393aba3b43dad7cdd04e386 Mon Sep 17 00:00:00 2001 From: Ciaro Vermeire Date: Fri, 12 Apr 2019 21:08:30 +0200 Subject: [PATCH 18/51] Require Laravel 5.7 and PHP 7.1 Due to some changes in the Laravel internals in regard with handling eager loading, upgrading the library to Laravel 5.7 is required. Also, nobody should be on PHP < 7 anyway. So now is a good time, if any... --- composer.json | 12 ++++++------ phpunit.xml | 1 - tests/NodeTest.php | 2 +- tests/ScopedNodeTest.php | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index c56fea5..ab4d192 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "kalnoy/nestedset", - "description": "Nested Set Model for Laravel 4-5", + "description": "Nested Set Model for Laravel 5.7 and up", "keywords": ["laravel", "nested sets", "nsm", "database", "hierarchy"], "license": "MIT", @@ -12,10 +12,10 @@ ], "require": { - "php": ">=5.5.9", - "illuminate/support": "5.2 - 5.8", - "illuminate/database": "5.2 - 5.8", - "illuminate/events": "5.2 - 5.8" + "php": ">=7.1.3", + "illuminate/support": "~5.7.0|~5.8.0", + "illuminate/database": "~5.7.0|~5.8.0", + "illuminate/events": "~5.7.0|~5.8.0" }, "autoload": { @@ -25,7 +25,7 @@ }, "require-dev": { - "phpunit/phpunit": "4.8.*" + "phpunit/phpunit": "7.*" }, "minimum-stability": "dev", diff --git a/phpunit.xml b/phpunit.xml index 80d7085..9d5784e 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -8,7 +8,6 @@ convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="true" - syntaxCheck="false" > diff --git a/tests/NodeTest.php b/tests/NodeTest.php index 6e23663..e29dadb 100644 --- a/tests/NodeTest.php +++ b/tests/NodeTest.php @@ -3,7 +3,7 @@ use Illuminate\Database\Capsule\Manager as Capsule; use Kalnoy\Nestedset\NestedSet; -class NodeTest extends PHPUnit_Framework_TestCase +class NodeTest extends PHPUnit\Framework\TestCase { public static function setUpBeforeClass() { diff --git a/tests/ScopedNodeTest.php b/tests/ScopedNodeTest.php index dc7ea4f..5fbe96f 100644 --- a/tests/ScopedNodeTest.php +++ b/tests/ScopedNodeTest.php @@ -3,7 +3,7 @@ use Illuminate\Database\Capsule\Manager as Capsule; use Kalnoy\Nestedset\NestedSet; -class ScopedNodeTest extends PHPUnit_Framework_TestCase +class ScopedNodeTest extends PHPUnit\Framework\TestCase { public static function setUpBeforeClass() { From 1f9bb95722cbc096af31fe51f99190b7cc54f466 Mon Sep 17 00:00:00 2001 From: Ciaro Vermeire Date: Fri, 12 Apr 2019 21:24:47 +0200 Subject: [PATCH 19/51] Fix eager loading issue ancestors/descendants relationships (fixes #339, #351, #329, #334, #271) The way eager loading is handled in Laravel has changed since the original implementation of the NestedSet library. It was not possible anymore to apply the scope to eagerly loaded ancestors/descendants relationships. Also removed defaultOrder() from the relations so custom orders can be applied. Sorting should never be a part of a relation anyway, or it would be hard to customize. --- phpunit.xml | 1 - src/AncestorsRelation.php | 3 ++- src/BaseRelation.php | 5 +++++ src/DescendantsRelation.php | 3 ++- src/NodeTrait.php | 4 ++-- tests/NodeTest.php | 6 ++++-- tests/ScopedNodeTest.php | 6 ++++-- 7 files changed, 19 insertions(+), 9 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index 9d5784e..1e71a58 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -7,7 +7,6 @@ convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" - stopOnFailure="true" > diff --git a/src/AncestorsRelation.php b/src/AncestorsRelation.php index 089e382..b59fba2 100644 --- a/src/AncestorsRelation.php +++ b/src/AncestorsRelation.php @@ -15,7 +15,8 @@ public function addConstraints() { if ( ! static::$constraints) return; - $this->query->whereAncestorOf($this->parent)->defaultOrder(); + $this->query->whereAncestorOf($this->parent) + ->applyNestedSetScope(); } /** diff --git a/src/BaseRelation.php b/src/BaseRelation.php index 6dbc064..386757d 100644 --- a/src/BaseRelation.php +++ b/src/BaseRelation.php @@ -154,6 +154,11 @@ public function getResults() */ public function addEagerConstraints(array $models) { + // The first model in the array is always the parent, so add the scope constraints based on that model. + // @link https://github.com/laravel/framework/pull/25240 + // @link https://github.com/lazychaser/laravel-nestedset/issues/351 + optional($models[0])->applyNestedSetScope($this->query); + $this->query->whereNested(function (Builder $inner) use ($models) { // We will use this query in order to apply constraints to the // base query builder diff --git a/src/DescendantsRelation.php b/src/DescendantsRelation.php index 5240d3a..4c6457d 100644 --- a/src/DescendantsRelation.php +++ b/src/DescendantsRelation.php @@ -17,7 +17,8 @@ public function addConstraints() { if ( ! static::$constraints) return; - $this->query->whereDescendantOf($this->parent); + $this->query->whereDescendantOf($this->parent) + ->applyNestedSetScope(); } /** diff --git a/src/NodeTrait.php b/src/NodeTrait.php index 167c001..b921984 100644 --- a/src/NodeTrait.php +++ b/src/NodeTrait.php @@ -248,7 +248,7 @@ public function children() */ public function descendants() { - return new DescendantsRelation($this->newScopedQuery(), $this); + return new DescendantsRelation($this->newQuery(), $this); } /** @@ -337,7 +337,7 @@ public function prevNodes() */ public function ancestors() { - return new AncestorsRelation($this->newScopedQuery(), $this); + return new AncestorsRelation($this->newQuery(), $this); } /** diff --git a/tests/NodeTest.php b/tests/NodeTest.php index e29dadb..7c2fbae 100644 --- a/tests/NodeTest.php +++ b/tests/NodeTest.php @@ -870,7 +870,9 @@ public function testFlatTree() $this->assertEquals('galaxy', $tree[3]->name); } - public function testSeveralNodesModelWork() + // Commented, cause there is no assertion here and otherwise the test is marked as risky in PHPUnit 7. + // What's the purpose of this method? @todo: remove/update? + /*public function testSeveralNodesModelWork() { $category = new Category; @@ -883,7 +885,7 @@ public function testSeveralNodesModelWork() $duplicate->name = 'test'; $duplicate->saveAsRoot(); - } + }*/ public function testWhereIsLeaf() { diff --git a/tests/ScopedNodeTest.php b/tests/ScopedNodeTest.php index 5fbe96f..f1c6921 100644 --- a/tests/ScopedNodeTest.php +++ b/tests/ScopedNodeTest.php @@ -193,11 +193,13 @@ protected function assertOtherScopeNotAffected() $this->assertEquals(1, $node->getLft()); } - public function testRebuildsTree() + // Commented, cause there is no assertion here and otherwise the test is marked as risky in PHPUnit 7. + // What's the purpose of this method? @todo: remove/update? + /*public function testRebuildsTree() { $data = []; MenuItem::scoped([ 'menu_id' => 2 ])->rebuildTree($data); - } + }*/ /** * @expectedException LogicException From 10732f165b5d93ab1b1992681e81bb320e05704b Mon Sep 17 00:00:00 2001 From: Ciaro Vermeire Date: Sun, 21 Apr 2019 12:28:36 +0200 Subject: [PATCH 20/51] Split off v5 branch to indicate BC for Laravel 5.7 and 5.8 --- README.markdown | 3 ++- composer.json | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.markdown b/README.markdown index 8a3f253..77c313a 100644 --- a/README.markdown +++ b/README.markdown @@ -6,7 +6,8 @@ This is a Laravel 4-5 package for working with trees in relational databases. -* **Laravel 5.5, 5.6, 5.7, 5.8** is supported since v4.3 +* **Laravel 5.7, 5.8** is supported since v5 +* **Laravel 5.5, 5.6** is supported since v4.3 * **Laravel 5.2, 5.3, 5.4** is supported since v4 * **Laravel 5.1** is supported in v3 * **Laravel 4** is supported in v2 diff --git a/composer.json b/composer.json index ab4d192..e126663 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,7 @@ "extra": { "branch-alias": { - "dev-master": "v4.2.x-dev" + "dev-master": "v5.0.x-dev" }, "laravel": { From 9c0ae248f38289147a5094fa0c5ba9bb9e93104b Mon Sep 17 00:00:00 2001 From: Alexander Kalnoy Date: Fri, 6 Sep 2019 09:18:32 +0300 Subject: [PATCH 21/51] SUpport l6.0 --- .travis.yml | 3 ++- README.markdown | 6 +++--- composer.json | 6 +++--- src/NodeTrait.php | 3 ++- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index d7e4828..63d9638 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,8 @@ language: php php: - 5.5 - 5.6 - - 7.0 + - 7.1 + - 7.2 before_script: - curl -s http://getcomposer.org/installer | php diff --git a/README.markdown b/README.markdown index 77c313a..a45cccf 100644 --- a/README.markdown +++ b/README.markdown @@ -4,10 +4,10 @@ [![Latest Unstable Version](https://poser.pugx.org/kalnoy/nestedset/v/unstable.svg)](https://packagist.org/packages/kalnoy/nestedset) [![License](https://poser.pugx.org/kalnoy/nestedset/license.svg)](https://packagist.org/packages/kalnoy/nestedset) -This is a Laravel 4-5 package for working with trees in relational databases. +This is a Laravel 4-6 package for working with trees in relational databases. -* **Laravel 5.7, 5.8** is supported since v5 -* **Laravel 5.5, 5.6** is supported since v4.3 +* **Laravel 5.7, 5.8, 6.0** is supported since v5 +* **Laravel 5.5, 5.6, 5.7, 5.8, 6.0** is supported since v4.3 * **Laravel 5.2, 5.3, 5.4** is supported since v4 * **Laravel 5.1** is supported in v3 * **Laravel 4** is supported in v2 diff --git a/composer.json b/composer.json index e126663..580401e 100644 --- a/composer.json +++ b/composer.json @@ -13,9 +13,9 @@ "require": { "php": ">=7.1.3", - "illuminate/support": "~5.7.0|~5.8.0", - "illuminate/database": "~5.7.0|~5.8.0", - "illuminate/events": "~5.7.0|~5.8.0" + "illuminate/support": "~5.7.0|~5.8.0|~6.0", + "illuminate/database": "~5.7.0|~5.8.0|~6.0", + "illuminate/events": "~5.7.0|~5.8.0|~6.0" }, "autoload": { diff --git a/src/NodeTrait.php b/src/NodeTrait.php index b921984..0b985ab 100644 --- a/src/NodeTrait.php +++ b/src/NodeTrait.php @@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Support\Arr; use LogicException; trait NodeTrait @@ -752,7 +753,7 @@ public function newCollection(array $models = array()) */ public static function create(array $attributes = [], self $parent = null) { - $children = array_pull($attributes, 'children'); + $children = Arr::pull($attributes, 'children'); $instance = new static($attributes); From f6f6d7368ef7aeadbffa288ce7454c22d7ad3160 Mon Sep 17 00:00:00 2001 From: Alexander Kalnoy Date: Fri, 6 Sep 2019 09:20:50 +0300 Subject: [PATCH 22/51] Fixed readme --- README.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index a45cccf..7731978 100644 --- a/README.markdown +++ b/README.markdown @@ -7,7 +7,7 @@ This is a Laravel 4-6 package for working with trees in relational databases. * **Laravel 5.7, 5.8, 6.0** is supported since v5 -* **Laravel 5.5, 5.6, 5.7, 5.8, 6.0** is supported since v4.3 +* **Laravel 5.5, 5.6** is supported since v4.3 * **Laravel 5.2, 5.3, 5.4** is supported since v4 * **Laravel 5.1** is supported in v3 * **Laravel 4** is supported in v2 From 31832f7ffa28bc379563f5c9b7c11dcae85cdd09 Mon Sep 17 00:00:00 2001 From: antonkomarev Date: Fri, 6 Sep 2019 14:06:39 +0300 Subject: [PATCH 23/51] Use caret in L6 version name --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 580401e..764aab6 100644 --- a/composer.json +++ b/composer.json @@ -13,9 +13,9 @@ "require": { "php": ">=7.1.3", - "illuminate/support": "~5.7.0|~5.8.0|~6.0", - "illuminate/database": "~5.7.0|~5.8.0|~6.0", - "illuminate/events": "~5.7.0|~5.8.0|~6.0" + "illuminate/support": "~5.7.0|~5.8.0|^6.0", + "illuminate/database": "~5.7.0|~5.8.0|^6.0", + "illuminate/events": "~5.7.0|~5.8.0|^6.0" }, "autoload": { From 173280db7c63ca50f0c89e01b66a8ed1f5c9b4c1 Mon Sep 17 00:00:00 2001 From: Alexander Kalnoy Date: Wed, 4 Mar 2020 08:32:25 +0300 Subject: [PATCH 24/51] Bump laravel ver --- README.markdown | 2 +- composer.json | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.markdown b/README.markdown index 7731978..8f2a48f 100644 --- a/README.markdown +++ b/README.markdown @@ -6,7 +6,7 @@ This is a Laravel 4-6 package for working with trees in relational databases. -* **Laravel 5.7, 5.8, 6.0** is supported since v5 +* **Laravel 5.7, 5.8, 6.0, 7.0** is supported since v5 * **Laravel 5.5, 5.6** is supported since v4.3 * **Laravel 5.2, 5.3, 5.4** is supported since v4 * **Laravel 5.1** is supported in v3 diff --git a/composer.json b/composer.json index 580401e..f7f3c0e 100644 --- a/composer.json +++ b/composer.json @@ -13,9 +13,9 @@ "require": { "php": ">=7.1.3", - "illuminate/support": "~5.7.0|~5.8.0|~6.0", - "illuminate/database": "~5.7.0|~5.8.0|~6.0", - "illuminate/events": "~5.7.0|~5.8.0|~6.0" + "illuminate/support": "~5.7.0|~5.8.0|~6.0|~7.0", + "illuminate/database": "~5.7.0|~5.8.0|~6.0|~7.0", + "illuminate/events": "~5.7.0|~5.8.0|~6.0|~7.0" }, "autoload": { From b394b050f770cd598cb2e069e474bdacaad567b3 Mon Sep 17 00:00:00 2001 From: David VanScott Date: Tue, 8 Sep 2020 17:52:31 -0400 Subject: [PATCH 25/51] Add support for Laravel 8 --- .travis.yml | 1 + README.markdown | 4 ++-- composer.json | 8 ++++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 63d9638..38ff41f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,7 @@ php: - 5.6 - 7.1 - 7.2 + - 7.3 before_script: - curl -s http://getcomposer.org/installer | php diff --git a/README.markdown b/README.markdown index 8f2a48f..40d6adb 100644 --- a/README.markdown +++ b/README.markdown @@ -4,9 +4,9 @@ [![Latest Unstable Version](https://poser.pugx.org/kalnoy/nestedset/v/unstable.svg)](https://packagist.org/packages/kalnoy/nestedset) [![License](https://poser.pugx.org/kalnoy/nestedset/license.svg)](https://packagist.org/packages/kalnoy/nestedset) -This is a Laravel 4-6 package for working with trees in relational databases. +This is a Laravel 4-8 package for working with trees in relational databases. -* **Laravel 5.7, 5.8, 6.0, 7.0** is supported since v5 +* **Laravel 5.7, 5.8, 6.0, 7.0, 8.0** is supported since v5 * **Laravel 5.5, 5.6** is supported since v4.3 * **Laravel 5.2, 5.3, 5.4** is supported since v4 * **Laravel 5.1** is supported in v3 diff --git a/composer.json b/composer.json index 92eed7b..6a5d1a4 100644 --- a/composer.json +++ b/composer.json @@ -12,10 +12,10 @@ ], "require": { - "php": ">=7.1.3", - "illuminate/support": "~5.7.0|~5.8.0|^6.0|^7.0", - "illuminate/database": "~5.7.0|~5.8.0|^6.0|^7.0", - "illuminate/events": "~5.7.0|~5.8.0|^6.0|^7.0" + "php": ">=7.3.0", + "illuminate/support": "~5.7.0|~5.8.0|^6.0|^7.0|^8.0", + "illuminate/database": "~5.7.0|~5.8.0|^6.0|^7.0|^8.0", + "illuminate/events": "~5.7.0|~5.8.0|^6.0|^7.0|^8.0" }, "autoload": { From a4c9728b92566120987354606e25be3600237c32 Mon Sep 17 00:00:00 2001 From: David VanScott Date: Wed, 9 Sep 2020 08:28:25 -0400 Subject: [PATCH 26/51] Add PHP 7.4 to test suite --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 38ff41f..d0ba93c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,7 @@ php: - 7.1 - 7.2 - 7.3 + - 7.4 before_script: - curl -s http://getcomposer.org/installer | php From ea701ed5b0ea5b52d5d2b09092c958d60580d102 Mon Sep 17 00:00:00 2001 From: David VanScott Date: Wed, 9 Sep 2020 08:28:37 -0400 Subject: [PATCH 27/51] Revert PHP version requirement --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 6a5d1a4..44292ad 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ ], "require": { - "php": ">=7.3.0", + "php": ">=7.1.3", "illuminate/support": "~5.7.0|~5.8.0|^6.0|^7.0|^8.0", "illuminate/database": "~5.7.0|~5.8.0|^6.0|^7.0|^8.0", "illuminate/events": "~5.7.0|~5.8.0|^6.0|^7.0|^8.0" From b6233fd600c0ecd54e77bda35f8a1d9e9bbe64ff Mon Sep 17 00:00:00 2001 From: Yury Kozyrev Date: Tue, 1 Dec 2020 16:48:04 +0100 Subject: [PATCH 28/51] update getRelationCountHash --- src/BaseRelation.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/BaseRelation.php b/src/BaseRelation.php index 386757d..81a2ee2 100644 --- a/src/BaseRelation.php +++ b/src/BaseRelation.php @@ -130,9 +130,9 @@ public function getRelationQuery( * * @return string */ - public function getRelationCountHash() + public function getRelationCountHash($incrementJoinCount = true) { - return 'nested_set_'.self::$selfJoinCount++; + return 'nested_set_'.($incrementJoinCount ? static::$selfJoinCount++ : static::$selfJoinCount); } /** @@ -208,4 +208,4 @@ protected function matchForModel(Model $model, EloquentCollection $results) return $result; } -} \ No newline at end of file +} From b2c98cc1169dabda7400e620ae3f6a2f32140a5c Mon Sep 17 00:00:00 2001 From: Yury Kozyrev Date: Tue, 1 Dec 2020 16:54:36 +0100 Subject: [PATCH 29/51] add phpdoc --- src/BaseRelation.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/BaseRelation.php b/src/BaseRelation.php index 81a2ee2..3b3b592 100644 --- a/src/BaseRelation.php +++ b/src/BaseRelation.php @@ -128,6 +128,7 @@ public function getRelationQuery( /** * Get a relationship join table hash. * + * @param bool $incrementJoinCount * @return string */ public function getRelationCountHash($incrementJoinCount = true) From cd0fecb79d2df8192fb4e1db264b2172a5b4280f Mon Sep 17 00:00:00 2001 From: Alexander Kalnoy Date: Fri, 28 May 2021 10:05:38 +0300 Subject: [PATCH 30/51] Lock laravel version --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 44292ad..6113644 100644 --- a/composer.json +++ b/composer.json @@ -13,9 +13,9 @@ "require": { "php": ">=7.1.3", - "illuminate/support": "~5.7.0|~5.8.0|^6.0|^7.0|^8.0", - "illuminate/database": "~5.7.0|~5.8.0|^6.0|^7.0|^8.0", - "illuminate/events": "~5.7.0|~5.8.0|^6.0|^7.0|^8.0" + "illuminate/support": "~5.7.0|~5.8.0|^6.0|^7.0|^8.41", + "illuminate/database": "~5.7.0|~5.8.0|^6.0|^7.0|^8.41", + "illuminate/events": "~5.7.0|~5.8.0|^6.0|^7.0|^8.41" }, "autoload": { From f5351234588a20b14134980552b1bf6dccb3e733 Mon Sep 17 00:00:00 2001 From: Alexander Kalnoy Date: Fri, 28 May 2021 10:08:55 +0300 Subject: [PATCH 31/51] Fix incompatibility --- composer.json | 6 +++--- src/BaseRelation.php | 14 -------------- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/composer.json b/composer.json index 6113644..5c937a9 100644 --- a/composer.json +++ b/composer.json @@ -13,9 +13,9 @@ "require": { "php": ">=7.1.3", - "illuminate/support": "~5.7.0|~5.8.0|^6.0|^7.0|^8.41", - "illuminate/database": "~5.7.0|~5.8.0|^6.0|^7.0|^8.41", - "illuminate/events": "~5.7.0|~5.8.0|^6.0|^7.0|^8.41" + "illuminate/support": "^7.0|^8.0", + "illuminate/database": "^7.0|^8.0", + "illuminate/events": "^7.0|^8.0" }, "autoload": { diff --git a/src/BaseRelation.php b/src/BaseRelation.php index 3b3b592..f4acd1e 100644 --- a/src/BaseRelation.php +++ b/src/BaseRelation.php @@ -111,20 +111,6 @@ public function initRelation(array $models, $relation) return $models; } - /** - * @param EloquentBuilder $query - * @param EloquentBuilder $parent - * @param array $columns - * - * @return mixed - */ - public function getRelationQuery( - EloquentBuilder $query, EloquentBuilder $parent, - $columns = [ '*' ] - ) { - return $this->getRelationExistenceQuery($query, $parent, $columns); - } - /** * Get a relationship join table hash. * From abf4c8602977874368a79eb6648d5d0014b613bb Mon Sep 17 00:00:00 2001 From: Alexander Kalnoy Date: Fri, 28 May 2021 10:23:48 +0300 Subject: [PATCH 32/51] Update --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 6113644..62079e9 100644 --- a/composer.json +++ b/composer.json @@ -13,9 +13,9 @@ "require": { "php": ">=7.1.3", - "illuminate/support": "~5.7.0|~5.8.0|^6.0|^7.0|^8.41", - "illuminate/database": "~5.7.0|~5.8.0|^6.0|^7.0|^8.41", - "illuminate/events": "~5.7.0|~5.8.0|^6.0|^7.0|^8.41" + "illuminate/support": "~5.7.0|~5.8.0|^6.0|^7.0|>=8.0 <8.43.0", + "illuminate/database": "~5.7.0|~5.8.0|^6.0|^7.0|>=8.0 <8.43.0", + "illuminate/events": "~5.7.0|~5.8.0|^6.0|^7.0|>=8.0 <8.43.0" }, "autoload": { From 46e8c2704fecfca2f4202a076c3db433cbe14490 Mon Sep 17 00:00:00 2001 From: Grigory Tumakov <4266448+vokamut@users.noreply.github.com> Date: Fri, 28 May 2021 14:38:00 +0300 Subject: [PATCH 33/51] Added version v6 --- README.markdown | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index 40d6adb..7e7341e 100644 --- a/README.markdown +++ b/README.markdown @@ -6,7 +6,8 @@ This is a Laravel 4-8 package for working with trees in relational databases. -* **Laravel 5.7, 5.8, 6.0, 7.0, 8.0** is supported since v5 +* **Laravel 8.0** is supported since v6 +* **Laravel 5.7, 5.8, 6.0, 7.0** is supported since v5 * **Laravel 5.5, 5.6** is supported since v4.3 * **Laravel 5.2, 5.3, 5.4** is supported since v4 * **Laravel 5.1** is supported in v3 From 41a445dd579198082814196ee0e42fa223e30abc Mon Sep 17 00:00:00 2001 From: Emiel Molenaar Date: Tue, 15 Jun 2021 11:19:20 +0200 Subject: [PATCH 34/51] Adding Github actions, removing Travis CI --- .github/workflows/run-tests.yml | 42 +++++++++++++++++++++++++++++++++ .travis.yml | 15 ------------ composer.json | 5 ++++ 3 files changed, 47 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/run-tests.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml new file mode 100644 index 0000000..6d89c90 --- /dev/null +++ b/.github/workflows/run-tests.yml @@ -0,0 +1,42 @@ +name: Unit Tests + +on: + push: + branches: + - master + pull_request: + branches: + - "*" + schedule: + - cron: '0 0 * * *' + +jobs: + php-tests: + runs-on: ubuntu-latest + timeout-minutes: 15 + env: + COMPOSER_NO_INTERACTION: 1 + + strategy: + matrix: + php: [8.0, 7.4, 7.3, 7.2, 7.1] + + name: P${{ matrix.php }} + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + coverage: none + tools: composer:v2 + + - name: Install dependencies + run: | + composer install -o --quiet + + - name: Execute Unit Tests + run: composer test diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index d0ba93c..0000000 --- a/.travis.yml +++ /dev/null @@ -1,15 +0,0 @@ -language: php - -php: - - 5.5 - - 5.6 - - 7.1 - - 7.2 - - 7.3 - - 7.4 - -before_script: - - curl -s http://getcomposer.org/installer | php - - php composer.phar install --dev - -script: phpunit \ No newline at end of file diff --git a/composer.json b/composer.json index 62079e9..30cfde1 100644 --- a/composer.json +++ b/composer.json @@ -41,5 +41,10 @@ "Kalnoy\\Nestedset\\NestedSetServiceProvider" ] } + }, + "scripts": { + "test": [ + "@php ./vendor/bin/phpunit" + ] } } From 427d4282d7f75e559a69e73a8c5fcea20c501782 Mon Sep 17 00:00:00 2001 From: Felix Rudat Date: Mon, 8 Nov 2021 11:37:09 +0100 Subject: [PATCH 35/51] fix issues with novas reverse relation resolver --- src/BaseRelation.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/BaseRelation.php b/src/BaseRelation.php index f4acd1e..031eecf 100644 --- a/src/BaseRelation.php +++ b/src/BaseRelation.php @@ -195,4 +195,16 @@ protected function matchForModel(Model $model, EloquentCollection $results) return $result; } + + /** + * Get the plain foreign key. + * + * @return mixed + */ + public function getForeignKeyName() + { + // Return a stub value for relation + // resolvers which need this function. + return NestedSet::PARENT_ID; + } } From 4efffc8e47a8ed64434060298d866a4999237825 Mon Sep 17 00:00:00 2001 From: Quentin Renard Date: Wed, 26 Jan 2022 00:44:53 +0100 Subject: [PATCH 36/51] Init Laravel 9 support --- composer.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 5c937a9..10b3485 100644 --- a/composer.json +++ b/composer.json @@ -13,9 +13,9 @@ "require": { "php": ">=7.1.3", - "illuminate/support": "^7.0|^8.0", - "illuminate/database": "^7.0|^8.0", - "illuminate/events": "^7.0|^8.0" + "illuminate/support": "^7.0|^8.0|^9.0", + "illuminate/database": "^7.0|^8.0|^9.0", + "illuminate/events": "^7.0|^8.0|^9.0" }, "autoload": { @@ -25,7 +25,7 @@ }, "require-dev": { - "phpunit/phpunit": "7.*" + "phpunit/phpunit": "7.*|8.*|9.*" }, "minimum-stability": "dev", From 9c307bfd237ef6cbaab03068dec0ae1eb36022de Mon Sep 17 00:00:00 2001 From: Quentin Renard Date: Wed, 26 Jan 2022 00:46:32 +0100 Subject: [PATCH 37/51] Add PHP 8.0 to tests --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d0ba93c..418b13e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,9 +7,10 @@ php: - 7.2 - 7.3 - 7.4 + - 8.0 before_script: - curl -s http://getcomposer.org/installer | php - php composer.phar install --dev -script: phpunit \ No newline at end of file +script: phpunit From cf3e49ae3f7f289354eea5fa81d0db9043029692 Mon Sep 17 00:00:00 2001 From: Quentin Renard Date: Wed, 9 Feb 2022 12:51:51 +0100 Subject: [PATCH 38/51] Remove PHP 7.1 from tests matrix --- .github/workflows/run-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 6d89c90..1ae8a99 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -19,7 +19,7 @@ jobs: strategy: matrix: - php: [8.0, 7.4, 7.3, 7.2, 7.1] + php: [8.0, 7.4, 7.3, 7.2] name: P${{ matrix.php }} From 68519a1dfcaaa190d9a4bffb9608297b84b5e26d Mon Sep 17 00:00:00 2001 From: Quentin Renard Date: Wed, 9 Feb 2022 13:20:51 +0100 Subject: [PATCH 39/51] Support PHPUnit updates --- .gitignore | 1 + tests/NodeTest.php | 6 +++--- tests/ScopedNodeTest.php | 6 +++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 8879189..6bef520 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ composer.phar composer.lock .DS_Store +.phpunit.result.cache diff --git a/tests/NodeTest.php b/tests/NodeTest.php index 7c2fbae..a4fcf2b 100644 --- a/tests/NodeTest.php +++ b/tests/NodeTest.php @@ -5,7 +5,7 @@ class NodeTest extends PHPUnit\Framework\TestCase { - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { $schema = Capsule::schema(); @@ -23,7 +23,7 @@ public static function setUpBeforeClass() Capsule::enableQueryLog(); } - public function setUp() + public function setUp(): void { $data = include __DIR__.'/data/categories.php'; @@ -36,7 +36,7 @@ public function setUp() date_default_timezone_set('America/Denver'); } - public function tearDown() + public function tearDown(): void { Capsule::table('categories')->truncate(); } diff --git a/tests/ScopedNodeTest.php b/tests/ScopedNodeTest.php index f1c6921..a02f67a 100644 --- a/tests/ScopedNodeTest.php +++ b/tests/ScopedNodeTest.php @@ -5,7 +5,7 @@ class ScopedNodeTest extends PHPUnit\Framework\TestCase { - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { $schema = Capsule::schema(); @@ -23,7 +23,7 @@ public static function setUpBeforeClass() Capsule::enableQueryLog(); } - public function setUp() + public function setUp(): void { $data = include __DIR__.'/data/menu_items.php'; @@ -36,7 +36,7 @@ public function setUp() date_default_timezone_set('America/Denver'); } - public function tearDown() + public function tearDown(): void { Capsule::table('menu_items')->truncate(); } From 47bd676d10f2217580c545668cab61ec29c45386 Mon Sep 17 00:00:00 2001 From: Quentin Renard Date: Wed, 9 Feb 2022 13:21:00 +0100 Subject: [PATCH 40/51] Add PHP 8.1 to tests matrix --- .github/workflows/run-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 1ae8a99..aa8d88a 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -19,7 +19,7 @@ jobs: strategy: matrix: - php: [8.0, 7.4, 7.3, 7.2] + php: [8.1, 8.0, 7.4, 7.3, 7.2] name: P${{ matrix.php }} From 1195f44ee215cd5659fc93549fe0a83999dd8128 Mon Sep 17 00:00:00 2001 From: Quentin Renard Date: Wed, 9 Feb 2022 13:27:15 +0100 Subject: [PATCH 41/51] Disable GitHub Actions fail-fast strategy --- .github/workflows/run-tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index aa8d88a..438e5dd 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -18,6 +18,7 @@ jobs: COMPOSER_NO_INTERACTION: 1 strategy: + fail-fast: false matrix: php: [8.1, 8.0, 7.4, 7.3, 7.2] From de97a56c30ce7ed6276243fca42527ff9fe75794 Mon Sep 17 00:00:00 2001 From: Quentin Renard Date: Thu, 10 Feb 2022 13:29:57 +0100 Subject: [PATCH 42/51] Refactor deprecated PHPUnit annotations --- tests/NodeTest.php | 35 ++++++++++++++--------------------- tests/ScopedNodeTest.php | 15 ++++++--------- 2 files changed, 20 insertions(+), 30 deletions(-) diff --git a/tests/NodeTest.php b/tests/NodeTest.php index a4fcf2b..3b0831a 100644 --- a/tests/NodeTest.php +++ b/tests/NodeTest.php @@ -221,32 +221,29 @@ public function testCategoryMovesUp() $this->assertNodeReceivesValidValues($node); } - /** - * @expectedException Exception - */ public function testFailsToInsertIntoChild() { + $this->expectException(Exception::class); + $node = $this->findCategory('notebooks'); $target = $node->children()->first(); $node->afterNode($target)->save(); } - /** - * @expectedException Exception - */ public function testFailsToAppendIntoItself() { + $this->expectException(Exception::class); + $node = $this->findCategory('notebooks'); $node->appendToNode($node)->save(); } - /** - * @expectedException Exception - */ public function testFailsToPrependIntoItself() { + $this->expectException(Exception::class); + $node = $this->findCategory('notebooks'); $node->prependTo($node)->save(); @@ -338,11 +335,10 @@ public function testParentIdAttributeAccessorAppendsNode() $this->assertTrue($node->isRoot()); } - /** - * @expectedException Exception - */ public function testFailsToSaveNodeUntilNotInserted() { + $this->expectException(Exception::class); + $node = new Category; $node->save(); } @@ -405,11 +401,10 @@ public function testSoftDeletedNodeisDeletedWhenParentIsDeleted() $this->assertNull($this->findCategory('sony')); } - /** - * @expectedException Exception - */ public function testFailsToSaveNodeUntilParentIsSaved() { + $this->expectException(Exception::class); + $node = new Category(array('title' => 'Node')); $parent = new Category(array('title' => 'Parent')); @@ -641,11 +636,10 @@ public function testDescendantsOfNonExistingNode() $this->assertTrue($node->getDescendants()->isEmpty()); } - /** - * @expectedException \Illuminate\Database\Eloquent\ModelNotFoundException - */ public function testWhereDescendantsOf() { + $this->expectException(\Illuminate\Database\Eloquent\ModelNotFoundException::class); + Category::whereDescendantOf(124)->get(); } @@ -852,11 +846,10 @@ public function testRebuildTreeWithDeletion() $this->assertTrue($nodes->count() > 1); } - /** - * @expectedException \Illuminate\Database\Eloquent\ModelNotFoundException - */ public function testRebuildFailsWithInvalidPK() { + $this->expectException(\Illuminate\Database\Eloquent\ModelNotFoundException::class); + Category::rebuildTree([ [ 'id' => 24 ] ]); } diff --git a/tests/ScopedNodeTest.php b/tests/ScopedNodeTest.php index a02f67a..c0eac24 100644 --- a/tests/ScopedNodeTest.php +++ b/tests/ScopedNodeTest.php @@ -159,11 +159,10 @@ public function testInsertion() $this->assertOtherScopeNotAffected(); } - /** - * @expectedException \Illuminate\Database\Eloquent\ModelNotFoundException - */ public function testInsertionToParentFromOtherScope() { + $this->expectException(\Illuminate\Database\Eloquent\ModelNotFoundException::class); + $node = MenuItem::create([ 'menu_id' => 2, 'parent_id' => 5 ]); } @@ -201,22 +200,20 @@ protected function assertOtherScopeNotAffected() MenuItem::scoped([ 'menu_id' => 2 ])->rebuildTree($data); }*/ - /** - * @expectedException LogicException - */ public function testAppendingToAnotherScopeFails() { + $this->expectException(LogicException::class); + $a = MenuItem::find(1); $b = MenuItem::find(3); $a->appendToNode($b)->save(); } - /** - * @expectedException LogicException - */ public function testInsertingBeforeAnotherScopeFails() { + $this->expectException(LogicException::class); + $a = MenuItem::find(1); $b = MenuItem::find(3); From 49490dde2deb9b4ddd7cba995f1272a11b85ba66 Mon Sep 17 00:00:00 2001 From: Simon Verwaard Date: Tue, 28 Jun 2022 08:53:58 +0200 Subject: [PATCH 43/51] Fix return type of NodeTrait::scoped method --- src/NodeTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NodeTrait.php b/src/NodeTrait.php index 0b985ab..46c9fea 100644 --- a/src/NodeTrait.php +++ b/src/NodeTrait.php @@ -725,7 +725,7 @@ protected function getScopeAttributes() /** * @param array $attributes * - * @return self + * @return QueryBuilder */ public static function scoped(array $attributes) { From a9fbb0101d681a441c127494c2f2ca215f07db6c Mon Sep 17 00:00:00 2001 From: Jon Nott Date: Wed, 15 Feb 2023 11:25:36 +0000 Subject: [PATCH 44/51] [6.x] support Laravel 10.x --- README.markdown | 2 +- composer.json | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.markdown b/README.markdown index 7e7341e..58f0391 100644 --- a/README.markdown +++ b/README.markdown @@ -6,7 +6,7 @@ This is a Laravel 4-8 package for working with trees in relational databases. -* **Laravel 8.0** is supported since v6 +* **Laravel 8.0, 9.0, 10.0** is supported since v6 * **Laravel 5.7, 5.8, 6.0, 7.0** is supported since v5 * **Laravel 5.5, 5.6** is supported since v4.3 * **Laravel 5.2, 5.3, 5.4** is supported since v4 diff --git a/composer.json b/composer.json index ff3df84..92701dc 100644 --- a/composer.json +++ b/composer.json @@ -13,9 +13,9 @@ "require": { "php": "^7.2.5|^8.0", - "illuminate/support": "^7.0|^8.0|^9.0", - "illuminate/database": "^7.0|^8.0|^9.0", - "illuminate/events": "^7.0|^8.0|^9.0" + "illuminate/support": "^7.0|^8.0|^9.0|^10.0", + "illuminate/database": "^7.0|^8.0|^9.0|^10.0", + "illuminate/events": "^7.0|^8.0|^9.0|^10.0" }, "autoload": { From 2d5c99fe1bfbaa4004f8d6fb24475f7ff88bb526 Mon Sep 17 00:00:00 2001 From: Alexander Kalnoy Date: Thu, 16 Feb 2023 17:41:24 +0300 Subject: [PATCH 45/51] Update --- phpunit.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/phpunit.php b/phpunit.php index a9fa67a..7f72aff 100644 --- a/phpunit.php +++ b/phpunit.php @@ -8,4 +8,5 @@ $capsule->bootEloquent(); $capsule->setAsGlobal(); -include __DIR__.'/tests/models/Category.php'; \ No newline at end of file +include __DIR__.'/tests/models/Category.php'; +include __DIR__.'/tests/models/MenuItem.php'; \ No newline at end of file From 562f5e1a407fea1ba8de66693ea1306c9d6d6fed Mon Sep 17 00:00:00 2001 From: Jonny Nott Date: Thu, 16 Feb 2023 14:53:05 +0000 Subject: [PATCH 46/51] fix readme versions --- README.markdown | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.markdown b/README.markdown index 58f0391..73e1938 100644 --- a/README.markdown +++ b/README.markdown @@ -4,9 +4,11 @@ [![Latest Unstable Version](https://poser.pugx.org/kalnoy/nestedset/v/unstable.svg)](https://packagist.org/packages/kalnoy/nestedset) [![License](https://poser.pugx.org/kalnoy/nestedset/license.svg)](https://packagist.org/packages/kalnoy/nestedset) -This is a Laravel 4-8 package for working with trees in relational databases. +This is a Laravel 4-10 package for working with trees in relational databases. -* **Laravel 8.0, 9.0, 10.0** is supported since v6 +* **Laravel 10.0** is supported since v6.0.2 +* **Laravel 9.0** is supported since v6.0.1 +* **Laravel 8.0** is supported since v6.0.0 * **Laravel 5.7, 5.8, 6.0, 7.0** is supported since v5 * **Laravel 5.5, 5.6** is supported since v4.3 * **Laravel 5.2, 5.3, 5.4** is supported since v4 From bf599ab01b4ae7f5b6223e83e3db1a8ccfd2fd96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damian=20J=C3=B3=C5=BAwiak?= Date: Thu, 22 Jun 2023 12:44:21 +0200 Subject: [PATCH 47/51] eagerLoadingAncestorsWithScope | add failing test --- tests/ScopedNodeTest.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/ScopedNodeTest.php b/tests/ScopedNodeTest.php index c0eac24..6230f94 100644 --- a/tests/ScopedNodeTest.php +++ b/tests/ScopedNodeTest.php @@ -219,4 +219,12 @@ public function testInsertingBeforeAnotherScopeFails() $a->insertAfterNode($b); } + + public function testEagerLoadingAncestorsWithScope() + { + $filteredNodes = MenuItem::where('title', 'menu item 3')->with(['ancestors'])->get(); + + $this->assertEquals(2, $filteredNodes->find(5)->ancestors[0]->id); + $this->assertEquals(4, $filteredNodes->find(6)->ancestors[0]->id); + } } \ No newline at end of file From df8736aec6b816c275ec03889854cef1110e8b34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damian=20J=C3=B3=C5=BAwiak?= Date: Thu, 22 Jun 2023 15:31:33 +0200 Subject: [PATCH 48/51] eagerLoadingAncestorsWithScope | fix applying scope in whereAncestorOf() and whereDescendantOf() --- src/BaseRelation.php | 5 ----- src/NodeTrait.php | 21 ++++++++++++++++++- src/QueryBuilder.php | 44 ++++++++++++++++++++++++++-------------- tests/ScopedNodeTest.php | 10 ++++++++- 4 files changed, 58 insertions(+), 22 deletions(-) diff --git a/src/BaseRelation.php b/src/BaseRelation.php index 031eecf..7f82f29 100644 --- a/src/BaseRelation.php +++ b/src/BaseRelation.php @@ -141,11 +141,6 @@ public function getResults() */ public function addEagerConstraints(array $models) { - // The first model in the array is always the parent, so add the scope constraints based on that model. - // @link https://github.com/laravel/framework/pull/25240 - // @link https://github.com/lazychaser/laravel-nestedset/issues/351 - optional($models[0])->applyNestedSetScope($this->query); - $this->query->whereNested(function (Builder $inner) use ($models) { // We will use this query in order to apply constraints to the // base query builder diff --git a/src/NodeTrait.php b/src/NodeTrait.php index 0b985ab..bcd0314 100644 --- a/src/NodeTrait.php +++ b/src/NodeTrait.php @@ -1005,7 +1005,8 @@ public function getPrevSibling(array $columns = [ '*' ]) public function isDescendantOf(self $other) { return $this->getLft() > $other->getLft() && - $this->getLft() < $other->getRgt(); + $this->getLft() < $other->getRgt() && + $this->isSameScope($other); } /** @@ -1201,6 +1202,24 @@ protected function assertSameScope(self $node) } } + /** + * @param self $node + */ + protected function isSameScope(self $node): bool + { + if ( ! $scoped = $this->getScopeAttributes()) { + return true; + } + + foreach ($scoped as $attr) { + if ($this->getAttribute($attr) != $node->getAttribute($attr)) { + return false; + } + } + + return true; + } + /** * @param array|null $except * diff --git a/src/QueryBuilder.php b/src/QueryBuilder.php index 61aba6a..10edb27 100644 --- a/src/QueryBuilder.php +++ b/src/QueryBuilder.php @@ -87,8 +87,10 @@ public function whereIsRoot() public function whereAncestorOf($id, $andSelf = false, $boolean = 'and') { $keyName = $this->model->getTable() . '.' . $this->model->getKeyName(); + $model = null; if (NestedSet::isNode($id)) { + $model = $id; $value = '?'; $this->query->addBinding($id->getRgt()); @@ -108,7 +110,7 @@ public function whereAncestorOf($id, $andSelf = false, $boolean = 'and') $value = '('.$valueQuery->toSql().')'; } - $this->query->whereNested(function ($inner) use ($value, $andSelf, $id, $keyName) { + $this->query->whereNested(function ($inner) use ($model, $value, $andSelf, $id, $keyName) { list($lft, $rgt) = $this->wrappedColumns(); $wrappedTable = $this->query->getGrammar()->wrapTable($this->model->getTable()); @@ -117,9 +119,13 @@ public function whereAncestorOf($id, $andSelf = false, $boolean = 'and') if ( ! $andSelf) { $inner->where($keyName, '<>', $id); } + if ($model !== null) { + // we apply scope only when Node was passed as $id. + // In other cases, according to docs, query should be scoped() before calling this method + $model->applyNestedSetScope($inner); + } }, $boolean); - return $this; } @@ -178,12 +184,13 @@ public function ancestorsAndSelf($id, array $columns = [ '*' ]) * @param array $values * @param string $boolean * @param bool $not + * @param Query $query * * @return $this */ - public function whereNodeBetween($values, $boolean = 'and', $not = false) + public function whereNodeBetween($values, $boolean = 'and', $not = false, $query = null) { - $this->query->whereBetween($this->model->getTable() . '.' . $this->model->getLftName(), $values, $boolean, $not); + ($query ?? $this->query)->whereBetween($this->model->getTable() . '.' . $this->model->getLftName(), $values, $boolean, $not); return $this; } @@ -217,19 +224,26 @@ public function orWhereNodeBetween($values) public function whereDescendantOf($id, $boolean = 'and', $not = false, $andSelf = false ) { - if (NestedSet::isNode($id)) { - $data = $id->getBounds(); - } else { - $data = $this->model->newNestedSetQuery() - ->getPlainNodeData($id, true); - } + $this->query->whereNested(function (Query $inner) use ($id, $andSelf, $not) { + if (NestedSet::isNode($id)) { + $id->applyNestedSetScope($inner); + $data = $id->getBounds(); + } else { + // we apply scope only when Node was passed as $id. + // In other cases, according to docs, query should be scoped() before calling this method + $data = $this->model->newNestedSetQuery() + ->getPlainNodeData($id, true); + } - // Don't include the node - if ( ! $andSelf) { - ++$data[0]; - } + // Don't include the node + if (!$andSelf) { + ++$data[0]; + } - return $this->whereNodeBetween($data, $boolean, $not); + return $this->whereNodeBetween($data, 'and', $not, $inner); + }, $boolean); + + return $this; } /** diff --git a/tests/ScopedNodeTest.php b/tests/ScopedNodeTest.php index 6230f94..9622fc9 100644 --- a/tests/ScopedNodeTest.php +++ b/tests/ScopedNodeTest.php @@ -219,7 +219,7 @@ public function testInsertingBeforeAnotherScopeFails() $a->insertAfterNode($b); } - + public function testEagerLoadingAncestorsWithScope() { $filteredNodes = MenuItem::where('title', 'menu item 3')->with(['ancestors'])->get(); @@ -227,4 +227,12 @@ public function testEagerLoadingAncestorsWithScope() $this->assertEquals(2, $filteredNodes->find(5)->ancestors[0]->id); $this->assertEquals(4, $filteredNodes->find(6)->ancestors[0]->id); } + + public function testEagerLoadingDescendantsWithScope() + { + $filteredNodes = MenuItem::where('title', 'menu item 2')->with(['descendants'])->get(); + + $this->assertEquals(5, $filteredNodes->find(2)->descendants[0]->id); + $this->assertEquals(6, $filteredNodes->find(4)->descendants[0]->id); + } } \ No newline at end of file From f7a36eb3779ee4119a8ea72404aaf90c44fc9a15 Mon Sep 17 00:00:00 2001 From: Alexander Kalnoy Date: Wed, 29 Nov 2023 18:32:59 +0300 Subject: [PATCH 49/51] Update readme --- README.markdown | 4 ---- 1 file changed, 4 deletions(-) diff --git a/README.markdown b/README.markdown index 73e1938..7a3b0fb 100644 --- a/README.markdown +++ b/README.markdown @@ -15,10 +15,6 @@ This is a Laravel 4-10 package for working with trees in relational databases. * **Laravel 5.1** is supported in v3 * **Laravel 4** is supported in v2 -Although this project is completely free for use, I appreciate any support! - -- __[Donate via PayPal](https://www.paypal.me/lazychaser)__ - __Contents:__ - [Theory](#what-are-nested-sets) From c16faeb3a72b1a39fe0e8910d0bc1f021b005e9a Mon Sep 17 00:00:00 2001 From: asurcodes Date: Tue, 19 Mar 2024 12:12:54 +0100 Subject: [PATCH 50/51] Drop compatibility for EOL PHP versions, update dependecies for PHP 8.3 and Laravel 11 --- .github/workflows/run-tests.yml | 4 +-- composer.json | 16 +++++++---- phpunit.xml | 43 +++++++++++++++--------------- tests/.gitkeep | 0 tests/NodeTest.php | 8 ++---- tests/ScopedNodeTest.php | 1 + tests/data/categories.php | 26 +++++++++--------- tests/data/menu_items.php | 16 ++++++----- tests/models/Category.php | 9 +++++-- tests/models/DuplicateCategory.php | 8 ++++-- tests/models/MenuItem.php | 7 +++-- 11 files changed, 77 insertions(+), 61 deletions(-) delete mode 100644 tests/.gitkeep diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 438e5dd..e9c4015 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -20,13 +20,13 @@ jobs: strategy: fail-fast: false matrix: - php: [8.1, 8.0, 7.4, 7.3, 7.2] + php: [8.3, 8.2] name: P${{ matrix.php }} steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 diff --git a/composer.json b/composer.json index 92701dc..9f8d6c1 100644 --- a/composer.json +++ b/composer.json @@ -12,10 +12,10 @@ ], "require": { - "php": "^7.2.5|^8.0", - "illuminate/support": "^7.0|^8.0|^9.0|^10.0", - "illuminate/database": "^7.0|^8.0|^9.0|^10.0", - "illuminate/events": "^7.0|^8.0|^9.0|^10.0" + "php": "^8.2", + "illuminate/support": "^11.0", + "illuminate/database": "^11.0", + "illuminate/events": "^11.0" }, "autoload": { @@ -24,8 +24,14 @@ } }, + "autoload-dev": { + "psr-4": { + "Kalnoy\\Nestedset\\Tests\\": "tests/" + } + }, + "require-dev": { - "phpunit/phpunit": "7.*|8.*|9.*" + "phpunit/phpunit": "10.*" }, "minimum-stability": "dev", diff --git a/phpunit.xml b/phpunit.xml index 1e71a58..8021fb0 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,22 +1,21 @@ - - - - - ./tests/ - - - - - - ./src - - - \ No newline at end of file + + + + + ./tests/ + + + + + ./src + + + diff --git a/tests/.gitkeep b/tests/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/tests/NodeTest.php b/tests/NodeTest.php index 3b0831a..16d6d9e 100644 --- a/tests/NodeTest.php +++ b/tests/NodeTest.php @@ -2,6 +2,7 @@ use Illuminate\Database\Capsule\Manager as Capsule; use Kalnoy\Nestedset\NestedSet; +use Kalnoy\Nestedset\Tests\Models\Category; class NodeTest extends PHPUnit\Framework\TestCase { @@ -104,12 +105,7 @@ public function assertNodeReceivesValidValues($node) ); } - /** - * @param $name - * - * @return \Category - */ - public function findCategory($name, $withTrashed = false) + public function findCategory(string $name, bool $withTrashed = false): Category { $q = new Category; diff --git a/tests/ScopedNodeTest.php b/tests/ScopedNodeTest.php index 9622fc9..aed1fe1 100644 --- a/tests/ScopedNodeTest.php +++ b/tests/ScopedNodeTest.php @@ -2,6 +2,7 @@ use Illuminate\Database\Capsule\Manager as Capsule; use Kalnoy\Nestedset\NestedSet; +use Kalnoy\Nestedset\Tests\Models\MenuItem; class ScopedNodeTest extends PHPUnit\Framework\TestCase { diff --git a/tests/data/categories.php b/tests/data/categories.php index 1f5b8ab..cd16d40 100644 --- a/tests/data/categories.php +++ b/tests/data/categories.php @@ -1,15 +1,15 @@ 1, 'name' => 'store', '_lft' => 1, '_rgt' => 20, 'parent_id' => null), - array('id' => 2, 'name' => 'notebooks', '_lft' => 2, '_rgt' => 7, 'parent_id' => 1), - array('id' => 3, 'name' => 'apple', '_lft' => 3, '_rgt' => 4, 'parent_id' => 2), - array('id' => 4, 'name' => 'lenovo', '_lft' => 5, '_rgt' => 6, 'parent_id' => 2), - array('id' => 5, 'name' => 'mobile', '_lft' => 8, '_rgt' => 19, 'parent_id' => 1), - array('id' => 6, 'name' => 'nokia', '_lft' => 9, '_rgt' => 10, 'parent_id' => 5), - array('id' => 7, 'name' => 'samsung', '_lft' => 11, '_rgt' => 14, 'parent_id' => 5), - array('id' => 8, 'name' => 'galaxy', '_lft' => 12, '_rgt' => 13, 'parent_id' => 7), - array('id' => 9, 'name' => 'sony', '_lft' => 15, '_rgt' => 16, 'parent_id' => 5), - array('id' => 10, 'name' => 'lenovo', '_lft' => 17, '_rgt' => 18, 'parent_id' => 5), - array('id' => 11, 'name' => 'store_2', '_lft' => 21, '_rgt' => 22, 'parent_id' => null), -); \ No newline at end of file +return [ + ['id' => 1, 'name' => 'store', '_lft' => 1, '_rgt' => 20, 'parent_id' => null], + ['id' => 2, 'name' => 'notebooks', '_lft' => 2, '_rgt' => 7, 'parent_id' => 1], + ['id' => 3, 'name' => 'apple', '_lft' => 3, '_rgt' => 4, 'parent_id' => 2], + ['id' => 4, 'name' => 'lenovo', '_lft' => 5, '_rgt' => 6, 'parent_id' => 2], + ['id' => 5, 'name' => 'mobile', '_lft' => 8, '_rgt' => 19, 'parent_id' => 1], + ['id' => 6, 'name' => 'nokia', '_lft' => 9, '_rgt' => 10, 'parent_id' => 5], + ['id' => 7, 'name' => 'samsung', '_lft' => 11, '_rgt' => 14, 'parent_id' => 5], + ['id' => 8, 'name' => 'galaxy', '_lft' => 12, '_rgt' => 13, 'parent_id' => 7], + ['id' => 9, 'name' => 'sony', '_lft' => 15, '_rgt' => 16, 'parent_id' => 5], + ['id' => 10, 'name' => 'lenovo', '_lft' => 17, '_rgt' => 18, 'parent_id' => 5], + ['id' => 11, 'name' => 'store_2', '_lft' => 21, '_rgt' => 22, 'parent_id' => null], +]; \ No newline at end of file diff --git a/tests/data/menu_items.php b/tests/data/menu_items.php index 5490f7d..fba6acb 100644 --- a/tests/data/menu_items.php +++ b/tests/data/menu_items.php @@ -1,8 +1,10 @@ - 1, 'menu_id' => 1, '_lft' => 1, '_rgt' => 2, 'parent_id' => null, 'title' => 'menu item 1' ], - [ 'id' => 2, 'menu_id' => 1, '_lft' => 3, '_rgt' => 6, 'parent_id' => null, 'title' => 'menu item 2' ], - [ 'id' => 5, 'menu_id' => 1, '_lft' => 4, '_rgt' => 5, 'parent_id' => 2, 'title' => 'menu item 3' ], - [ 'id' => 3, 'menu_id' => 2, '_lft' => 1, '_rgt' => 2, 'parent_id' => null, 'title' => 'menu item 1' ], - [ 'id' => 4, 'menu_id' => 2, '_lft' => 3, '_rgt' => 6, 'parent_id' => null, 'title' => 'menu item 2' ], - [ 'id' => 6, 'menu_id' => 2, '_lft' => 4, '_rgt' => 5, 'parent_id' => 4, 'title' => 'menu item 3' ], + 1, 'menu_id' => 1, '_lft' => 1, '_rgt' => 2, 'parent_id' => null, 'title' => 'menu item 1' ], + ['id' => 2, 'menu_id' => 1, '_lft' => 3, '_rgt' => 6, 'parent_id' => null, 'title' => 'menu item 2' ], + ['id' => 5, 'menu_id' => 1, '_lft' => 4, '_rgt' => 5, 'parent_id' => 2, 'title' => 'menu item 3' ], + ['id' => 3, 'menu_id' => 2, '_lft' => 1, '_rgt' => 2, 'parent_id' => null, 'title' => 'menu item 1' ], + ['id' => 4, 'menu_id' => 2, '_lft' => 3, '_rgt' => 6, 'parent_id' => null, 'title' => 'menu item 2' ], + ['id' => 6, 'menu_id' => 2, '_lft' => 4, '_rgt' => 5, 'parent_id' => 4, 'title' => 'menu item 3' ], ]; \ No newline at end of file diff --git a/tests/models/Category.php b/tests/models/Category.php index bcce8e9..0c35daa 100644 --- a/tests/models/Category.php +++ b/tests/models/Category.php @@ -1,12 +1,17 @@ Date: Tue, 19 Mar 2024 12:14:55 +0100 Subject: [PATCH 51/51] Update readme --- README.markdown | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index 7a3b0fb..f4d2d51 100644 --- a/README.markdown +++ b/README.markdown @@ -4,8 +4,9 @@ [![Latest Unstable Version](https://poser.pugx.org/kalnoy/nestedset/v/unstable.svg)](https://packagist.org/packages/kalnoy/nestedset) [![License](https://poser.pugx.org/kalnoy/nestedset/license.svg)](https://packagist.org/packages/kalnoy/nestedset) -This is a Laravel 4-10 package for working with trees in relational databases. +This is a Laravel 4-11 package for working with trees in relational databases. +* **Laravel 11.0** is supported since v7 * **Laravel 10.0** is supported since v6.0.2 * **Laravel 9.0** is supported since v6.0.1 * **Laravel 8.0** is supported since v6.0.0