diff --git a/README.md b/README.md index f1af987..926f9b8 100644 --- a/README.md +++ b/README.md @@ -23,4 +23,3 @@ About the fixes: - I've just removed all unused code from composer point of view. I've ported all classes into src folder, and kept all of them into a separated file (there was some files with multiple classes). - I've formatted code into PSR-1/PSR-2 format - I've changed some methods signatures, changing their type, like from **date** to **string**, in order to give them the proper type according to current usage. I've not added/removed parameters from phpdoc signatures, despite the high amount of errors. -- I've added a backslash for some classes calls such as SoapClient, as needed by PSR context loading. diff --git a/src/Davispeixoto/ForceDotComToolkitForPhp/SObject.php b/src/Davispeixoto/ForceDotComToolkitForPhp/SObject.php index 22ed408..a2c2992 100644 --- a/src/Davispeixoto/ForceDotComToolkitForPhp/SObject.php +++ b/src/Davispeixoto/ForceDotComToolkitForPhp/SObject.php @@ -26,6 +26,9 @@ * POSSIBILITY OF SUCH DAMAGE. */ +use Exception; +use stdClass; + class SObject { public $type; @@ -56,7 +59,7 @@ public function __construct($response = null) if (isset($response->any)) { try { - if ($response->any instanceof \stdClass) { + if ($response->any instanceof stdClass) { if ($this->isSObject($response->any)) { $anArray = array(); $sobject = new SObject($response->any); @@ -69,7 +72,7 @@ public function __construct($response = null) if (is_array($response->any)) { $anArray = array(); foreach ($response->any as $key => $item) { - if ($item instanceof \stdClass) { + if ($item instanceof stdClass) { if ($this->isSObject($item)) { $sobject = new SObject($item); $anArray[$key] = $sobject; @@ -108,7 +111,8 @@ public function __construct($response = null) } } } catch (Exception $e) { - var_dump('exception: ', $e); + error_log('salesforce exception: ', $e->getMessage()); + error_log('salesforce exception: ', $e->getTraceAsString()); } } } @@ -135,7 +139,7 @@ public function convertFields($any) $array = $this->xml2array('' . $str . '', 2); - $xml = new \stdClass(); + $xml = new stdClass(); if (!count($array['Object'])) { return $xml; } @@ -229,7 +233,7 @@ public function xml2array($contents, $get_attributes = 1) if ($type == "open") {//The starting of the tag '' $parent[$level - 1] = &$current; - if (!is_array($current) or (!in_array($tag, array_keys($current)))) { //Insert New tag + if (!is_array($current) || (!in_array($tag, array_keys($current)))) { //Insert New tag $current[$tag] = $result; $current = &$current[$tag]; @@ -249,8 +253,8 @@ public function xml2array($contents, $get_attributes = 1) $current[$tag] = $result; } else { //If taken, put all things inside a list(array) - if ((is_array($current[$tag]) and $get_attributes == 0)//If it is already an array... - or (isset($current[$tag][0]) and is_array($current[$tag][0]) and ($get_attributes == 1 || $get_attributes == 2)) + if ((is_array($current[$tag]) && $get_attributes == 0)//If it is already an array... + || (isset($current[$tag][0]) && is_array($current[$tag][0]) && ($get_attributes == 1 || $get_attributes == 2)) ) { array_push($current[$tag], $result); // ...push the new element into that array. } else { //If it is not an array... diff --git a/src/Davispeixoto/ForceDotComToolkitForPhp/SforceBaseClient.php b/src/Davispeixoto/ForceDotComToolkitForPhp/SforceBaseClient.php index 4358381..41ed7f8 100644 --- a/src/Davispeixoto/ForceDotComToolkitForPhp/SforceBaseClient.php +++ b/src/Davispeixoto/ForceDotComToolkitForPhp/SforceBaseClient.php @@ -30,6 +30,11 @@ * This file contains one class. * @package SalesforceSoapClient */ +use SoapClient; +use SoapHeader; +use SoapVar; +use stdClass; + /** * SalesforceSoapClient * @package SalesforceSoapClient @@ -60,7 +65,7 @@ class SforceBaseClient protected function getSoapClient($wsdl, $options) { - return new \SoapClient($wsdl, $options); + return new SoapClient($wsdl, $options); } public function getNamespace() @@ -107,7 +112,12 @@ public function printDebugInfo() */ public function createConnection($wsdl, $proxy = null, $soap_options = array()) { + // We don't need to parse out any subversion suffix - e.g. "-01" since + // PHP type conversion will ignore it $phpversion = substr(phpversion(), 0, strpos(phpversion(), '-')); + if ($phpversion < 5.3) { + throw new Exception ('PHP versions older than 5.3 are no longer supported. Please upgrade!'); + } $soapClientArray = array_merge(array( 'user_agent' => 'salesforce-toolkit-php/' . $this->version, @@ -117,11 +127,6 @@ public function createConnection($wsdl, $proxy = null, $soap_options = array()) 'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP ), $soap_options); - // We don't need to parse out any subversion suffix - e.g. "-01" since - // PHP type conversion will ignore it - if (phpversion() < 5.3) { - die("PHP versions older than 5.3 are no longer supported. Please upgrade!"); - } if ($proxy != null) { $proxySettings = array(); @@ -140,7 +145,7 @@ public function createConnection($wsdl, $proxy = null, $soap_options = array()) public function setCallOptions($header) { if ($header != null) { - $this->callOptions = new \SoapHeader($this->namespace, 'CallOptions', array( + $this->callOptions = new SoapHeader($this->namespace, 'CallOptions', array( 'client' => $header->client, 'defaultNamespace' => $header->defaultNamespace )); @@ -184,7 +189,7 @@ public function login($username, $password) public function logout() { $this->setHeaders("logout"); - $arg = new \stdClass(); + $arg = new stdClass(); return $this->sforce->logout(); } @@ -197,7 +202,7 @@ public function logout() public function invalidateSessions() { $this->setHeaders("invalidateSessions"); - $arg = new \stdClass(); + $arg = new stdClass(); $this->logout(); return $this->sforce->invalidateSessions(); @@ -357,7 +362,7 @@ private function setHeaders($call = null) public function setAssignmentRuleHeader($header) { if ($header != null) { - $this->assignmentRuleHeader = new \SoapHeader($this->namespace, 'AssignmentRuleHeader', array( + $this->assignmentRuleHeader = new SoapHeader($this->namespace, 'AssignmentRuleHeader', array( 'assignmentRuleId' => $header->assignmentRuleId, 'useDefaultRule' => $header->useDefaultRuleFlag )); @@ -369,7 +374,7 @@ public function setAssignmentRuleHeader($header) public function setEmailHeader($header) { if ($header != null) { - $this->emailHeader = new \SoapHeader($this->namespace, 'EmailHeader', array( + $this->emailHeader = new SoapHeader($this->namespace, 'EmailHeader', array( 'triggerAutoResponseEmail' => $header->triggerAutoResponseEmail, 'triggerOtherEmail' => $header->triggerOtherEmail, 'triggerUserEmail' => $header->triggerUserEmail @@ -382,7 +387,7 @@ public function setEmailHeader($header) public function setLoginScopeHeader($header) { if ($header != null) { - $this->loginScopeHeader = new \SoapHeader($this->namespace, 'LoginScopeHeader', array( + $this->loginScopeHeader = new SoapHeader($this->namespace, 'LoginScopeHeader', array( 'organizationId' => $header->organizationId, 'portalId' => $header->portalId )); @@ -394,7 +399,7 @@ public function setLoginScopeHeader($header) public function setMruHeader($header) { if ($header != null) { - $this->mruHeader = new \SoapHeader($this->namespace, 'MruHeader', array( + $this->mruHeader = new SoapHeader($this->namespace, 'MruHeader', array( 'updateMru' => $header->updateMruFlag )); } else { @@ -405,7 +410,7 @@ public function setMruHeader($header) public function setSessionHeader($id) { if ($id != null) { - $this->sessionHeader = new \SoapHeader($this->namespace, 'SessionHeader', array( + $this->sessionHeader = new SoapHeader($this->namespace, 'SessionHeader', array( 'sessionId' => $id )); $this->sessionId = $id; @@ -418,7 +423,7 @@ public function setSessionHeader($id) public function setUserTerritoryDeleteHeader($header) { if ($header != null) { - $this->userTerritoryDeleteHeader = new \SoapHeader($this->namespace, 'UserTerritoryDeleteHeader ', array( + $this->userTerritoryDeleteHeader = new SoapHeader($this->namespace, 'UserTerritoryDeleteHeader ', array( 'transferToUserId' => $header->transferToUserId )); } else { @@ -429,7 +434,7 @@ public function setUserTerritoryDeleteHeader($header) public function setQueryOptions($header) { if ($header != null) { - $this->queryHeader = new \SoapHeader($this->namespace, 'QueryOptions', array( + $this->queryHeader = new SoapHeader($this->namespace, 'QueryOptions', array( 'batchSize' => $header->batchSize )); } else { @@ -440,7 +445,7 @@ public function setQueryOptions($header) public function setAllowFieldTruncationHeader($header) { if ($header != null) { - $this->allowFieldTruncationHeader = new \SoapHeader($this->namespace, 'AllowFieldTruncationHeader', array( + $this->allowFieldTruncationHeader = new SoapHeader($this->namespace, 'AllowFieldTruncationHeader', array( 'allowFieldTruncation' => $header->allowFieldTruncation ) ); @@ -452,7 +457,7 @@ public function setAllowFieldTruncationHeader($header) public function setLocaleOptions($header) { if ($header != null) { - $this->localeOptions = new \SoapHeader($this->namespace, 'LocaleOptions', + $this->localeOptions = new SoapHeader($this->namespace, 'LocaleOptions', array( 'language' => $header->language ) @@ -478,7 +483,7 @@ public function setPackageVersionHeader($header) ); } - $this->packageVersionHeader = new \SoapHeader($this->namespace, + $this->packageVersionHeader = new SoapHeader($this->namespace, 'PackageVersionHeader', $headerData ); @@ -582,16 +587,17 @@ public function sendSingleEmail($request) if (is_array($request)) { $messages = array(); foreach ($request as $r) { - $email = new \SoapVar($r, SOAP_ENC_OBJECT, 'SingleEmailMessage', $this->namespace); + $email = new SoapVar($r, SOAP_ENC_OBJECT, 'SingleEmailMessage', $this->namespace); array_push($messages, $email); } - $arg = new \stdClass(); + $arg = new stdClass(); $arg->messages = $messages; return $this->_sendEmail($arg); } else { $backtrace = debug_backtrace(); - die('Please pass in array to this function: ' . $backtrace[0]['function']); + error_log('Please pass in array to this function: ' . $backtrace[0]['function']); + return false; } } @@ -600,16 +606,17 @@ public function sendMassEmail($request) if (is_array($request)) { $messages = array(); foreach ($request as $r) { - $email = new \SoapVar($r, SOAP_ENC_OBJECT, 'MassEmailMessage', $this->namespace); + $email = new SoapVar($r, SOAP_ENC_OBJECT, 'MassEmailMessage', $this->namespace); array_push($messages, $email); } - $arg = new \stdClass(); + $arg = new stdClass(); $arg->messages = $messages; return $this->_sendEmail($arg); } else { $backtrace = debug_backtrace(); - die('Please pass in array to this function: ' . $backtrace[0]['function']); + error_log('Please pass in array to this function: ' . $backtrace[0]['function']); + return false; } } @@ -630,7 +637,7 @@ protected function _sendEmail($arg) public function convertLead($leadConverts) { $this->setHeaders("convertLead"); - $arg = new \stdClass(); + $arg = new stdClass(); $arg->leadConverts = $leadConverts; return $this->sforce->convertLead($arg); @@ -645,7 +652,7 @@ public function convertLead($leadConverts) public function delete($ids) { $this->setHeaders("delete"); - $arg = new \stdClass(); + $arg = new stdClass(); $arg->ids = $ids; return $this->sforce->delete($arg)->result; @@ -660,7 +667,7 @@ public function delete($ids) public function undelete($ids) { $this->setHeaders("undelete"); - $arg = new \stdClass(); + $arg = new stdClass(); $arg->ids = $ids; return $this->sforce->undelete($arg)->result; @@ -675,7 +682,7 @@ public function undelete($ids) public function emptyRecycleBin($ids) { $this->setHeaders(); - $arg = new \stdClass(); + $arg = new stdClass(); $arg->ids = $ids; return $this->sforce->emptyRecycleBin($arg)->result; @@ -691,15 +698,16 @@ public function processSubmitRequest($processRequestArray) { if (is_array($processRequestArray)) { foreach ($processRequestArray as &$process) { - $process = new \SoapVar($process, SOAP_ENC_OBJECT, 'ProcessSubmitRequest', $this->namespace); + $process = new SoapVar($process, SOAP_ENC_OBJECT, 'ProcessSubmitRequest', $this->namespace); } - $arg = new \stdClass(); + $arg = new stdClass(); $arg->actions = $processRequestArray; return $this->_process($arg); } else { $backtrace = debug_backtrace(); - die('Please pass in array to this function: ' . $backtrace[0]['function']); + error_log('Please pass in array to this function: ' . $backtrace[0]['function']); + return false; } } @@ -713,15 +721,16 @@ public function processWorkitemRequest($processRequestArray) { if (is_array($processRequestArray)) { foreach ($processRequestArray as &$process) { - $process = new \SoapVar($process, SOAP_ENC_OBJECT, 'ProcessWorkitemRequest', $this->namespace); + $process = new SoapVar($process, SOAP_ENC_OBJECT, 'ProcessWorkitemRequest', $this->namespace); } - $arg = new \stdClass(); + $arg = new stdClass(); $arg->actions = $processRequestArray; return $this->_process($arg); } else { $backtrace = debug_backtrace(); - die('Please pass in array to this function: ' . $backtrace[0]['function']); + error_log('Please pass in array to this function: ' . $backtrace[0]['function']); + return false; } } @@ -750,8 +759,8 @@ public function describeGlobal() public function describeLayout($type, array $recordTypeIds = null) { $this->setHeaders("describeLayout"); - $arg = new \stdClass(); - $arg->sObjectType = new \SoapVar($type, XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema'); + $arg = new stdClass(); + $arg->sObjectType = new SoapVar($type, XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema'); if (isset($recordTypeIds) && count($recordTypeIds)) { $arg->recordTypeIds = $recordTypeIds; } @@ -769,8 +778,8 @@ public function describeLayout($type, array $recordTypeIds = null) public function describeSObject($type) { $this->setHeaders("describeSObject"); - $arg = new \stdClass(); - $arg->sObjectType = new \SoapVar($type, XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema'); + $arg = new stdClass(); + $arg->sObjectType = new SoapVar($type, XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema'); return $this->sforce->describeSObject($arg)->result; } @@ -813,8 +822,8 @@ public function describeTabs() public function describeDataCategoryGroups($sObjectType) { $this->setHeaders('describeDataCategoryGroups'); - $arg = new \stdClass(); - $arg->sObjectType = new \SoapVar($sObjectType, XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema'); + $arg = new stdClass(); + $arg->sObjectType = new SoapVar($sObjectType, XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema'); return $this->sforce->describeDataCategoryGroups($arg)->result; } @@ -829,9 +838,9 @@ public function describeDataCategoryGroups($sObjectType) public function describeDataCategoryGroupStructures(array $pairs, $topCategoriesOnly) { $this->setHeaders('describeDataCategoryGroupStructures'); - $arg = new \stdClass(); + $arg = new stdClass(); $arg->pairs = $pairs; - $arg->topCategoriesOnly = new \SoapVar($topCategoriesOnly, XSD_BOOLEAN, 'boolean', + $arg->topCategoriesOnly = new SoapVar($topCategoriesOnly, XSD_BOOLEAN, 'boolean', 'http://www.w3.org/2001/XMLSchema'); return $this->sforce->describeDataCategoryGroupStructures($arg)->result; @@ -849,8 +858,8 @@ public function describeDataCategoryGroupStructures(array $pairs, $topCategories public function getDeleted($type, $startDate, $endDate) { $this->setHeaders("getDeleted"); - $arg = new \stdClass(); - $arg->sObjectType = new \SoapVar($type, XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema'); + $arg = new stdClass(); + $arg->sObjectType = new SoapVar($type, XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema'); $arg->startDate = $startDate; $arg->endDate = $endDate; @@ -869,8 +878,8 @@ public function getDeleted($type, $startDate, $endDate) public function getUpdated($type, $startDate, $endDate) { $this->setHeaders("getUpdated"); - $arg = new \stdClass(); - $arg->sObjectType = new \SoapVar($type, XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema'); + $arg = new stdClass(); + $arg->sObjectType = new SoapVar($type, XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema'); $arg->startDate = $startDate; $arg->endDate = $endDate; @@ -906,7 +915,7 @@ public function query($query) public function queryMore($queryLocator) { $this->setHeaders("queryMore"); - $arg = new \stdClass(); + $arg = new stdClass(); $arg->queryLocator = $queryLocator; $raw = $this->sforce->queryMore($arg)->result; $QueryResult = new QueryResult($raw); @@ -944,9 +953,9 @@ public function queryAll($query, $queryOptions = null) public function retrieve($fieldList, $sObjectType, $ids) { $this->setHeaders("retrieve"); - $arg = new \stdClass(); + $arg = new stdClass(); $arg->fieldList = $fieldList; - $arg->sObjectType = new \SoapVar($sObjectType, XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema'); + $arg->sObjectType = new SoapVar($sObjectType, XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema'); $arg->ids = $ids; return $this->sforce->retrieve($arg)->result; @@ -961,8 +970,8 @@ public function retrieve($fieldList, $sObjectType, $ids) public function search($searchString) { $this->setHeaders("search"); - $arg = new \stdClass(); - $arg->searchString = new \SoapVar($searchString, XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema'); + $arg = new stdClass(); + $arg->searchString = new SoapVar($searchString, XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema'); return new SforceSearchResult($this->sforce->search($arg)->result); } @@ -995,8 +1004,8 @@ public function getUserInfo() public function setPassword($userId, $password) { $this->setHeaders("setPassword"); - $arg = new \stdClass(); - $arg->userId = new \SoapVar($userId, XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema'); + $arg = new stdClass(); + $arg->userId = new SoapVar($userId, XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema'); $arg->password = $password; return $this->sforce->setPassword($arg); @@ -1011,8 +1020,8 @@ public function setPassword($userId, $password) public function resetPassword($userId) { $this->setHeaders("resetPassword"); - $arg = new \stdClass(); - $arg->userId = new \SoapVar($userId, XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema'); + $arg = new stdClass(); + $arg->userId = new SoapVar($userId, XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema'); return $this->sforce->resetPassword($arg)->result; } diff --git a/src/Davispeixoto/ForceDotComToolkitForPhp/SforceEnterpriseClient.php b/src/Davispeixoto/ForceDotComToolkitForPhp/SforceEnterpriseClient.php index 3f4abee..2ceb318 100644 --- a/src/Davispeixoto/ForceDotComToolkitForPhp/SforceEnterpriseClient.php +++ b/src/Davispeixoto/ForceDotComToolkitForPhp/SforceEnterpriseClient.php @@ -30,6 +30,10 @@ * This file contains two classes. * @package SalesforceSoapClient */ +use SoapParam; +use SoapVar; +use stdClass; + /** * SforceEnterpriseClient class. * @@ -62,17 +66,17 @@ public function create($sObjects, $type) } } - $sObject = new \SoapVar($sObject, SOAP_ENC_OBJECT, $type, $this->namespace); + $sObject = 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); + $sObject->enc_value->fieldsToNull = new SoapVar(new SoapVar($xmlStr, XSD_ANYXML), SOAP_ENC_ARRAY); } } $arg = $sObjects; - return parent::_create(new \SoapParam($arg, "sObjects")); + return parent::_create(new SoapParam($arg, "sObjects")); } /** @@ -93,15 +97,15 @@ public function update($sObjects, $type, $assignment_header = null, $mru_header } } - $sObject = new \SoapVar($sObject, SOAP_ENC_OBJECT, $type, $this->namespace); + $sObject = 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); + $sObject->enc_value->fieldsToNull = new SoapVar(new SoapVar($xmlStr, XSD_ANYXML), SOAP_ENC_ARRAY); } } - $arg = new \stdClass; + $arg = new stdClass; $arg->sObjects = $sObjects; return parent::_update($arg); @@ -120,8 +124,8 @@ public function update($sObjects, $type, $assignment_header = null, $mru_header */ public function upsert($ext_Id, $sObjects, $type = 'Contact') { - $arg = new \stdClass; - $arg->externalIDFieldName = new \SoapVar($ext_Id, XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema'); + $arg = new stdClass; + $arg->externalIDFieldName = new SoapVar($ext_Id, XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema'); foreach ($sObjects as &$sObject) { // FIX for fieldsToNull issue - allow array in fieldsToNull (STEP #1) @@ -132,11 +136,11 @@ public function upsert($ext_Id, $sObjects, $type = 'Contact') } } - $sObject = new \SoapVar($sObject, SOAP_ENC_OBJECT, $type, $this->namespace); + $sObject = 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); + $sObject->enc_value->fieldsToNull = new SoapVar(new SoapVar($xmlStr, XSD_ANYXML), SOAP_ENC_ARRAY); } } @@ -154,10 +158,10 @@ public function upsert($ext_Id, $sObjects, $type = 'Contact') */ public function merge($mergeRequest, $type) { - $mergeRequest->masterRecord = new \SoapVar($mergeRequest->masterRecord, SOAP_ENC_OBJECT, $type, + $mergeRequest->masterRecord = new SoapVar($mergeRequest->masterRecord, SOAP_ENC_OBJECT, $type, $this->namespace); - $arg = new \stdClass; - $arg->request = new \SoapVar($mergeRequest, SOAP_ENC_OBJECT, 'MergeRequest', $this->namespace); + $arg = new stdClass; + $arg->request = new SoapVar($mergeRequest, SOAP_ENC_OBJECT, 'MergeRequest', $this->namespace); return parent::_merge($arg); } diff --git a/src/Davispeixoto/ForceDotComToolkitForPhp/SforceMetadataClient.php b/src/Davispeixoto/ForceDotComToolkitForPhp/SforceMetadataClient.php index 66634d9..ae3c1c5 100644 --- a/src/Davispeixoto/ForceDotComToolkitForPhp/SforceMetadataClient.php +++ b/src/Davispeixoto/ForceDotComToolkitForPhp/SforceMetadataClient.php @@ -25,6 +25,11 @@ * POSSIBILITY OF SUCH DAMAGE. */ +use SoapClient; +use SoapHeader; +use SoapVar; +use stdClass; + class SforceMetadataClient { public $sforce; @@ -56,15 +61,15 @@ public function __construct($wsdl, $loginResult, $sforceConn) ); } - $this->sforce = new \SoapClient($wsdl, $soapClientArray); + $this->sforce = new SoapClient($wsdl, $soapClientArray); $sessionVar = array( - 'sessionId' => new \SoapVar($loginResult->sessionId, XSD_STRING) + 'sessionId' => new SoapVar($loginResult->sessionId, XSD_STRING) ); - $headerBody = new \SoapVar($sessionVar, SOAP_ENC_OBJECT); + $headerBody = new SoapVar($sessionVar, SOAP_ENC_OBJECT); - $session_header = new \SoapHeader($this->namespace, 'SessionHeader', $headerBody, false); + $session_header = new SoapHeader($this->namespace, 'SessionHeader', $headerBody, false); $header_array = array( $session_header @@ -107,7 +112,7 @@ public function setEndpoint($location) public function setSessionHeader($sessionId) { $this->sforce->__setSoapHeaders(null); - $session_header = new \SoapHeader($this->namespace, 'SessionHeader', array( + $session_header = new SoapHeader($this->namespace, 'SessionHeader', array( 'sessionId' => $sessionId )); $this->sessionId = $sessionId; @@ -131,17 +136,17 @@ private function getObjtype($obj) public function create($obj) { - $encodedObj = new \stdClass(); - $encodedObj->metadata = new \SoapVar($obj, SOAP_ENC_OBJECT, $this->getObjtype($obj), $this->namespace); + $encodedObj = new stdClass(); + $encodedObj->metadata = new SoapVar($obj, SOAP_ENC_OBJECT, $this->getObjtype($obj), $this->namespace); return $this->sforce->create($encodedObj); } public function update($obj) { - $encodedObj = new \stdClass(); + $encodedObj = new stdClass(); $encodedObj->UpdateMetadata = $obj; - $encodedObj->UpdateMetadata->metadata = new \SoapVar($obj->metadata, SOAP_ENC_OBJECT, + $encodedObj->UpdateMetadata->metadata = new SoapVar($obj->metadata, SOAP_ENC_OBJECT, $this->getObjtype($obj->metadata), $this->namespace); return $this->sforce->update($encodedObj); @@ -149,8 +154,8 @@ public function update($obj) public function delete($obj) { - $encodedObj = new \stdClass(); - $encodedObj->metadata = new \SoapVar($obj, SOAP_ENC_OBJECT, $this->getObjtype($obj), $this->namespace); + $encodedObj = new stdClass(); + $encodedObj->metadata = new SoapVar($obj, SOAP_ENC_OBJECT, $this->getObjtype($obj), $this->namespace); return $this->sforce->delete($encodedObj); } diff --git a/src/Davispeixoto/ForceDotComToolkitForPhp/SforcePartnerClient.php b/src/Davispeixoto/ForceDotComToolkitForPhp/SforcePartnerClient.php index f2b5b7b..0ea7d2c 100644 --- a/src/Davispeixoto/ForceDotComToolkitForPhp/SforcePartnerClient.php +++ b/src/Davispeixoto/ForceDotComToolkitForPhp/SforcePartnerClient.php @@ -25,6 +25,7 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ +use stdClass; /** * SforcePartnerClient class. @@ -52,7 +53,7 @@ protected function getSoapClient($wsdl, $options) */ public function create($sObjects) { - $arg = new \stdClass; + $arg = new stdClass; foreach ($sObjects as $sObject) { if (isset ($sObject->fields)) { $sObject->any = $this->_convertToAny($sObject->fields); @@ -76,7 +77,7 @@ public function merge($mergeRequest) if (isset($mergeRequest->masterRecord->fields)) { $mergeRequest->masterRecord->any = $this->_convertToAny($mergeRequest->masterRecord->fields); } - //return parent::merge($mergeRequest, $type); + $arg = new stdClass(); $arg->request = $mergeRequest; return $this->_merge($arg); @@ -100,7 +101,8 @@ public function sendSingleEmail($request) return parent::_sendEmail($arg); } else { $backtrace = debug_backtrace(); - die('Please pass in array to this function: ' . $backtrace[0]['function']); + error_log('Please pass in array to this function: ' . $backtrace[0]['function']); + return false; } } @@ -110,6 +112,7 @@ public function sendSingleEmail($request) */ public function sendMassEmail($request) { + $arg = new stdClass(); if (is_array($request)) { $messages = array(); foreach ($request as $r) { @@ -121,7 +124,8 @@ public function sendMassEmail($request) return parent::_sendEmail($arg); } else { $backtrace = debug_backtrace(); - die('Please pass in array to this function: ' . $backtrace[0]['function']); + error_log('Please pass in array to this function: ' . $backtrace[0]['function']); + return false; } } @@ -132,7 +136,7 @@ public function sendMassEmail($request) */ public function update($sObjects) { - $arg = new \stdClass; + $arg = new stdClass; foreach ($sObjects as $sObject) { if (isset($sObject->fields)) { $sObject->any = $this->_convertToAny($sObject->fields); @@ -155,7 +159,7 @@ public function update($sObjects) */ public function upsert($ext_Id, $sObjects) { - $arg = new \stdClass; + $arg = new stdClass; $arg->externalIDFieldName = new \SoapVar($ext_Id, XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema'); foreach ($sObjects as $sObject) { if (isset ($sObject->fields)) {