diff --git a/.travis.yml b/.travis.yml index 4a7ff2b..cd3ddd0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: php php: - - 5.3 - 5.4 - 5.5 diff --git a/CHANGELOG.markdown b/CHANGELOG.markdown index 727215e..69f5592 100644 --- a/CHANGELOG.markdown +++ b/CHANGELOG.markdown @@ -1,2 +1,3 @@ -### 1.0.1 -* `Collection::toDictionary` is now obsolete. Use `Collection::groupBy`. \ No newline at end of file +### 1.1.0 +* `Collection::toDictionary` is now obsolete. Use `Collection::groupBy`. +* Laravel 4.2 is required \ No newline at end of file diff --git a/composer.json b/composer.json index eee4ff2..011cbef 100644 --- a/composer.json +++ b/composer.json @@ -12,9 +12,9 @@ ], "require": { - "php": ">=5.3.0", - "illuminate/support": "~4.1.18", - "illuminate/database": "~4.1.18" + "php": ">=5.4.0", + "illuminate/support": "~4.2.1", + "illuminate/database": "~4.2.1" }, "require-dev": { diff --git a/src/Kalnoy/Nestedset/Node.php b/src/Kalnoy/Nestedset/Node.php index 04b4c24..235c5fb 100644 --- a/src/Kalnoy/Nestedset/Node.php +++ b/src/Kalnoy/Nestedset/Node.php @@ -1,4 +1,6 @@ -exists || $node->isDirty(static::LFT)) + if ( ! $node->exists || $node->isDirty(static::LFT)) { throw new Exception("Target node is updated but not saved."); } @@ -361,19 +384,19 @@ public function fireModelEvent($event, $halt = true) { if ($this->exists) { - if ($this->isDirty(static::LFT) && !$this->updateTree()) + if ($this->isDirty(static::LFT) && ! $this->updateTree()) { return false; } } else { - if (!isset($this->attributes[static::LFT])) + if ( ! isset($this->attributes[static::LFT])) { throw new Exception("Cannot save node until it is inserted."); } - if (!$this->updateTree()) return false; + if ( ! $this->updateTree()) return false; } } @@ -382,7 +405,7 @@ public function fireModelEvent($event, $halt = true) throw new Exception("Cannot delete root node."); } - if ($event === 'deleted' && !$this->softDelete) $this->deleteNode(); + if ($event === 'deleted' && ! static::$softDelete) $this->deleteNode(); return parent::fireModelEvent($event, $halt); } @@ -591,6 +614,16 @@ protected function newBaseQueryBuilder() return new QueryBuilder($conn, $grammar, $conn->getPostProcessor(), $this); } + /** + * Get a new query including deleted nodes. + * + * @since 1.1 + */ + protected function newQueryWithDeleted() + { + return static::$softDelete ? $this->withTrashed() : $this->newQuery(); + } + /** * Create a new NestedSet Collection instance. * @@ -610,7 +643,7 @@ public function newCollection(array $models = array()) */ public function getNodeHeight() { - if (!$this->exists) return 2; + if ( ! $this->exists) return 2; return $this->attributes[static::RGT] - $this->attributes[static::LFT] + 1; } @@ -635,7 +668,7 @@ public function getDescendantCount() */ public function setParentIdAttribute($value) { - if (!isset($this->attributes[static::PARENT_ID]) || $this->attributes[static::PARENT_ID] != $value) + if ( ! isset($this->attributes[static::PARENT_ID]) || $this->attributes[static::PARENT_ID] != $value) { $this->appendTo(static::findOrFail($value)); } diff --git a/tests/NodeTest.php b/tests/NodeTest.php index 70a90d0..b9f6714 100644 --- a/tests/NodeTest.php +++ b/tests/NodeTest.php @@ -48,7 +48,7 @@ public function assertTreeNotBroken($table = 'categories') // Check if lft and rgt values are unique $checks[] = "from $table c1, $table c2 where c1.id <> c2.id and ". "(c1._lft=c2._lft or c1._rgt=c2._rgt or c1._lft=c2._rgt or c1._rgt=c2._lft)"; - + // Check if parent_id is set correctly $checks[] = "from $table c, $table p, $table m where c.parent_id=p.id and m.id <> p.id and m.id <> c.id and ". "(c._lft not between p._lft and p._rgt or c._lft between m._lft and m._rgt and m._lft between p._lft and p._rgt)";