Skip to content

Allow saving Parse Objects with Master Key #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 16, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/Parse/ParseObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -818,38 +818,42 @@ private function getSaveJSON()
/**
* Save Object to Parse
*
* @param bool $useMasterKey Whether to use the Master Key.
*
* @return null
*/
public function save()
public function save($useMasterKey = false)
{
if (!$this->isDirty()) {
return;
}
static::deepSave($this);
static::deepSave($this, $useMasterKey);
}

/**
* Save all the objects in the provided array
*
* @param array $list
* @param bool $useMasterKey Whether to use the Master Key.
*
* @return null
*/
public static function saveAll($list)
public static function saveAll($list, $useMasterKey = false)
{
static::deepSave($list);
static::deepSave($list, $useMasterKey);
}

/**
* Save Object and unsaved children within.
*
* @param $target
* @param bool $useMasterKey Whether to use the Master Key.
*
* @return null
*
* @throws ParseException
*/
private static function deepSave($target)
private static function deepSave($target, $useMasterKey = false)
{
$unsavedChildren = array();
$unsavedFiles = array();
Expand Down Expand Up @@ -916,7 +920,7 @@ private static function deepSave($target)
$batch[0]->mergeAfterSave($result);
} else {
$result = ParseClient::_request('POST', '/1/batch', $sessionToken,
json_encode(array("requests" => $requests)));
json_encode(array("requests" => $requests)), $useMasterKey);

$errorCollection = array();

Expand Down