@@ -511,6 +511,58 @@ public function fetch($useMasterKey = false)
511
511
$ this ->_mergeAfterFetch ($ response );
512
512
}
513
513
514
+ /**
515
+ * Fetch an array of Parse objects from the server
516
+ *
517
+ * @param array $objects The ParseObjects to fetch
518
+ * @param boolean $useMasterKey Whether to override ACLs
519
+ *
520
+ * @return array
521
+ */
522
+ public static function fetchAll (array $ objects , $ useMasterKey = false ) {
523
+ $ objectIds = static ::toObjectIdArray ($ objects );
524
+ if (!count ($ objectIds )) return $ objects ;
525
+ $ className = $ objects [0 ]->getClassName ();
526
+ $ query = new ParseQuery ($ className );
527
+ $ query ->containedIn ("objectId " , $ objectIds );
528
+ $ query ->limit (count ($ objectIds ));
529
+ $ results = $ query ->find ($ useMasterKey );
530
+ return static ::updateWithFetchedResults ($ objects , $ results );
531
+ }
532
+
533
+ private static function toObjectIdArray (array $ objects ) {
534
+ $ objectIds = [];
535
+ $ count = count ($ objects );
536
+ if (!$ count ) return $ objectIds ;
537
+ $ className = $ objects [0 ]->getClassName ();
538
+ for ($ i = 0 ; $ i < $ count ; $ i ++) {
539
+ $ obj = $ objects [$ i ];
540
+ if ($ obj ->getClassName () !== $ className ) {
541
+ throw new ParseException ("All objects should be of the same class. " );
542
+ } else if (!$ obj ->getObjectId ()) {
543
+ throw new ParseException ("All objects must have an ID. " );
544
+ }
545
+ array_push ($ objectIds , $ obj ->getObjectId ());
546
+ }
547
+ return $ objectIds ;
548
+ }
549
+
550
+ private static function updateWithFetchedResults (array $ objects , array $ fetched ) {
551
+ $ fetchedObjectsById = [];
552
+ foreach ($ fetched as $ object ) {
553
+ $ fetchedObjectsById [$ object ->getObjectId ()] = $ object ;
554
+ }
555
+ $ count = count ($ objects );
556
+ for ($ i = 0 ; $ i < $ count ; $ i ++) {
557
+ $ obj = $ objects [$ i ];
558
+ if (!isset ($ fetchedObjectsById [$ obj ->getObjectId ()])) {
559
+ throw new ParseException ("All objects must exist on the server. " );
560
+ }
561
+ $ obj ->mergeFromObject ($ fetchedObjectsById [$ obj ->getObjectId ()]);
562
+ }
563
+ return $ objects ;
564
+ }
565
+
514
566
/**
515
567
* Merges data received from the server.
516
568
*
@@ -589,6 +641,17 @@ private function mergeFromServer($data, $completeData = true)
589
641
}
590
642
}
591
643
644
+ private function mergeFromObject ($ other ) {
645
+ if (!$ other ) return ;
646
+ $ this ->objectId = $ other ->getObjectId ();
647
+ $ this ->createdAt = $ other ->getCreatedAt ();
648
+ $ this ->updatedAt = $ other ->getUpdatedAt ();
649
+ $ this ->serverData = $ other ->serverData ;
650
+ $ this ->operationSet = [];
651
+ $ this ->hasBeenFetched = true ;
652
+ $ this ->rebuildEstimatedData ();
653
+ }
654
+
592
655
/**
593
656
* Handle merging of special fields for the object.
594
657
*
0 commit comments