Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
fec7bf0
Fire mautic.company_pre_merge and mautic.company_post_merge events
ReplicaObscura Jan 20, 2021
fd73a66
Initial support for syncing the merge operation for companies and con…
ReplicaObscura Jan 20, 2021
2dcf621
Merge branch 'company-merge-event' into pipedrive-merge-support
ReplicaObscura Jan 20, 2021
bbac14f
Fix field name mismatch
ReplicaObscura Jan 20, 2021
2d1ae01
Testing PR 6071
ReplicaObscura Jan 20, 2021
a478ffd
Add a setting to delete via cron, and keep the old behavior by default
ReplicaObscura Feb 8, 2021
1625583
Merge branch 'pipedrive-merge-support' into brilliant-metrics
ReplicaObscura Feb 8, 2021
cbf23c3
Separate create and update settings for Pipedrive
ReplicaObscura Feb 8, 2021
8052efa
Merge branch 'pipedrive-add-update-setting' into brilliant-metrics
ReplicaObscura Feb 8, 2021
23736fe
Fixes for PipedriveDeletion entity class
ReplicaObscura Feb 11, 2021
f95f3f1
Merge branch 'pipedrive-merge-support' into brilliant-metrics
ReplicaObscura Feb 11, 2021
a9fc114
Add missing rename
ReplicaObscura Feb 24, 2021
b587705
Merge branch 'pipedrive-merge-support' into brilliant-metrics
ReplicaObscura Feb 24, 2021
db57e1a
Update deletedDate field name reference
ReplicaObscura Feb 24, 2021
bd3d2f4
Merge branch 'pipedrive-merge-support' into brilliant-metrics
ReplicaObscura Feb 24, 2021
44b9ccb
Fix attempting to access the integration on the CompanyExport object …
ReplicaObscura Mar 18, 2021
b238ecb
Merge branch 'pipedrive-add-update-setting' into brilliant-metrics
ReplicaObscura Mar 18, 2021
09c6774
Fix order of operations
ReplicaObscura Mar 23, 2021
619cf55
Merge branch 'pipedrive-add-update-setting' into brilliant-metrics
ReplicaObscura Mar 23, 2021
d0c9d07
Add missing cron handler for pipedrive lead deletion
ReplicaObscura Apr 7, 2021
fef91c5
Merge branch 'pipedrive-merge-support' into brilliant-metrics
ReplicaObscura Apr 7, 2021
0ff69c3
Bug fixes
ReplicaObscura Apr 12, 2021
6da0814
Merge branch 'pipedrive-merge-support' into brilliant-metrics
ReplicaObscura Apr 12, 2021
471d304
Fix var reference
ReplicaObscura Apr 12, 2021
e3db065
Merge branch 'pipedrive-merge-support' into brilliant-metrics
ReplicaObscura Apr 12, 2021
a2f863c
Refactor data value access
ReplicaObscura Apr 19, 2021
fc1196d
Flush pipedrive deletions to database
ReplicaObscura Apr 19, 2021
880673e
Merge branch 'pipedrive-merge-support' into brilliant-metrics
ReplicaObscura Apr 19, 2021
484edfe
Fix merged ID that's passed in
ReplicaObscura May 7, 2021
4b307c8
Merge branch 'pipedrive-merge-support' into brilliant-metrics
ReplicaObscura May 7, 2021
1c0716f
Fix entity type reference for company in deletion queue
ReplicaObscura May 13, 2021
a26581f
Merge branch 'pipedrive-merge-support' into brilliant-metrics
ReplicaObscura May 13, 2021
ff08af2
Fix Lead class reference in ProcessPipedriveDeletionsCommand.php
ReplicaObscura Aug 3, 2021
a682e68
Force an additional update after a merge to standardize Mautic's data…
ReplicaObscura Aug 3, 2021
0162403
Merge branch 'pipedrive-merge-support' into brilliant-metrics
ReplicaObscura Aug 3, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/bundles/EmailBundle/Config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@
'translator',
'doctrine.orm.entity_manager',
'mautic.stage.model.stage',
'mautic.helper.core_parameters',
],
],
'mautic.form.type.email.utm_tags' => [
Expand Down
27 changes: 27 additions & 0 deletions app/bundles/EmailBundle/Entity/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ class Email extends FormEntity implements VariantEntityInterface, TranslationEnt
*/
private $subject;

/**
* @var bool
*/
private $useOwnerAsMailer;

/**
* @var string
*/
Expand Down Expand Up @@ -265,6 +270,7 @@ public static function loadMetadata(ORM\ClassMetadata $metadata)
$builder->addNullableField('fromName', Type::STRING, 'from_name');
$builder->addNullableField('replyToAddress', Type::STRING, 'reply_to_address');
$builder->addNullableField('bccAddress', Type::STRING, 'bcc_address');
$builder->addNullableField('useOwnerAsMailer', Type::BOOLEAN, 'use_owner_as_mailer');
$builder->addNullableField('template', Type::STRING);
$builder->addNullableField('content', Type::TARRAY);
$builder->addNullableField('utmTags', Type::TARRAY, 'utm_tags');
Expand Down Expand Up @@ -436,6 +442,7 @@ public static function loadApiMetadata(ApiMetadataDriver $metadata)
'fromName',
'replyToAddress',
'bccAddress',
'useOwnerAsMailer',
'utmTags',
'customHtml',
'plainText',
Expand Down Expand Up @@ -678,6 +685,26 @@ public function setSubject($subject)
return $this;
}

