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.

PHP 7 support #59

Merged
merged 4 commits into from
Mar 16, 2017
Merged
Show file tree
Hide file tree
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
44 changes: 19 additions & 25 deletions soapclient/SforceEnterpriseClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
require_once ('SforceBaseClient.php');

/**
* This file contains two classes.
* @package SalesforceSoapClient
Expand All @@ -37,11 +36,9 @@
*/
class SforceEnterpriseClient extends SforceBaseClient {
const ENTERPRISE_NAMESPACE = 'urn:enterprise.soap.sforce.com';

function SforceEnterpriseClient() {
public function __construct() {
$this->namespace = self::ENTERPRISE_NAMESPACE;
}

/**
* Adds one or more new individual objects to your organization's data.
* @param array $sObjects Array of one or more sObjects (up to 200) to create.
Expand All @@ -50,7 +47,8 @@ function SforceEnterpriseClient() {
* @return SaveResult
*/
public function create($sObjects, $type) {
foreach ($sObjects as &$sObject) {
$arg = [];
foreach ($sObjects as $sObject) {
// FIX for fieldsToNull issue - allow array in fieldsToNull (STEP #1)
$xmlStr = '';
if(isset($sObject->fieldsToNull) && is_array($sObject->fieldsToNull)) {
Expand All @@ -60,19 +58,16 @@ public function create($sObjects, $type) {
}
// ------

$sObject = new SoapVar($sObject, SOAP_ENC_OBJECT, $type, $this->namespace);

$soapObject = new SoapVar($sObject, SOAP_ENC_OBJECT, $type, $this->namespace);
// FIX for fieldsToNull issue - allow array in fieldsToNull (STEP #2)
if($xmlStr != '') {
$sObject->enc_value->fieldsToNull = new SoapVar(new SoapVar($xmlStr, XSD_ANYXML), SOAP_ENC_ARRAY);
$soapObject->enc_value->fieldsToNull = new SoapVar(new SoapVar($xmlStr, XSD_ANYXML), SOAP_ENC_ARRAY);
}
// ------
$arg[] = $soapObject;
}
$arg = $sObjects;

return parent::_create(new SoapParam($arg, "sObjects"));
}

/**
* Updates one or more new individual objects to your organization's data.
* @param array sObjects Array of sObjects
Expand All @@ -81,9 +76,9 @@ public function create($sObjects, $type) {
* @return UpdateResult
*/
public function update($sObjects, $type, $assignment_header = NULL, $mru_header = NULL) {

foreach ($sObjects as &$sObject) {

$arg = new stdClass;
$arg->sObjects = [];
foreach ($sObjects as $sObject) {
// FIX for fieldsToNull issue - allow array in fieldsToNull (STEP #1)
$xmlStr = '';
if(isset($sObject->fieldsToNull) && is_array($sObject->fieldsToNull)) {
Expand All @@ -93,19 +88,18 @@ public function update($sObjects, $type, $assignment_header = NULL, $mru_header
}
// ------

$sObject = new SoapVar($sObject, SOAP_ENC_OBJECT, $type, $this->namespace);
$soapObject = new SoapVar($sObject, SOAP_ENC_OBJECT, $type, $this->namespace);

// FIX for fieldsToNull issue - allow array in fieldsToNull (STEP #2)
if($xmlStr != '') {
$sObject->enc_value->fieldsToNull = new SoapVar(new SoapVar($xmlStr, XSD_ANYXML), SOAP_ENC_ARRAY);
$soapObject->enc_value->fieldsToNull = new SoapVar(new SoapVar($xmlStr, XSD_ANYXML), SOAP_ENC_ARRAY);
}
// ------
$arg->sObjects[] = $soapObject;
}
$arg = new stdClass;
$arg->sObjects = $sObjects;

return parent::_update($arg);
}

/**
* Creates new objects and updates existing objects; uses a custom field to
* determine the presence of existing objects. In most cases, we recommend
Expand All @@ -119,8 +113,9 @@ public function update($sObjects, $type, $assignment_header = NULL, $mru_header
*/
public function upsert($ext_Id, $sObjects, $type = 'Contact') {
$arg = new stdClass;
$arg->sObjects = [];
$arg->externalIDFieldName = new SoapVar($ext_Id, XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema');
foreach ($sObjects as &$sObject) {
foreach ($sObjects as $sObject) {
// FIX for fieldsToNull issue - allow array in fieldsToNull (STEP #1)
$xmlStr = '';
if(isset($sObject->fieldsToNull) && is_array($sObject->fieldsToNull)) {
Expand All @@ -130,18 +125,17 @@ public function upsert($ext_Id, $sObjects, $type = 'Contact') {
}
// ------

$sObject = new SoapVar($sObject, SOAP_ENC_OBJECT, $type, $this->namespace);

$soapObject = new SoapVar($sObject, SOAP_ENC_OBJECT, $type, $this->namespace);
// FIX for fieldsToNull issue - allow array in fieldsToNull (STEP #2)
if($xmlStr != '') {
$sObject->enc_value->fieldsToNull = new SoapVar(new SoapVar($xmlStr, XSD_ANYXML), SOAP_ENC_ARRAY);
$soapObject->enc_value->fieldsToNull = new SoapVar(new SoapVar($xmlStr, XSD_ANYXML), SOAP_ENC_ARRAY);
}
// ------
$arg->sObjects[] = $soapObject;
}
$arg->sObjects = $sObjects;

return parent::_upsert($arg);
}

/**
* Merge records
*
Expand Down
4 changes: 2 additions & 2 deletions soapclient/SforcePartnerClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function __doRequest($request, $location, $action, $version, $one_way=0) {
class SforcePartnerClient extends SforceBaseClient {
const PARTNER_NAMESPACE = 'urn:partner.soap.sforce.com';

function SforcePartnerClient() {
public function __construct() {
$this->namespace = self::PARTNER_NAMESPACE;
}

Expand Down Expand Up @@ -223,4 +223,4 @@ private function _retrieveResult($response) {
return $arr;
}

}
}