Skip to content

Commit dbebf07

Browse files
committed
Allow saving Parse Objects with Master Key
1 parent 97bb205 commit dbebf07

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/Parse/ParseObject.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -818,24 +818,27 @@ private function getSaveJSON()
818818
/**
819819
* Save Object to Parse
820820
*
821+
* @param bool $useMasterKey Whether to use the Master Key.
822+
*
821823
* @return null
822824
*/
823-
public function save()
825+
public function save($useMasterKey=false)
824826
{
825827
if (!$this->isDirty()) {
826828
return;
827829
}
828-
static::deepSave($this);
830+
static::deepSave($this, $useMasterKey);
829831
}
830832

831833
/**
832834
* Save all the objects in the provided array
833835
*
834836
* @param array $list
837+
* @param bool $useMasterKey Whether to use the Master Key.
835838
*
836839
* @return null
837840
*/
838-
public static function saveAll($list)
841+
public static function saveAll($list, $useMasterKey=false)
839842
{
840843
static::deepSave($list);
841844
}
@@ -844,12 +847,13 @@ public static function saveAll($list)
844847
* Save Object and unsaved children within.
845848
*
846849
* @param $target
850+
* @param bool $useMasterKey Whether to use the Master Key.
847851
*
848852
* @return null
849853
*
850854
* @throws ParseException
851855
*/
852-
private static function deepSave($target)
856+
private static function deepSave($target, $useMasterKey=false)
853857
{
854858
$unsavedChildren = array();
855859
$unsavedFiles = array();
@@ -912,11 +916,11 @@ private static function deepSave($target)
912916
if (count($requests) === 1) {
913917
$req = $requests[0];
914918
$result = ParseClient::_request($req['method'],
915-
$req['path'], $sessionToken, json_encode($req['body']));
919+
$req['path'], $sessionToken, json_encode($req['body']), $useMasterKey);
916920
$batch[0]->mergeAfterSave($result);
917921
} else {
918922
$result = ParseClient::_request('POST', '/1/batch', $sessionToken,
919-
json_encode(array("requests" => $requests)));
923+
json_encode(array("requests" => $requests)), $useMasterKey);
920924

921925
$errorCollection = array();
922926

0 commit comments

Comments
 (0)