Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

Commit

Permalink
Prevent PHP from parsing away OldValue, NewValue tags in XxxHistory q…
Browse files Browse the repository at this point in the history
…ueries. Fixes #13.
  • Loading branch information
Pat Patterson committed Apr 12, 2012
1 parent d1dd8a5 commit 0c3deb6
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
10 changes: 7 additions & 3 deletions soapclient/SforceBaseClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
require_once ('ProxySettings.php');
require_once ('SforceHeaderOptions.php');


/**
* This file contains one class.
* @package SalesforceSoapClient
Expand Down Expand Up @@ -61,6 +60,10 @@ class SforceBaseClient {
protected $localeOptions;
protected $packageVersionHeader;

protected function getSoapClient($wsdl, $options) {
return new SoapClient($wsdl, $options);
}

public function getNamespace() {
return $this->namespace;
}
Expand Down Expand Up @@ -90,7 +93,7 @@ public function printDebugInfo() {
echo 'False';
}
}

/**
* Connect method to www.salesforce.com
*
Expand Down Expand Up @@ -122,7 +125,8 @@ public function createConnection($wsdl, $proxy=null) {
$soapClientArray = array_merge($soapClientArray, $proxySettings);
}

$this->sforce = new SoapClient($wsdl, $soapClientArray);
$this->sforce = $this->getSoapClient($wsdl, $soapClientArray);

return $this->sforce;
}

Expand Down
39 changes: 39 additions & 0 deletions soapclient/SforcePartnerClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,40 @@
* This file contains two classes.
* @package SalesforceSoapClient
*/
/**
* SforceSoapClient class.
*
* @package SalesforceSoapClient
*/
// When parsing partner WSDL, when PHP SOAP sees NewValue and OldValue, since
// the element has a xsi:type attribute with value 'string', it drops the
// string content into the parsed output and loses the tag name. Removing the
// xsi:type forces PHP SOAP to just leave the tags intact
class SforceSoapClient extends SoapClient {
function __doRequest($request, $location, $action, $version) {
$response = parent::__doRequest($request, $location, $action, $version);

// Quick check to only parse the XML here if we think we need to
if (strpos($response, '<sf:OldValue') === false && strpos($response, '<sf:NewValue') === false) {
return $response;
}

$dom = new DOMDocument();
$dom->loadXML($response);

$nodeList = $dom->getElementsByTagName('NewValue');
foreach ($nodeList as $node) {
$node->removeAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'type');
}
$nodeList = $dom->getElementsByTagName('OldValue');
foreach ($nodeList as $node) {
$node->removeAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'type');
}

return $dom->saveXML();
}
}

/**
* SforcePartnerClient class.
*
Expand All @@ -43,6 +77,11 @@ class SforcePartnerClient extends SforceBaseClient {
function SforcePartnerClient() {
$this->namespace = self::PARTNER_NAMESPACE;
}

protected function getSoapClient($wsdl, $options) {
// Workaround an issue in parsing OldValue and NewValue in histories
return new SforceSoapClient($wsdl, $options);
}

/**
* Adds one or more new individual objects to your organization's data.
Expand Down

0 comments on commit 0c3deb6

Please sign in to comment.