/**
* @return bool
*/
public function getUseOwnerAsMailer()
{
return $this->useOwnerAsMailer;
}

/**
* @param bool $useOwnerAsMailer
*
* @return $this
*/
public function setUseOwnerAsMailer($useOwnerAsMailer)
{
$this->useOwnerAsMailer = $useOwnerAsMailer;

return $this;
}

/**
* @return mixed
*/
Expand Down
31 changes: 27 additions & 4 deletions app/bundles/EmailBundle/Form/Type/EmailType.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Mautic\CoreBundle\Form\Type\SortableListType;
use Mautic\CoreBundle\Form\Type\ThemeListType;
use Mautic\CoreBundle\Form\Type\YesNoButtonGroupType;
use Mautic\CoreBundle\Helper\CoreParametersHelper;
use Mautic\EmailBundle\Entity\Email;
use Mautic\FormBundle\Form\Type\FormListType;
use Mautic\LeadBundle\Form\Type\LeadListType;
Expand Down Expand Up @@ -62,14 +63,21 @@ class EmailType extends AbstractType
*/
private $stageModel;

/**
* @var CoreParametersHelper
*/
private $coreParametersHelper;

public function __construct(
TranslatorInterface $translator,
EntityManager $entityManager,
StageModel $stageModel
StageModel $stageModel,
CoreParametersHelper $coreParametersHelper
) {
$this->translator = $translator;
$this->em = $entityManager;
$this->stageModel = $stageModel;
$this->translator = $translator;
$this->em = $entityManager;
$this->stageModel = $stageModel;
$this->coreParametersHelper = $coreParametersHelper;
}

public function buildForm(FormBuilderInterface $builder, array $options)
Expand Down Expand Up @@ -160,6 +168,21 @@ public function buildForm(FormBuilderInterface $builder, array $options)
]
);

$builder->add(
'useOwnerAsMailer',
YesNoButtonGroupType::class,
[
'label' => 'mautic.email.use.owner.as.mailer',
'label_attr' => ['class' => 'control-label'],
'attr' => [
'class' => 'form-control',
'tooltip' => 'mautic.email.use.owner.as.mailer.tooltip',
],
'data' => (bool) (is_null($options['data']->getUseOwnerAsMailer()) ? $this->coreParametersHelper->get('mailer_is_owner') : $options['data']->getUseOwnerAsMailer()),
'required' => false,
]
);

