Skip to content

Commit

Permalink
Merge pull request mautic#4053 from mqueme/add-debugs-to-sf
Browse files Browse the repository at this point in the history
added debugs when patching and posting on SF
  • Loading branch information
alanhartless authored May 11, 2017
2 parents 1c555df + 626d7b6 commit 338d834
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
35 changes: 20 additions & 15 deletions app/bundles/PluginBundle/Integration/AbstractIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ public function persistIntegrationSettings()
*
* @param $mergeKeys
* @param $withKeys
* @param bool|false $return Returns the key array rather than setting them
* @param bool|false $return Returns the key array rather than setting them
*
* @return void|array
*/
Expand Down Expand Up @@ -746,10 +746,10 @@ public function makeRequest($url, $parameters = [], $method = 'GET', $settings =
if ($method == 'GET' && !empty($parameters)) {
$parameters = array_merge($settings['query'], $parameters);
$query = http_build_query($parameters);
$url .= (strpos($url, '?') === false) ? '?'.$query : '&'.$query;
$url .= (strpos($url, '?') === false) ? '?'.$query : '&'.$query;
} elseif (!empty($settings['query'])) {
$query = http_build_query($settings['query']);
$url .= (strpos($url, '?') === false) ? '?'.$query : '&'.$query;
$url .= (strpos($url, '?') === false) ? '?'.$query : '&'.$query;
}

if (isset($postAppend)) {
Expand Down Expand Up @@ -809,8 +809,8 @@ public function makeRequest($url, $parameters = [], $method = 'GET', $settings =
foreach ($parseHeaders as $key => $value) {
if (strpos($value, ':') !== false) {
list($key, $value) = explode(':', $value);
$key = trim($key);
$value = trim($value);
$key = trim($key);
$value = trim($value);
}

$headers[$key] = $value;
Expand Down Expand Up @@ -919,21 +919,21 @@ public function prepareRequest($url, $parameters, $method, $settings, $authType)
break;
case 'oauth2':
if ($bearerToken = $this->getBearerToken(true)) {
$headers = [
$headers = [
"Authorization: Basic {$bearerToken}",
'Content-Type: application/x-www-form-urlencoded;charset=UTF-8',
];
$parameters['grant_type'] = 'client_credentials';
} else {
$defaultGrantType = (!empty($settings['refresh_token'])) ? 'refresh_token'
: 'authorization_code';
$grantType = (!isset($settings['grant_type'])) ? $defaultGrantType
$grantType = (!isset($settings['grant_type'])) ? $defaultGrantType
: $settings['grant_type'];

$useClientIdKey = (empty($settings[$clientIdKey])) ? $clientIdKey : $settings[$clientIdKey];
$useClientSecretKey = (empty($settings[$clientSecretKey])) ? $clientSecretKey
: $settings[$clientSecretKey];
$parameters = array_merge(
$parameters = array_merge(
$parameters,
[
$useClientIdKey => $this->keys[$clientIdKey],
Expand Down Expand Up @@ -1448,7 +1448,7 @@ public function cleanUpFields(Integration $entity, array $mauticLeadFields, arra
$mauticLeadFields['mauticContactTimelineLink'] = '';

//make sure now non-existent aren't saved
$settings = [
$settings = [
'ignore_field_cache' => false,
];
$settings['feature_settings']['objects'] = $submittedObjects;
Expand Down Expand Up @@ -1705,9 +1705,9 @@ public function populateMauticLeadData($data, $config = [], $object = null)
/**
* Create or update existing Mautic lead from the integration's profile data.
*
* @param mixed $data Profile data from integration
* @param bool|true $persist Set to false to not persist lead to the database in this method
* @param array|null $socialCache
* @param mixed $data Profile data from integration
* @param bool|true $persist Set to false to not persist lead to the database in this method
* @param array|null $socialCache
* @param mixed||null $identifiers
*
* @return Lead
Expand Down Expand Up @@ -1908,7 +1908,7 @@ protected function matchUpData($data)
}
}
}
$fn = (isset($fieldDetails['fields'][0])) ? $this->matchFieldName(
$fn = (isset($fieldDetails['fields'][0])) ? $this->matchFieldName(
$field,
$fieldDetails['fields'][0]
) : $field;
Expand Down Expand Up @@ -2004,7 +2004,7 @@ public function logIntegrationError(\Exception $e, Lead $contact = null)
$this->lastIntegrationError = $errorHeader.': '.$errorMessage;

if ($contactId) {
$contactLink = $this->router->generate(
$contactLink = $this->router->generate(
'mautic_contact_action',
[
'objectAction' => 'view',
Expand Down Expand Up @@ -2234,8 +2234,13 @@ protected function cleanIdentifier($identifier)
/**
* @param $value
*/
protected function cleanPushData($value)
public function cleanPushData($value)
{
return strip_tags(html_entity_decode($value, ENT_QUOTES));
}

public function getLogger()
{
return $this->logger;
}
}
6 changes: 4 additions & 2 deletions plugins/MauticCrmBundle/Api/SalesforceApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@ public function createLead(array $data)
//try searching for lead as this has been changed before in updated done to the plugin
if (isset($config['objects']) && array_search('Contact', $config['objects']) && isset($data['Contact']['Email'])) {
$sfObject = 'Contact';
$findContact = 'select Id from Contact where email = \''.$data['Contact']['Email'].'\'';
$findContact = 'select Id from Contact where email = \''.str_replace("'", "\'", $this->integration->cleanPushData($data['Contact']['Email'])).'\'';
$sfRecord = $this->request('query', ['q' => $findContact], 'GET', false, null, $queryUrl);
}

if (empty($sfRecord['records']) && isset($data['Lead']['Email'])) {
$sfObject = 'Lead';
$findLead = 'select Id from Lead where email = \''.$data['Lead']['Email'].'\' and ConvertedContactId = NULL';
$findLead = 'select Id from Lead where email = \''.str_replace("'", "\'", $this->integration->cleanPushData($data['Lead']['Email'])).'\' and ConvertedContactId = NULL';
$sfRecord = $this->request('query', ['q' => $findLead], 'GET', false, null, $queryUrl);
}
$sfLeadRecords = $sfRecord['records'];
Expand All @@ -131,6 +131,7 @@ public function createLead(array $data)
foreach ($sfLeadRecords as $sfLeadRecord) {
$sfLeadId = $sfLeadRecord['Id'];
$this->request('', $data[$sfObject], 'PATCH', false, $sfObject.'/'.$sfLeadId);
$this->integration->getLogger()->debug('SALESFORCE: PATCH through trigger action '.$sfObject.' '.var_export($data[$sfObject], true));
}

$createdLeadData = $data[$sfObject];
Expand All @@ -139,6 +140,7 @@ public function createLead(array $data)

if ($createLead && isset($data['Lead']['Email'])) {
$createdLeadData = $this->request('', $data['Lead'], 'POST', false, 'Lead');
$this->integration->getLogger()->debug('SALESFORCE: POST through trigger action Lead '.var_export($data['Lead'], true));
}

//todo: check if push activities is selected in config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,7 @@ public function pushLeads($params = [])
if ($chunk) {
$request['compositeRequest'] = $chunk;
$result = $apiHelper->syncMauticToSalesforce($request);

$this->logger->debug('SALESFORCE: Sync Composite '.var_export($request, true));
list($updated, $created) = $this->processCompositeResponse($result['compositeResponse'], $salesforceIdMapping);
$totalUpdated += (int) $updated;
$totalCreated += (int) $created;
Expand Down

0 comments on commit 338d834

Please sign in to comment.