Skip to content

Commit f48c1ad

Browse files
ildyrianagmat84
andauthored
Added ORDER BY to delete operation + update composer.json + fix tests (#7)
* Adjusted composer.json * Adjusted `readme.md` * Fixes upstream issue lazychaser#538 * exclude 8.1 low * Fixed order of deletion. (#5) * Added ORDER BY to delete operation. * lazychaser#552 * bumping version of phpunit to 9.5.20 Co-authored-by: Matthias Nagel <[email protected]>
1 parent 350b3c5 commit f48c1ad

13 files changed

+529
-89
lines changed

.github/workflows/CI.yaml

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
name: Tests
2+
3+
# Run this workflow every time a new commit pushed to your repository
4+
on:
5+
push:
6+
paths-ignore:
7+
- '**/*.md'
8+
pull_request:
9+
paths-ignore:
10+
- '**/*.md'
11+
12+
jobs:
13+
tests:
14+
runs-on: ${{ matrix.operating-system }}
15+
if: (github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository)
16+
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
operating-system: [ubuntu-20.04]
21+
php-versions: ['7.4', '8.0', '8.1']
22+
dependencies: ['no', 'low', 'beta']
23+
exclude:
24+
- operating-system: ubuntu-20.04
25+
php-versions: '8.1'
26+
dependencies: 'low'
27+
28+
name: PHP ${{ matrix.php-versions }} - ${{ matrix.dependencies }}
29+
30+
env:
31+
COMPOSER_NO_INTERACTION: 1
32+
extensions: curl json libxml dom
33+
key: cache-v1 # can be any string, change to clear the extension cache.
34+
35+
steps:
36+
37+
# Checks out a copy of your repository on the ubuntu machine
38+
- name: Checkout code
39+
uses: actions/checkout@v2
40+
41+
- name: Setup cache environment
42+
id: extcache
43+
uses: shivammathur/cache-extensions@v1
44+
with:
45+
php-version: ${{ matrix.php-versions }}
46+
extensions: ${{ env.extensions }}
47+
key: ${{ env.key }}
48+
49+
- name: Cache PHP Extensions
50+
uses: actions/cache@v2
51+
with:
52+
path: ${{ steps.extcache.outputs.dir }}
53+
key: ${{ steps.extcache.outputs.key }}
54+
restore-keys: ${{ steps.extcache.outputs.key }}
55+
56+
- name: Cache Composer Dependencies
57+
uses: actions/cache@v1
58+
with:
59+
path: ~/.composer/cache/files
60+
key: dependencies-composer-${{ hashFiles('composer.json') }}
61+
62+
- name: Fix beta
63+
if: ${{ matrix.dependencies == 'beta' }}
64+
run: perl -pi -e 's/^}$/,"minimum-stability":"beta"}/' composer.json
65+
66+
- name: Setup PHP Action
67+
uses: shivammathur/[email protected]
68+
with:
69+
php-version: ${{ matrix.php-versions }}
70+
extensions: ${{ env.extensions }}
71+
coverage: xdebug
72+
tools: pecl, composer
73+
74+
- name: PHP Show modules
75+
run: php -m
76+
77+
- name: Get composer cache directory
78+
id: composer-cache
79+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
80+
81+
- name: Cache dependencies
82+
uses: actions/cache@v2
83+
with:
84+
path: ${{ steps.composer-cache.outputs.dir }}
85+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
86+
restore-keys: ${{ runner.os }}-composer-
87+
88+
- name: Install Composer dependencies
89+
if: ${{ matrix.dependencies != 'low' }}
90+
run: composer update --no-interaction
91+
92+
- name: Install Composer dependencies
93+
if: ${{ matrix.dependencies == 'low' }}
94+
run: composer update -vvv --prefer-lowest --prefer-stable --no-interaction
95+
96+
- name: Validate files
97+
run: composer validate-files
98+
99+
- name: Run tests
100+
run: composer run-tests

.github/workflows/run-tests.yml

-43
This file was deleted.

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
composer.phar
44
composer.lock
55
.DS_Store
6+
.php-cs-fixer.cache
67
.phpunit.result.cache

README.markdown

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
[![Build Status](https://travis-ci.org/lazychaser/laravel-nestedset.svg?branch=master)](https://travis-ci.org/lazychaser/laravel-nestedset)
2-
[![Total Downloads](https://poser.pugx.org/kalnoy/nestedset/downloads.svg)](https://packagist.org/packages/kalnoy/nestedset)
3-
[![Latest Stable Version](https://poser.pugx.org/kalnoy/nestedset/v/stable.svg)](https://packagist.org/packages/kalnoy/nestedset)
4-
[![Latest Unstable Version](https://poser.pugx.org/kalnoy/nestedset/v/unstable.svg)](https://packagist.org/packages/kalnoy/nestedset)
5-
[![License](https://poser.pugx.org/kalnoy/nestedset/license.svg)](https://packagist.org/packages/kalnoy/nestedset)
1+
[![Total Downloads](https://poser.pugx.org/lychee-org/nestedset/downloads.svg)](https://packagist.org/packages/lychee-org/nestedset)
2+
[![Latest Stable Version](https://poser.pugx.org/lychee-org/nestedset/v/stable.svg)](https://packagist.org/packages/lychee-org/nestedset)
3+
[![Latest Unstable Version](https://poser.pugx.org/lychee-org/nestedset/v/unstable.svg)](https://packagist.org/packages/lychee-org/nestedset)
4+
[![License](https://poser.pugx.org/lychee-org/nestedset/license.svg)](https://packagist.org/packages/lychee-org/nestedset)
65

76
This is a Laravel 4-8 package for working with trees in relational databases.
87

8+
It is a fork of [lazychaser/laravel-nestedset](https://github.com/lazychaser/laravel-nestedset) and contains general patches which are required for using the library with [Lychee](https://github.com/LycheeOrg/Lychee). Note that the patches are **not** specific for Lychee, but a generally useful. Inter alia:
9+
10+
* Routines respect a foreign key constraint on the parent-child-relation by taking care that changes to the tree are applied in the correct order.
11+
* The code does not fail if the model which uses `NoteTrait` does not directly extend `Model` but indirectly inherits `Model` via another parent class.
12+
913
* **Laravel 8.0** is supported since v6
1014
* **Laravel 5.7, 5.8, 6.0, 7.0** is supported since v5
1115
* **Laravel 5.5, 5.6** is supported since v4.3
1216
* **Laravel 5.2, 5.3, 5.4** is supported since v4
1317
* **Laravel 5.1** is supported in v3
1418
* **Laravel 4** is supported in v2
1519

16-
Although this project is completely free for use, I appreciate any support!
17-
18-
- __[Donate via PayPal](https://www.paypal.me/lazychaser)__
19-
2020
__Contents:__
2121

2222
- [Theory](#what-are-nested-sets)

composer.json

+13-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "kalnoy/nestedset",
3-
"description": "Nested Set Model for Laravel 5.7 and up",
2+
"name": "lychee-org/nestedset",
3+
"description": "Nested Set Model for Laravel 5.7 and up (fork with patches for Lychee)",
44
"keywords": ["laravel", "nested sets", "nsm", "database", "hierarchy"],
55
"license": "MIT",
66

@@ -25,9 +25,19 @@
2525
},
2626

2727
"require-dev": {
28-
"phpunit/phpunit": "7.*|8.*|9.*"
28+
"php-parallel-lint/php-parallel-lint": "^1.2",
29+
"phpunit/phpunit": "^9.5.20"
2930
},
3031

32+
"scripts": {
33+
"run-tests": [
34+
"vendor/bin/phpunit -c phpunit.xml",
35+
"vendor/bin/phpunit -c phpunit.xml --coverage-clover=coverage.xml"
36+
],
37+
"validate-files": [
38+
"vendor/bin/parallel-lint --exclude vendor ."
39+
]
40+
},
3141
"minimum-stability": "dev",
3242
"prefer-stable": true,
3343

@@ -41,10 +51,5 @@
4151
"Kalnoy\\Nestedset\\NestedSetServiceProvider"
4252
]
4353
}
44-
},
45-
"scripts": {
46-
"test": [
47-
"@php ./vendor/bin/phpunit"
48-
]
4954
}
5055
}

phpunit.xml

+11-20
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit backupGlobals="false"
3-
backupStaticAttributes="false"
4-
bootstrap="phpunit.php"
5-
colors="true"
6-
convertErrorsToExceptions="true"
7-
convertNoticesToExceptions="true"
8-
convertWarningsToExceptions="true"
9-
processIsolation="false"
10-
>
11-
<testsuites>
12-
<testsuite name="Package Test Suite">
13-
<directory suffix=".php">./tests/</directory>
14-
</testsuite>
15-
</testsuites>
16-
17-
<filter>
18-
<whitelist>
19-
<directory>./src</directory>
20-
</whitelist>
21-
</filter>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" bootstrap="phpunit.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
3+
<coverage>
4+
<include>
5+
<directory>./src</directory>
6+
</include>
7+
</coverage>
8+
<testsuites>
9+
<testsuite name="Package Test Suite">
10+
<directory suffix=".php">./tests/</directory>
11+
</testsuite>
12+
</testsuites>
2213
</phpunit>

src/BaseRelation.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public function addEagerConstraints(array $models)
144144
// The first model in the array is always the parent, so add the scope constraints based on that model.
145145
// @link https://github.com/laravel/framework/pull/25240
146146
// @link https://github.com/lazychaser/laravel-nestedset/issues/351
147-
optional($models[0])->applyNestedSetScope($this->query);
147+
optional(reset($models))->applyNestedSetScope($this->query);
148148

149149
$this->query->whereNested(function (Builder $inner) use ($models) {
150150
// We will use this query in order to apply constraints to the

src/NestedSet.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public static function getDefaultColumns()
7777
*/
7878
public static function isNode($node)
7979
{
80-
return is_object($node) && in_array(NodeTrait::class, (array)$node);
80+
return $node instanceof Node;
8181
}
8282

8383
}

0 commit comments

Comments
 (0)