5454 }
5555
5656 // Filtering deleted keys
57- $ oldForeignKeys = $ oldPage ->$ relation ()->toStructure ();
58- $ newForeignKeys = $ newPage ->$ relation ()->toStructure ();
59-
57+ $ oldForeignKeys = $ oldPage ->$ relation ()->toStructure ()->toArray ();
58+ $ newForeignKeys = $ newPage ->$ relation ()->toStructure ()->toArray ();
59+ $ oldForeignKeys = array_map ('unSetID ' , $ oldForeignKeys );
60+ $ newForeignKeys = array_map ('unSetID ' , $ newForeignKeys );
6061 $ deletedForeignKeys = [];
61- foreach ($ oldForeignKeys-> toArray () as $ oldForeignKey ) {
62- if (!in_array ($ oldForeignKey , $ newForeignKeys-> toArray () )) {
62+ foreach ($ oldForeignKeys as $ oldForeignKey ) {
63+ if (!in_array ($ oldForeignKey , $ newForeignKeys )) {
6364 array_push ($ deletedForeignKeys , $ oldForeignKey );
6465 }
6566 }
@@ -161,13 +162,33 @@ function deleteRelation($page, $value, $relationField)
161162 }
162163}
163164
164- function relationIsChanged ( $ newPage , $ oldPage , $ relation )
165+ function unSetID ( $ value )
165166{
166- //Constructing safer strings for comparison
167- $ oldRelations = str_replace (["\n" , "\r" ], '' , $ oldPage ->$ relation ()->toString ());
168- $ newRelations = str_replace (["\n" , "\r" ], '' , $ newPage ->$ relation ()->toString ());
167+ $ newValue = $ value ;
168+ $ newValue ['id ' ] = 0 ;
169+ return $ newValue ;
170+ }
169171
170- return $ newRelations != $ oldRelations ;
172+ function relationIsChanged ($ newPage , $ oldPage , $ relation )
173+ {
174+
175+ $ change = false ;
176+ $ oldRelationsArray = $ oldPage ->$ relation ()->toStructure ()->toArray ();
177+ $ oldRelationsArray = array_map ('unSetID ' , $ oldRelationsArray );
178+ $ newRelationsArray = $ newPage ->$ relation ()->toStructure ()->toArray ();
179+ $ newRelationsArray = array_map ('unSetID ' , $ newRelationsArray );
180+
181+ foreach ($ oldRelationsArray as $ oldRelation ) {
182+ if (!in_array ($ oldRelation , $ newRelationsArray )) {
183+ $ change = true ;
184+ }
185+ }
186+ foreach ($ newRelationsArray as $ newRelation ) {
187+ if (!in_array ($ newRelation , $ oldRelationsArray )) {
188+ $ change = true ;
189+ }
190+ }
191+ return $ change ;
171192}
172193
173194function addRelation ($ page , $ value , $ relationField )
@@ -201,4 +222,4 @@ function addRelation($page, $value, $relationField)
201222 return $ e ->getMessage ();
202223 }
203224 }
204- }
225+ }
0 commit comments