Example #1
0
 /**
  * Delete objects in batch
  *
  * @param array $objects Array of Objects to destroy
  */
 public static function destroyAll($objects)
 {
     $batch = array();
     foreach ($objects as $obj) {
         if (!$obj->getObjectId()) {
             throw new \RuntimeException("Cannot destroy object without ID");
         }
         // Remove duplicate objects by ID
         $batch[$obj->getObjectId()] = $obj;
     }
     if (empty($batch)) {
         return;
     }
     $requests = array();
     $objects = array();
     foreach ($batch as $obj) {
         $requests[] = array("path" => "/1.1/classes/{$obj->getClassName()}" . "/{$obj->getObjectId()}", "method" => "DELETE");
         $objects[] = $obj;
     }
     $sessionToken = User::getCurrentSessionToken();
     $response = Client::batch($requests, $sessionToken);
 }
Example #2
0
 public function testBatchGetNotFound()
 {
     $obj = array("name" => "alice");
     $resp = Client::post("/classes/TestObject", $obj);
     $this->assertNotEmpty($resp["objectId"]);
     $req[] = array("path" => "/1.1/classes/TestObject/{$resp['objectId']}", "method" => "GET");
     $req[] = array("path" => "/1.1/classes/TestObject/nonexistent_id", "method" => "GET");
     $resp2 = Client::batch($req);
     $this->assertNotEmpty($resp2[0]["success"]);
     $this->assertEmpty($resp2[1]["success"]);
     // empty when not found
     Client::delete("/classes/TestObject/{$resp['objectId']}");
 }