Skip to content

Commit

Permalink
Updated push to integration campaign action to use configuration from…
Browse files Browse the repository at this point in the history
… action
  • Loading branch information
shinde-rahul committed Jul 13, 2023
1 parent 5c4a0ff commit 4f9d640
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 22 deletions.
20 changes: 9 additions & 11 deletions app/bundles/PluginBundle/EventListener/PushToIntegrationTrait.php
Expand Up @@ -44,22 +44,20 @@ protected function pushToIntegration(array $config, Lead $lead, array &$errors =
}

/**
* Used because the the Point trigger actions have not be converted to Events yet and thus must leverage a callback.
* Used because the Point trigger actions have not been converted to Events yet and thus must leverage a callback.
*
* @param $config
* @param $lead
* @param $errors
* @param array<string, array<string, int|string>|null> $config
* @param Lead $lead
* @param mixed[] $errors
*
* @return bool
*/
protected static function pushIt($config, $lead, &$errors)
{
$integration = (!empty($config['integration'])) ? $config['integration'] : null;
$integrationCampaign = (!empty($config['config']['campaigns'])) ? $config['config']['campaigns'] : null;
$integrationMemberStatus = (!empty($config['campaign_member_status']['campaign_member_status']))
? $config['campaign_member_status']['campaign_member_status'] : null;
$services = static::$integrationHelper->getIntegrationObjects($integration);
$success = true;
$integration = (!empty($config['integration'])) ? $config['integration'] : null;
$integrationCampaign = (!empty($config['config']['campaigns'])) ? $config['config']['campaigns'] : null;
$services = static::$integrationHelper->getIntegrationObjects($integration);
$success = true;

Check warning on line 60 in app/bundles/PluginBundle/EventListener/PushToIntegrationTrait.php

View check run for this annotation

Codecov / codecov/patch

app/bundles/PluginBundle/EventListener/PushToIntegrationTrait.php#L57-L60

Added lines #L57 - L60 were not covered by tests

/**
* @var string
Expand All @@ -82,7 +80,7 @@ protected static function pushIt($config, $lead, &$errors)
}

if ($success && $integrationCampaign && method_exists($s, 'pushLeadToCampaign')) {
if (!$s->resetLastIntegrationError()->pushLeadToCampaign($lead, $integrationCampaign, $integrationMemberStatus, $personIds)) {
if (!$s->resetLastIntegrationError()->pushLeadToCampaign($lead, $integrationCampaign, $personIds, $config)) {

Check warning on line 83 in app/bundles/PluginBundle/EventListener/PushToIntegrationTrait.php

View check run for this annotation

Codecov / codecov/patch

app/bundles/PluginBundle/EventListener/PushToIntegrationTrait.php#L83

Added line #L83 was not covered by tests
$success = false;
if ($error = $s->getLastIntegrationError()) {
$errors[] = $error;
Expand Down
Expand Up @@ -49,7 +49,7 @@

/**
* @method pushLead(Lead $lead, array $config = [])
* @method pushLeadToCampaign(Lead $lead, mixed $integrationCampaign, mixed $integrationMemberStatus)
* @method pushLeadToCampaign(Lead $lead, mixed $integrationCampaignId, mixed $personIds = null, array $config = [])
* @method getLeads(array $params, string $query, &$executed, array $result = [], $object = 'Lead')
* @method getCompanies(array $params)
*
Expand Down
18 changes: 9 additions & 9 deletions plugins/MauticCrmBundle/Integration/SalesforceIntegration.php
Expand Up @@ -1504,12 +1504,13 @@ public function getCampaignMemberStatus($campaignId)
}

/**
* @param $campaignId
* @param $status
* @param string|int $integrationCampaignId
* @param array<string, array<int|string, int|string>|null>|null $personIds
* @param array<string, array<string, int|string>|null> $config
*
* @return array
*/
public function pushLeadToCampaign(Lead $lead, $campaignId, $status = '', $personIds = null)
public function pushLeadToCampaign(Lead $lead, $integrationCampaignId, $personIds = null, array $config = [])
{
if (empty($personIds)) {
// personIds should have been generated by pushLead()
Expand All @@ -1518,13 +1519,12 @@ public function pushLeadToCampaign(Lead $lead, $campaignId, $status = '', $perso
}

$mauticData = [];
$objectId = null;

/** @var IntegrationEntityRepository $integrationEntityRepo */
$integrationEntityRepo = $this->em->getRepository('MauticPluginBundle:IntegrationEntity');

$body = [
'Status' => $status,
'Status' => (!empty($config['campaign_member_status']['campaign_member_status'])) ? $config['campaign_member_status']['campaign_member_status'] : null,
];
$object = 'CampaignMember';
$url = '/services/data/v38.0/sobjects/'.$object;
Expand All @@ -1536,19 +1536,19 @@ public function pushLeadToCampaign(Lead $lead, $campaignId, $status = '', $perso
// Give precendence to Contact CampaignMembers
if (!empty($personIds['Contact'])) {
$pushObject = 'Contact';
$campaignMembers = $this->getApiHelper()->checkCampaignMembership($campaignId, $pushObject, $personIds[$pushObject]);
$campaignMembers = $this->getApiHelper()->checkCampaignMembership($integrationCampaignId, $pushObject, $personIds[$pushObject]);

Check warning on line 1539 in plugins/MauticCrmBundle/Integration/SalesforceIntegration.php

View check run for this annotation

Codecov / codecov/patch

plugins/MauticCrmBundle/Integration/SalesforceIntegration.php#L1539

Added line #L1539 was not covered by tests
$pushPeople = $personIds[$pushObject];
}

if (empty($campaignMembers) && !empty($personIds['Lead'])) {
$pushObject = 'Lead';
$campaignMembers = $this->getApiHelper()->checkCampaignMembership($campaignId, $pushObject, $personIds[$pushObject]);
$campaignMembers = $this->getApiHelper()->checkCampaignMembership($integrationCampaignId, $pushObject, $personIds[$pushObject]);
$pushPeople = $personIds[$pushObject];
}
} // pushLead should have handled this

foreach ($pushPeople as $memberId) {
$campaignMappingId = '-'.$campaignId;
$campaignMappingId = '-'.$integrationCampaignId;

if (isset($campaignMembers[$memberId])) {
$existingCampaignMember = $integrationEntityRepo->getIntegrationsEntityId(
Expand Down Expand Up @@ -1593,7 +1593,7 @@ public function pushLeadToCampaign(Lead $lead, $campaignId, $status = '', $perso
'body' => array_merge(
$body,
[
'CampaignId' => $campaignId,
'CampaignId' => $integrationCampaignId,
"{$pushObject}Id" => $memberId,
]
),
Expand Down
Expand Up @@ -455,7 +455,7 @@ function () {
}
);

$sf->pushLeadToCampaign($lead, 1, 'Active', ['Lead' => [1]]);
$sf->pushLeadToCampaign($lead, 1, ['Lead' => [1]]);
}

public function testPushCompany()
Expand Down

0 comments on commit 4f9d640

Please sign in to comment.