1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* Copyright (c) 2007, salesforce.com, inc. |
4
|
|
|
* All rights reserved. |
5
|
|
|
* |
6
|
|
|
* Redistribution and use in source and binary forms, with or without modification, are permitted provided |
7
|
|
|
* that the following conditions are met: |
8
|
|
|
* |
9
|
|
|
* Redistributions of source code must retain the above copyright notice, this list of conditions and the |
10
|
|
|
* following disclaimer. |
11
|
|
|
* |
12
|
|
|
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and |
13
|
|
|
* the following disclaimer in the documentation and/or other materials provided with the distribution. |
14
|
|
|
* |
15
|
|
|
* Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or |
16
|
|
|
* promote products derived from this software without specific prior written permission. |
17
|
|
|
* |
18
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED |
19
|
|
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
20
|
|
|
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR |
21
|
|
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED |
22
|
|
|
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
23
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
24
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
25
|
|
|
* POSSIBILITY OF SUCH DAMAGE. |
26
|
|
|
*/ |
27
|
|
|
require_once ('SforceBaseClient.php'); |
|
|
|
|
28
|
|
|
//require_once ('SforceEmail.php'); |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* This file contains two classes. |
33
|
|
|
* @package SalesforceSoapClient |
34
|
|
|
*/ |
35
|
|
|
/** |
36
|
|
|
* SforceSoapClient class. |
37
|
|
|
* |
38
|
|
|
* @package SalesforceSoapClient |
39
|
|
|
*/ |
40
|
|
|
// When parsing partner WSDL, when PHP SOAP sees NewValue and OldValue, since |
41
|
|
|
// the element has a xsi:type attribute with value 'string', it drops the |
42
|
|
|
// string content into the parsed output and loses the tag name. Removing the |
43
|
|
|
// xsi:type forces PHP SOAP to just leave the tags intact |
44
|
|
|
class SforceSoapClient extends SoapClient { |
45
|
|
|
function __doRequest($request, $location, $action, $version, $one_way=0) { |
|
|
|
|
46
|
|
|
$response = parent::__doRequest($request, $location, $action, $version, $one_way); |
47
|
|
|
|
48
|
|
|
// Quick check to only parse the XML here if we think we need to |
49
|
|
|
if (strpos($response, '<sf:OldValue') === false && strpos($response, '<sf:NewValue') === false) { |
|
|
|
|
50
|
|
|
return $response; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
$dom = new DOMDocument(); |
54
|
|
|
$dom->loadXML($response); |
55
|
|
|
|
56
|
|
|
$nodeList = $dom->getElementsByTagName('NewValue'); |
57
|
|
|
foreach ($nodeList as $node) { |
|
|
|
|
58
|
|
|
$node->removeAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'type'); |
59
|
|
|
} |
60
|
|
|
$nodeList = $dom->getElementsByTagName('OldValue'); |
61
|
|
|
foreach ($nodeList as $node) { |
|
|
|
|
62
|
|
|
$node->removeAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'type'); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
return $dom->saveXML(); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* SforcePartnerClient class. |
71
|
|
|
* |
72
|
|
|
* @package SalesforceSoapClient |
73
|
|
|
*/ |
74
|
|
|
class SforcePartnerClient extends SforceBaseClient { |
75
|
|
|
const PARTNER_NAMESPACE = 'urn:partner.soap.sforce.com'; |
76
|
|
|
|
77
|
|
|
public function __construct() { |
78
|
|
|
$this->namespace = self::PARTNER_NAMESPACE; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
protected function getSoapClient($wsdl, $options) { |
|
|
|
|
82
|
|
|
// Workaround an issue in parsing OldValue and NewValue in histories |
83
|
|
|
return new SforceSoapClient($wsdl, $options); |
|
|
|
|
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Adds one or more new individual objects to your organization's data. |
88
|
|
|
* @param array $sObjects Array of one or more sObjects (up to 200) to create. |
89
|
|
|
* @return SaveResult |
90
|
|
|
*/ |
91
|
|
View Code Duplication |
public function create($sObjects) { |
|
|
|
|
92
|
|
|
$arg = new stdClass; |
93
|
|
|
foreach ($sObjects as $sObject) { |
|
|
|
|
94
|
|
|
if (isset ($sObject->fields)) { |
|
|
|
|
95
|
|
|
$sObject->any = $this->_convertToAny($sObject->fields); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
$arg->sObjects = $sObjects; |
99
|
|
|
return parent::_create($arg); |
|
|
|
|
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Merge records |
104
|
|
|
* |
105
|
|
|
* @param stdclass $mergeRequest |
106
|
|
|
* @param String $type |
|
|
|
|
107
|
|
|
* @return mixed |
108
|
|
|
*/ |
109
|
|
|
public function merge($mergeRequest) { |
110
|
|
|
if (isset($mergeRequest->masterRecord)) { |
|
|
|
|
111
|
|
|
if (isset($mergeRequest->masterRecord->fields)) { |
|
|
|
|
112
|
|
|
$mergeRequest->masterRecord->any = $this->_convertToAny($mergeRequest->masterRecord->fields); |
113
|
|
|
} |
114
|
|
|
//return parent::merge($mergeRequest, $type); |
115
|
|
|
$arg->request = $mergeRequest; |
116
|
|
|
return $this->_merge($arg); |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* |
122
|
|
|
* @param array $request |
123
|
|
|
*/ |
124
|
|
View Code Duplication |
public function sendSingleEmail($request) { |
|
|
|
|
125
|
|
|
if (is_array($request)) { |
|
|
|
|
126
|
|
|
$messages = array(); |
127
|
|
|
foreach ($request as $r) { |
|
|
|
|
128
|
|
|
$email = new SoapVar($r, SOAP_ENC_OBJECT, 'SingleEmailMessage', $this->namespace); |
129
|
|
|
array_push($messages, $email); |
130
|
|
|
} |
131
|
|
|
$arg->messages = $messages; |
132
|
|
|
return parent::_sendEmail($arg); |
|
|
|
|
133
|
|
|
} else { |
134
|
|
|
$backtrace = debug_backtrace(); |
135
|
|
|
die('Please pass in array to this function: '.$backtrace[0]['function']); |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* |
141
|
|
|
* @param array $request |
142
|
|
|
*/ |
143
|
|
View Code Duplication |
public function sendMassEmail($request) { |
|
|
|
|
144
|
|
|
if (is_array($request)) { |
|
|
|
|
145
|
|
|
$messages = array(); |
146
|
|
|
foreach ($request as $r) { |
|
|
|
|
147
|
|
|
$email = new SoapVar($r, SOAP_ENC_OBJECT, 'MassEmailMessage', $this->namespace); |
148
|
|
|
array_push($messages, $email); |
149
|
|
|
} |
150
|
|
|
$arg->messages = $messages; |
151
|
|
|
return parent::_sendEmail($arg); |
|
|
|
|
152
|
|
|
} else { |
153
|
|
|
$backtrace = debug_backtrace(); |
154
|
|
|
die('Please pass in array to this function: '.$backtrace[0]['function']); |
155
|
|
|
} |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* Updates one or more new individual objects to your organization's data. |
160
|
|
|
* @param array sObjects Array of sObjects |
161
|
|
|
* @return UpdateResult |
162
|
|
|
*/ |
163
|
|
View Code Duplication |
public function update($sObjects) { |
|
|
|
|
164
|
|
|
$arg = new stdClass; |
165
|
|
|
foreach ($sObjects as $sObject) { |
|
|
|
|
166
|
|
|
if (isset($sObject->fields)) { |
|
|
|
|
167
|
|
|
$sObject->any = $this->_convertToAny($sObject->fields); |
168
|
|
|
} |
169
|
|
|
} |
170
|
|
|
$arg->sObjects = $sObjects; |
171
|
|
|
return parent::_update($arg); |
|
|
|
|
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Creates new objects and updates existing objects; uses a custom field to |
176
|
|
|
* determine the presence of existing objects. In most cases, we recommend |
177
|
|
|
* that you use upsert instead of create because upsert is idempotent. |
178
|
|
|
* Available in the API version 7.0 and later. |
179
|
|
|
* |
180
|
|
|
* @param string $ext_Id External Id |
181
|
|
|
* @param array $sObjects Array of sObjects |
182
|
|
|
* @return UpsertResult |
183
|
|
|
*/ |
184
|
|
|
public function upsert($ext_Id, $sObjects) { |
185
|
|
|
// $this->_setSessionHeader(); |
186
|
|
|
$arg = new stdClass; |
187
|
|
|
$arg->externalIDFieldName = new SoapVar($ext_Id, XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema'); |
188
|
|
|
foreach ($sObjects as $sObject) { |
|
|
|
|
189
|
|
|
if (isset ($sObject->fields)) { |
|
|
|
|
190
|
|
|
$sObject->any = $this->_convertToAny($sObject->fields); |
191
|
|
|
} |
192
|
|
|
} |
193
|
|
|
$arg->sObjects = $sObjects; |
194
|
|
|
return parent::_upsert($arg); |
|
|
|
|
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* @param string $fieldList |
199
|
|
|
* @param string $sObjectType |
200
|
|
|
* @param array $ids |
201
|
|
|
* @return string |
202
|
|
|
*/ |
203
|
|
|
public function retrieve($fieldList, $sObjectType, $ids) { |
204
|
|
|
return $this->_retrieveResult(parent::retrieve($fieldList, $sObjectType, $ids)); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* |
209
|
|
|
* @param mixed $response |
210
|
|
|
* @return array |
211
|
|
|
*/ |
212
|
|
|
private function _retrieveResult($response) { |
|
|
|
|
213
|
|
|
$arr = array(); |
214
|
|
|
if(is_array($response)) { |
|
|
|
|
215
|
|
|
foreach($response as $r) { |
|
|
|
|
216
|
|
|
$sobject = new SObject($r); |
217
|
|
|
array_push($arr,$sobject); |
218
|
|
|
}; |
219
|
|
|
}else { |
220
|
|
|
$sobject = new SObject($response); |
221
|
|
|
array_push($arr, $sobject); |
222
|
|
|
} |
223
|
|
|
return $arr; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
} |
227
|
|
|
|