Skip to content

Commit

Permalink
New sf contacts dnc sync (#13411)
Browse files Browse the repository at this point in the history
* download dnc info from salesforce for new records

* cs fixes

* Update plugins/MauticCrmBundle/Integration/SalesforceIntegration.php

* enable sf optout only for leads

* cs fix

* use contact only for opted-out

* fix handling

* wip: add error handling for optout fields in sf

* work in progress, add upsert method, add notification transformer

* add transformer, add helper methods for user, add method to notify administrators, add messages translation

* add transformer, add helper methods for user, add method to notify administrators, add messages translation, commit #2

* wip

* wip

* Update wording according to rowlands suggestion.

* Prevent a cycle of requests if the error is not related to the HasOptedOutOfEmail field

* Unset HasOptedOutOfEmail for getPerson as it's not used and will cause issues for Salesforce instances without the field enabled on Contact

* Fixed owner fields from overriding all fields

* fix cs

* removed unused files

* fix test case

* Fixed API test warnings

* Exclude deleted SF leads/contacts in order to prevent them from being re-created in Mautic after being deleted.

* Fix warnings after PHP8 upgrade

* Fixed plugin field mapping pages

---------

Co-authored-by: Jan Kozak <galvani78@gmail.com>
Co-authored-by: Don Gilbert <don.gilbert@mautic.com>
Co-authored-by: Alan Hartless <alan@devkardia.com>
Co-authored-by: Tejas Navghane <ts.navghane@gmail.com>
Co-authored-by: mtshaw3 <mike.shaw@acquia.com>
  • Loading branch information
6 people committed Mar 7, 2024
1 parent a434336 commit 6a294bd
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace Mautic\CoreBundle\Entity\Transformer;

use Mautic\CoreBundle\Entity\Notification;
use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Component\PropertyAccess\PropertyAccess;

class NotificationArrayTransformer implements DataTransformerInterface
{
/** {@inheritdoc} */
public function transform($value)
{
/** Notification $value */
if (!$value instanceof Notification) {
throw new \InvalidArgumentException('Transformer expects '.Notification::class);
}

$notification = new Notification();
$reflection = new \ReflectionClass($notification);
$vars = $reflection->getProperties();

$propertyAccessor = PropertyAccess::createPropertyAccessorBuilder()
->enableExceptionOnInvalidIndex()
->getPropertyAccessor();

$array = [];

foreach ($vars as $property) {
$propertyValue = $propertyAccessor->getValue($value, $property->getName());
$array[$property->getName()] = $propertyValue;
}

return $array;
}

/** {@inheritdoc} */
public function reverseTransform($value)
{
if (!is_array($value)) {
throw new \InvalidArgumentException('Method expects array as argument');
}

$vars = get_class_vars(Notification::class);
$notification = new Notification();

$propertyAccessor = PropertyAccess::createPropertyAccessorBuilder()
->enableExceptionOnInvalidIndex()
->getPropertyAccessor();

foreach ($value as $property => $val) {
if (!in_array($property, $vars)) {
throw new \InvalidArgumentException('Object '.Notification::class.' does not have property '.$property);
}
$propertyAccessor->setValue($notification, "[{$property}]", $val);
}

return $notification;
}
}
4 changes: 2 additions & 2 deletions bundles/PluginBundle/Controller/AjaxController.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ public function getIntegrationFieldsAction(Request $request, IntegrationHelper $
$mauticFields = ($isLead) ? $pluginModel->getLeadFields() : $pluginModel->getCompanyFields();
$featureSettings = $integrationObject->getIntegrationSettings()->getFeatureSettings();
$enableDataPriority = $integrationObject->getDataPriority();
$formType = $isLead ? FieldsType::class : CompanyFieldsType::class;
$formType = $isLead ? 'integration_fields' : 'integration_company_fields';
$form = $this->createForm(
$formType,
$isLead ? FieldsType::class : CompanyFieldsType::class,
$featureSettings[$object.'Fields'] ?? [],
[
'mautic_fields' => $mauticFields,
Expand Down

0 comments on commit 6a294bd

Please sign in to comment.