@@ -252,27 +252,43 @@ public function updateAcl(MutableAclInterface $acl)
252
252
}
253
253
}
254
254
255
+ // check properties for deleted, and created ACEs, and perform deletions
256
+ // we need to perfom deletions before updating existing ACEs, in order to
257
+ // preserve uniqueness of the order field
258
+ if (isset ($ propertyChanges ['classAces ' ])) {
259
+ $ this ->updateOldAceProperty ('classAces ' , $ propertyChanges ['classAces ' ]);
260
+ }
261
+ if (isset ($ propertyChanges ['classFieldAces ' ])) {
262
+ $ this ->updateOldFieldAceProperty ('classFieldAces ' , $ propertyChanges ['classFieldAces ' ]);
263
+ }
264
+ if (isset ($ propertyChanges ['objectAces ' ])) {
265
+ $ this ->updateOldAceProperty ('objectAces ' , $ propertyChanges ['objectAces ' ]);
266
+ }
267
+ if (isset ($ propertyChanges ['objectFieldAces ' ])) {
268
+ $ this ->updateOldFieldAceProperty ('objectFieldAces ' , $ propertyChanges ['objectFieldAces ' ]);
269
+ }
270
+
255
271
// this includes only updates of existing ACEs, but neither the creation, nor
256
272
// the deletion of ACEs; these are tracked by changes to the ACL's respective
257
273
// properties (classAces, classFieldAces, objectAces, objectFieldAces)
258
274
if (isset ($ propertyChanges ['aces ' ])) {
259
275
$ this ->updateAces ($ propertyChanges ['aces ' ]);
260
276
}
261
277
262
- // check properties for deleted, and created ACEs
278
+ // check properties for deleted, and created ACEs, and perform creations
263
279
if (isset ($ propertyChanges ['classAces ' ])) {
264
- $ this ->updateAceProperty ('classAces ' , $ propertyChanges ['classAces ' ]);
280
+ $ this ->updateNewAceProperty ('classAces ' , $ propertyChanges ['classAces ' ]);
265
281
$ sharedPropertyChanges ['classAces ' ] = $ propertyChanges ['classAces ' ];
266
282
}
267
283
if (isset ($ propertyChanges ['classFieldAces ' ])) {
268
- $ this ->updateFieldAceProperty ('classFieldAces ' , $ propertyChanges ['classFieldAces ' ]);
284
+ $ this ->updateNewFieldAceProperty ('classFieldAces ' , $ propertyChanges ['classFieldAces ' ]);
269
285
$ sharedPropertyChanges ['classFieldAces ' ] = $ propertyChanges ['classFieldAces ' ];
270
286
}
271
287
if (isset ($ propertyChanges ['objectAces ' ])) {
272
- $ this ->updateAceProperty ('objectAces ' , $ propertyChanges ['objectAces ' ]);
288
+ $ this ->updateNewAceProperty ('objectAces ' , $ propertyChanges ['objectAces ' ]);
273
289
}
274
290
if (isset ($ propertyChanges ['objectFieldAces ' ])) {
275
- $ this ->updateFieldAceProperty ('objectFieldAces ' , $ propertyChanges ['objectFieldAces ' ]);
291
+ $ this ->updateNewFieldAceProperty ('objectFieldAces ' , $ propertyChanges ['objectFieldAces ' ]);
276
292
}
277
293
278
294
// if there have been changes to shared properties, we need to synchronize other
@@ -740,12 +756,12 @@ private function regenerateAncestorRelations(AclInterface $acl)
740
756
}
741
757
742
758
/**
743
- * This processes changes on an ACE related property (classFieldAces, or objectFieldAces).
759
+ * This processes new entries changes on an ACE related property (classFieldAces, or objectFieldAces).
744
760
*
745
761
* @param string $name
746
762
* @param array $changes
747
763
*/
748
- private function updateFieldAceProperty ($ name , array $ changes )
764
+ private function updateNewFieldAceProperty ($ name , array $ changes )
749
765
{
750
766
$ sids = new \SplObjectStorage ();
751
767
$ classIds = new \SplObjectStorage ();
@@ -782,6 +798,26 @@ private function updateFieldAceProperty($name, array $changes)
782
798
}
783
799
}
784
800
}
801
+ }
802
+
803
+ /**
804
+ * This process old entries changes on an ACE related property (classFieldAces, or objectFieldAces).
805
+ *
806
+ * @param string $name
807
+ * @param array $changes
808
+ */
809
+ private function updateOldFieldAceProperty ($ ane , array $ changes )
810
+ {
811
+ $ currentIds = array ();
812
+ foreach ($ changes [1 ] as $ field => $ new ) {
813
+ for ($ i =0 ,$ c =count ($ new ); $ i <$ c ; $ i ++) {
814
+ $ ace = $ new [$ i ];
815
+
816
+ if (null != $ ace ->getId ()) {
817
+ $ currentIds [$ ace ->getId ()] = true ;
818
+ }
819
+ }
820
+ }
785
821
786
822
foreach ($ changes [0 ] as $ old ) {
787
823
for ($ i =0 ,$ c =count ($ old ); $ i <$ c ; $ i ++) {
@@ -796,12 +832,12 @@ private function updateFieldAceProperty($name, array $changes)
796
832
}
797
833
798
834
/**
799
- * This processes changes on an ACE related property (classAces, or objectAces).
835
+ * This processes new entries changes on an ACE related property (classAces, or objectAces).
800
836
*
801
837
* @param string $name
802
838
* @param array $changes
803
839
*/
804
- private function updateAceProperty ($ name , array $ changes )
840
+ private function updateNewAceProperty ($ name , array $ changes )
805
841
{
806
842
list ($ old , $ new ) = $ changes ;
807
843
@@ -838,6 +874,26 @@ private function updateAceProperty($name, array $changes)
838
874
$ currentIds [$ ace ->getId ()] = true ;
839
875
}
840
876
}
877
+ }
878
+
879
+ /**
880
+ * This processes old entries changes on an ACE related property (classAces, or objectAces).
881
+ *
882
+ * @param string $name
883
+ * @param array $changes
884
+ */
885
+ private function updateOldAceProperty ($ name , array $ changes )
886
+ {
887
+ list ($ old , $ new ) = $ changes ;
888
+ $ currentIds = array ();
889
+
890
+ for ($ i =0 ,$ c =count ($ new ); $ i <$ c ; $ i ++) {
891
+ $ ace = $ new [$ i ];
892
+
893
+ if (null != $ ace ->getId ()) {
894
+ $ currentIds [$ ace ->getId ()] = true ;
895
+ }
896
+ }
841
897
842
898
for ($ i =0 ,$ c =count ($ old ); $ i <$ c ; $ i ++) {
843
899
$ ace = $ old [$ i ];
@@ -857,26 +913,41 @@ private function updateAceProperty($name, array $changes)
857
913
private function updateAces (\SplObjectStorage $ aces )
858
914
{
859
915
foreach ($ aces as $ ace ) {
860
- $ propertyChanges = $ aces ->offsetGet ($ ace );
861
- $ sets = array ();
916
+ $ this ->updateAce ($ aces , $ ace );
917
+ }
918
+ }
862
919
863
- if (isset ($ propertyChanges ['mask ' ])) {
864
- $ sets [] = sprintf ('mask = %d ' , $ propertyChanges ['mask ' ][1 ]);
865
- }
866
- if (isset ($ propertyChanges ['strategy ' ])) {
867
- $ sets [] = sprintf ('granting_strategy = %s ' , $ this ->connection ->quote ($ propertyChanges ['strategy ' ]));
868
- }
869
- if (isset ($ propertyChanges ['aceOrder ' ])) {
870
- $ sets [] = sprintf ('ace_order = %d ' , $ propertyChanges ['aceOrder ' ][1 ]);
871
- }
872
- if (isset ($ propertyChanges ['auditSuccess ' ])) {
873
- $ sets [] = sprintf ('audit_success = %s ' , $ this ->connection ->getDatabasePlatform ()->convertBooleans ($ propertyChanges ['auditSuccess ' ][1 ]));
874
- }
875
- if (isset ($ propertyChanges ['auditFailure ' ])) {
876
- $ sets [] = sprintf ('audit_failure = %s ' , $ this ->connection ->getDatabasePlatform ()->convertBooleans ($ propertyChanges ['auditFailure ' ][1 ]));
920
+ private function updateAce (\SplObjectStorage $ aces , $ ace )
921
+ {
922
+ $ propertyChanges = $ aces ->offsetGet ($ ace );
923
+ $ sets = array ();
924
+
925
+ if (isset ($ propertyChanges ['aceOrder ' ])
926
+ && $ propertyChanges ['aceOrder ' ][1 ] > $ propertyChanges ['aceOrder ' ][0 ]
927
+ && $ propertyChanges == $ aces ->offsetGet ($ ace )) {
928
+ $ aces ->next ();
929
+ if ($ aces ->valid ()) {
930
+ $ this ->updateAce ($ aces , $ aces ->current ());
931
+ }
877
932
}
878
933
879
- $ this ->connection ->executeQuery ($ this ->getUpdateAccessControlEntrySql ($ ace ->getId (), $ sets ));
934
+ if (isset ($ propertyChanges ['mask ' ])) {
935
+ $ sets [] = sprintf ('mask = %d ' , $ propertyChanges ['mask ' ][1 ]);
936
+ }
937
+ if (isset ($ propertyChanges ['strategy ' ])) {
938
+ $ sets [] = sprintf ('granting_strategy = %s ' , $ this ->connection ->quote ($ propertyChanges ['strategy ' ]));
939
+ }
940
+ if (isset ($ propertyChanges ['aceOrder ' ])) {
941
+ $ sets [] = sprintf ('ace_order = %d ' , $ propertyChanges ['aceOrder ' ][1 ]);
942
+ }
943
+ if (isset ($ propertyChanges ['auditSuccess ' ])) {
944
+ $ sets [] = sprintf ('audit_success = %s ' , $ this ->connection ->getDatabasePlatform ()->convertBooleans ($ propertyChanges ['auditSuccess ' ][1 ]));
880
945
}
946
+ if (isset ($ propertyChanges ['auditFailure ' ])) {
947
+ $ sets [] = sprintf ('audit_failure = %s ' , $ this ->connection ->getDatabasePlatform ()->convertBooleans ($ propertyChanges ['auditFailure ' ][1 ]));
948
+ }
949
+
950
+ $ this ->connection ->executeQuery ($ this ->getUpdateAccessControlEntrySql ($ ace ->getId (), $ sets ));
881
951
}
952
+
882
953
}
0 commit comments