$builder->add(
'utmTags',
EmailUtmTagsType::class,
Expand Down
98 changes: 49 additions & 49 deletions app/bundles/EmailBundle/Helper/MailHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,6 @@ class MailHelper
*/
protected $fatal = false;

/**
* Flag whether to use only the globally set From email and name or whether to switch to mailer is owner.
*
* @var bool
*/
protected $useGlobalFrom = false;

/**
* Large batch mail sends may result on timeouts with SMTP servers. This will will keep track of the number of sends and restart the connection once met.
*
Expand Down Expand Up @@ -323,18 +316,17 @@ public function getSampleMailer($cleanSlate = true)
*
* @param bool $dispatchSendEvent
* @param bool $isQueueFlush (a tokenized/batch send via API such as Mandrill)
* @param bool $useOwnerAsMailer
*
* @return bool
*/
public function send($dispatchSendEvent = false, $isQueueFlush = false, $useOwnerAsMailer = true)
public function send($dispatchSendEvent = false, $isQueueFlush = false)
{
if ($this->tokenizationEnabled && !empty($this->queuedRecipients) && !$isQueueFlush) {
// This transport uses tokenization and queue()/flushQueue() was not used therefore use them in order
// properly populate metadata for this transport

if ($result = $this->queue($dispatchSendEvent)) {
$result = $this->flushQueue(['To', 'Cc', 'Bcc'], $useOwnerAsMailer);
$result = $this->flushQueue(['To', 'Cc', 'Bcc']);
}

return $result;
Expand All @@ -343,15 +335,23 @@ public function send($dispatchSendEvent = false, $isQueueFlush = false, $useOwne
// Set from email
$ownerSignature = false;
if (!$isQueueFlush) {
if ($useOwnerAsMailer) {
if ($owner = $this->getContactOwner($this->lead)) {
$this->setFrom($owner['email'], $owner['first_name'].' '.$owner['last_name'], null);
$ownerSignature = $this->getContactOwnerSignature($owner);
$emailToSend = $this->getEmail();
if (!empty($emailToSend)) {
if ($emailToSend->getUseOwnerAsMailer()) {
$owner = $this->getContactOwner($this->lead);
if (!empty($owner)) {
$this->setFrom($owner['email'], $owner['first_name'].' '.$owner['last_name']);
$ownerSignature = $this->getContactOwnerSignature($owner);
} else {
$this->setFrom($this->systemFrom, null);
}
} elseif (!empty($emailToSend->getFromAddress())) {
$this->setFrom($emailToSend->getFromAddress(), $emailToSend->getFromName());
} else {
$this->setFrom($this->from, null, null);
$this->setFrom($this->systemFrom, null);
}
} elseif (!$from = $this->message->getFrom()) {
$this->setFrom($this->from, null, null);
} else {
$this->setFrom($this->from, null);
}
} // from is set in flushQueue

Expand Down Expand Up @@ -572,12 +572,11 @@ public function queue($dispatchSendEvent = false, $returnMode = self::QUEUE_RESE
/**
* Send batched mail to mailer.
*
* @param array $resetEmailTypes Array of email types to clear after flusing the queue
* @param bool $useOwnerAsMailer
* @param array $resetEmailTypes Array of email types to clear after flusing the queue
*
* @return bool
*/
public function flushQueue($resetEmailTypes = ['To', 'Cc', 'Bcc'], $useOwnerAsMailer = true)
public function flushQueue($resetEmailTypes = ['To', 'Cc', 'Bcc'])
{
// Assume true unless there was a fatal error configuring the mailer because if tokenizationEnabled is false, the send happened in queue()
$flushed = empty($this->fatal);
Expand All @@ -593,10 +592,18 @@ public function flushQueue($resetEmailTypes = ['To', 'Cc', 'Bcc'], $useOwnerAsMa

$this->errors = [];

if (!$this->useGlobalFrom && $useOwnerAsMailer && 'default' !== $fromKey) {
$this->setFrom($metadatum['from']['email'], $metadatum['from']['first_name'].' '.$metadatum['from']['last_name'], null);
$email = $this->getEmail();

if (!empty($email)) {
if ($email->getUseOwnerAsMailer() && 'default' !== $fromKey) {
$this->setFrom($metadatum['from']['email'], $metadatum['from']['first_name'].' '.$metadatum['from']['last_name']);
} elseif (!empty($email->getFromAddress())) {
$this->setFrom($email->getFromAddress(), $email->getFromName());
} else {
$this->setFrom($this->systemFrom, null);
}
} else {
$this->setFrom($this->from, null, null);
$this->setFrom($this->from, null);
}

foreach ($metadatum['contacts'] as $email => $contact) {
Expand Down Expand Up @@ -657,7 +664,6 @@ public function reset($cleanSlate = true)
$this->internalSend = false;
$this->fatal = false;
$this->idHashState = true;
$this->useGlobalFrom = false;
$this->checkIfTransportNeedsRestart(true);

$this->logger->clear();
Expand Down Expand Up @@ -1235,25 +1241,15 @@ public function setReturnPath($address)
*
* @param string|array $fromEmail
* @param string $fromName
* @param bool|null $isGlobal
*/
public function setFrom($fromEmail, $fromName = null, $isGlobal = true)
public function setFrom($fromEmail, $fromName = null)
{
$fromName = $this->cleanName($fromName);

if (null !== $isGlobal) {
if ($isGlobal) {
if (is_array($fromEmail)) {
$this->from = $fromEmail;
} else {
$this->from = [$fromEmail => $fromName];
}
} else {
// Reset the default to the system from
$this->from = $this->systemFrom;
}

$this->useGlobalFrom = $isGlobal;
if (is_array($fromEmail)) {
$this->from = $fromEmail;
} else {
$this->from = [$fromEmail => $fromName];
}

try {
Expand Down Expand Up @@ -1371,7 +1367,7 @@ public function setEmail(Email $email, $allowBcc = true, $slots = [], $assetAtta
$fromEmail = key($this->from);
}

$this->setFrom($fromEmail, $fromName, null);
$this->setFrom($fromEmail, $fromName);
$this->from = [$fromEmail => $fromName];
} else {
$this->from = $this->systemFrom;
Expand Down Expand Up @@ -2055,15 +2051,19 @@ protected function cleanName($name)
protected function getContactOwner(&$contact)
{
$owner = false;

if ($this->factory->getParameter('mailer_is_owner') && is_array($contact) && isset($contact['id'])) {
if (!isset($contact['owner_id'])) {
$contact['owner_id'] = 0;
} elseif (isset($contact['owner_id'])) {
if (isset(self::$leadOwners[$contact['owner_id']])) {
$owner = self::$leadOwners[$contact['owner_id']];
} elseif ($owner = $this->factory->getModel('lead')->getRepository()->getLeadOwner($contact['owner_id'])) {
self::$leadOwners[$owner['id']] = $owner;
$email = $this->getEmail();

if (!empty($email)) {
if ($email->getUseOwnerAsMailer() && is_array($contact) && isset($contact['id'])) {
if (!isset($contact['owner_id'])) {
$contact['owner_id'] = 0;
} elseif (isset($contact['owner_id'])) {
$leadModel = $this->factory->getModel('lead');
if (isset(self::$leadOwners[$contact['owner_id']])) {
$owner = self::$leadOwners[$contact['owner_id']];
} elseif ($owner = $leadModel->getRepository()->getLeadOwner($contact['owner_id'])) {
self::$leadOwners[$owner['id']] = $owner;
}
}
}
}
Expand Down
22 changes: 15 additions & 7 deletions app/bundles/EmailBundle/Tests/Form/Type/EmailTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Doctrine\ORM\EntityManager;
use Mautic\CoreBundle\Form\Type\FormButtonsType;
use Mautic\CoreBundle\Helper\CoreParametersHelper;
use Mautic\EmailBundle\Entity\Email;
use Mautic\EmailBundle\Form\Type\EmailType;
use Mautic\StageBundle\Model\StageModel;
Expand Down Expand Up @@ -47,18 +48,25 @@ class EmailTypeTest extends \PHPUnit\Framework\TestCase
*/
private $form;

/**
* @var CoreParametersHelper|MockObject
*/
private $coreParametersHelper;

protected function setUp(): void
{
parent::setUp();

$this->translator = $this->createMock(TranslatorInterface::class);
$this->entityManager = $this->createMock(EntityManager::class);
$this->stageModel = $this->createMock(StageModel::class);
$this->formBuilder = $this->createMock(FormBuilderInterface::class);
$this->form = new EmailType(
$this->translator = $this->createMock(TranslatorInterface::class);
$this->entityManager = $this->createMock(EntityManager::class);
$this->stageModel = $this->createMock(StageModel::class);
$this->formBuilder = $this->createMock(FormBuilderInterface::class);
$this->coreParametersHelper = $this->createMock(CoreParametersHelper::class);
$this->form = new EmailType(
$this->translator,
$this->entityManager,
$this->stageModel
$this->stageModel,
$this->coreParametersHelper
);

$this->formBuilder->method('create')->willReturnSelf();
Expand All @@ -70,7 +78,7 @@ public function testBuildForm()
'data' => new Email(),
];

$this->formBuilder->expects($this->at(46))
$this->formBuilder->expects($this->at(47))
->method('add')
->with(
'buttons',
Expand Down
Loading