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