diff --git a/src/Parse/ParseObject.php b/src/Parse/ParseObject.php index bf488f62..a88d5138 100644 --- a/src/Parse/ParseObject.php +++ b/src/Parse/ParseObject.php @@ -797,16 +797,16 @@ public function destroy($useMasterKey = false) * * @param array $objects Objects to destroy. * @param bool $useMasterKey Whether to use the master key or not. + * @param int $batchSize Number of objects to process per request * * @throws ParseAggregateException */ - public static function destroyAll(array $objects, $useMasterKey = false) + public static function destroyAll(array $objects, $useMasterKey = false, $batchSize = 40) { $errors = []; $objects = array_values($objects); // To support non-ordered arrays $count = count($objects); if ($count) { - $batchSize = 40; $processed = 0; $currentBatch = []; $currentcount = 0; @@ -1153,10 +1153,11 @@ public function save($useMasterKey = false) * * @param array $list * @param bool $useMasterKey Whether to use the Master Key. + * @param int $batchSize Number of objects to process per request */ - public static function saveAll($list, $useMasterKey = false) + public static function saveAll($list, $useMasterKey = false, $batchSize = 40) { - static::deepSave($list, $useMasterKey); + static::deepSave($list, $useMasterKey, $batchSize); } /** @@ -1164,12 +1165,13 @@ public static function saveAll($list, $useMasterKey = false) * * @param ParseObject|array $target * @param bool $useMasterKey Whether to use the Master Key. + * @param int $batchSize Number of objects to process per request * * @throws Exception * @throws ParseAggregateException * @throws ParseException */ - private static function deepSave($target, $useMasterKey = false) + private static function deepSave($target, $useMasterKey = false, $batchSize = 40) { $unsavedChildren = []; $unsavedFiles = []; @@ -1197,7 +1199,7 @@ private static function deepSave($target, $useMasterKey = false) $newRemaining = []; foreach ($remaining as $key => &$object) { - if (count($batch) > 40) { + if (count($batch) > $batchSize) { $newRemaining[] = $object; continue; } diff --git a/tests/Parse/ParseObjectTest.php b/tests/Parse/ParseObjectTest.php index 454234b1..845b4505 100644 --- a/tests/Parse/ParseObjectTest.php +++ b/tests/Parse/ParseObjectTest.php @@ -818,6 +818,30 @@ public function testDestroyAll() $user->destroy(true); } + public function testBatchSize() + { + $batchSize = 1; + Helper::clearClass('TestObject'); + + // log in + $user = new ParseUser(); + $user->setUsername('username123'); + $user->setPassword('password123'); + $user->signUp(); + + $o1 = ParseObject::create('TestObject'); + $o2 = ParseObject::create('TestObject'); + $o3 = ParseObject::create('TestObject'); + ParseObject::saveAll([$o1, $o2, $o3], true, $batchSize); + ParseObject::destroyAll([$o1, $o2, $o3], true, $batchSize); + $query = new ParseQuery('TestObject'); + $results = $query->find(); + $this->assertEquals(0, count($results)); + + ParseUser::logOut(); + $user->destroy(true); + } + public function testEmptyArray() { $obj = ParseObject::create('TestObject');