From 0c3deb630abf73b33334ed31c3bfbe909d44ffc3 Mon Sep 17 00:00:00 2001 From: Pat Patterson Date: Thu, 12 Apr 2012 14:02:44 -0700 Subject: [PATCH] Prevent PHP from parsing away OldValue, NewValue tags in XxxHistory queries. Fixes #13. --- soapclient/SforceBaseClient.php | 10 +++++--- soapclient/SforcePartnerClient.php | 39 ++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/soapclient/SforceBaseClient.php b/soapclient/SforceBaseClient.php index 96f3552..ded6e78 100644 --- a/soapclient/SforceBaseClient.php +++ b/soapclient/SforceBaseClient.php @@ -29,7 +29,6 @@ require_once ('ProxySettings.php'); require_once ('SforceHeaderOptions.php'); - /** * This file contains one class. * @package SalesforceSoapClient @@ -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; } @@ -90,7 +93,7 @@ public function printDebugInfo() { echo 'False'; } } - + /** * Connect method to www.salesforce.com * @@ -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; } diff --git a/soapclient/SforcePartnerClient.php b/soapclient/SforcePartnerClient.php index 5a818ad..2399626 100644 --- a/soapclient/SforcePartnerClient.php +++ b/soapclient/SforcePartnerClient.php @@ -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, '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. * @@ -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.