@@ -61,6 +61,13 @@ class Node extends Eloquent {
61
61
*/
62
62
protected $ pending = [ 'root ' ];
63
63
64
+ /**
65
+ * Whether the node has moved since last save.
66
+ *
67
+ * @var bool
68
+ */
69
+ protected $ moved = false ;
70
+
64
71
/**
65
72
* Keep track of the number of performed operations.
66
73
*
@@ -117,6 +124,20 @@ protected static function signOnEvents()
117
124
}
118
125
}
119
126
127
+ /**
128
+ * {@inheritdoc}
129
+ *
130
+ * Saves a node in a transaction.
131
+ *
132
+ */
133
+ public function save (array $ options = array ())
134
+ {
135
+ return $ this ->getConnection ()->transaction (function () use ($ options )
136
+ {
137
+ return parent ::save ($ options );
138
+ });
139
+ }
140
+
120
141
/**
121
142
* Set an action.
122
143
*
@@ -144,14 +165,16 @@ protected function clearAction()
144
165
*/
145
166
protected function callPendingAction ()
146
167
{
168
+ $ this ->moved = false ;
169
+
147
170
if ( ! $ this ->pending ) return ;
148
171
149
172
$ method = 'action ' .ucfirst (array_shift ($ this ->pending ));
150
173
$ parameters = $ this ->pending ;
151
174
152
175
$ this ->pending = null ;
153
176
154
- return call_user_func_array ([ $ this , $ method ], $ parameters );
177
+ $ this -> moved = call_user_func_array ([ $ this , $ method ], $ parameters );
155
178
}
156
179
157
180
/**
@@ -170,6 +193,8 @@ protected function actionRoot()
170
193
return true ;
171
194
}
172
195
196
+ if ($ this ->isRoot ()) return false ;
197
+
173
198
// Reset parent object
174
199
$ this ->setParent (null );
175
200
@@ -290,7 +315,6 @@ public function refreshNode()
290
315
$ attributes = $ this ->newServiceQuery ()->getNodeData ($ this ->getKey ());
291
316
292
317
$ this ->attributes = array_merge ($ this ->attributes , $ attributes );
293
- $ this ->original = array_merge ($ this ->original , $ attributes );
294
318
}
295
319
296
320
/**
@@ -595,11 +619,11 @@ protected function insertAt($position)
595
619
*/
596
620
protected function moveNode ($ position )
597
621
{
598
- $ updated = $ this ->newServiceQuery ()->moveNode ($ this ->getKey (), $ position );
622
+ $ updated = $ this ->newServiceQuery ()->moveNode ($ this ->getKey (), $ position ) > 0 ;
599
623
600
624
if ($ updated ) $ this ->refreshNode ();
601
625
602
- return $ updated > 0 ;
626
+ return $ updated ;
603
627
}
604
628
605
629
/**
@@ -941,4 +965,14 @@ public function isBroken()
941
965
{
942
966
return $ this ->getTotalErrors () > 0 ;
943
967
}
968
+
969
+ /**
970
+ * Get whether the node has moved since last save.
971
+ *
972
+ * @return bool
973
+ */
974
+ public function hasMoved ()
975
+ {
976
+ return $ this ->moved ;
977
+ }
944
978
}
0 commit comments