Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jan 10, 2024. It is now read-only.
Open
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
86 changes: 81 additions & 5 deletions soapclient/SforceBaseClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,74 @@ public function login($username, $password) {

return $result;
}

/**
* Use existing session id for this API connection
*
* @param string $sessionid Session ID
* @param string $serverurl SFDC Server Url
*
* @return LoginResult
*/
public function ContinueSession($sessionid, $serverurl)
{
$this->sforce->__setSoapHeaders(NULL);
if ($this->callOptions != NULL) {
$this->sforce->__setSoapHeaders(array($this->callOptions));
}
if ($this->loginScopeHeader != NULL) {
$this->sforce->__setSoapHeaders(array($this->loginScopeHeader));
}
/*
$result = (object) array(
'sessionId' => '00D24000000J9Sn!ARYAQB3P0gUnmUymxhM.am70IjhG816sdg5zHkJEb.szVbVq6SLkwdPk_M4F_Jj.BcWXOqJYE8Qkn4MLsM8Mf7YJrc1AbjZs',
'serverUrl' => 'https://eu5.salesforce.com/services/Soap/u/32.0'
);
*/
$result = (object) array(
'sessionId' => $sessionid,
'serverUrl' => $serverurl
);
$this->_setLoginHeader($result);

return $result;
}

public function RefreshToken($client_id, $secret, $refresh_token)
{
try{
$url = 'https://login.salesforce.com/services/oauth2/token';
$fields = array(
'grant_type' => "refresh_token",
'client_id' => $client_id,
'client_secret' => $secret,
'refresh_token' => $refresh_token
);

// $fields_string = '';
// foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }

$ch = curl_init($url);

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_POSTFIELDS, http_build_query($fields));
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
//curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

//execute post
$result = curl_exec($ch);

//close connection
curl_close($ch);

$json_a = json_decode($result,true);
return $json_a;

}catch(Exception $e){
return false;
}
}

/**
* log outs from the salseforce system`
Expand Down Expand Up @@ -219,9 +287,9 @@ public function setEndpoint($location) {
private function setHeaders($call=NULL) {
$this->sforce->__setSoapHeaders(NULL);

$header_array = array (
$this->sessionHeader
);
$header_array = array ();
if( $this->sessionHeader )
array_push($header_array, $this->sessionHeader);

$header = $this->callOptions;
if ($header != NULL) {
Expand Down Expand Up @@ -322,7 +390,6 @@ private function setHeaders($call=NULL) {
}
}


$this->sforce->__setSoapHeaders($header_array);
}

Expand Down Expand Up @@ -489,10 +556,19 @@ public function getLastResponseHeaders() {
protected function _convertToAny($fields) {
$anyString = '';
foreach ($fields as $key => $value) {
$anyString = $anyString . '<' . $key . '>' . $value . '</' . $key . '>';
$anyString = $anyString . '<' . $key . '>' . $this->_sanitizeValue($value) . '</' . $key . '>'; // scavix
}
return $anyString;
}

/**
* Added by Scavix Software 4/2015
*/
protected function _sanitizeValue($value) {
if((strpos($value, '&') !== false) || (strpos($value, '<') !== false) || (strpos($value, '>') !== false))
return '<![CDATA['.$value.']]>';
return $value;
}

protected function _create($arg) {
$this->setHeaders("create");
Expand Down