-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tracking lead manipulator #5379
Changes from 6 commits
9d921e3
7643b19
e88ec04
f504a28
62c6882
c6add31
8143b25
7de7a6b
47ea3c0
aab73cf
c16a7f0
0ae20af
cd52227
3c522bd
cfc0aec
22778b6
2f03a0b
ef4ba89
b5423e0
b5ef6f8
8b5b79c
855863b
f9bf1ed
e3d2e1f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
/* | ||
* @copyright 2014 Mautic Contributors. All rights reserved | ||
* @author Mautic | ||
* | ||
* @link http://mautic.org | ||
* | ||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html | ||
*/ | ||
|
||
namespace Mautic\LeadBundle\DataObject; | ||
|
||
/** | ||
* Class LeadManipulator. | ||
*/ | ||
class LeadManipulator | ||
{ | ||
/** @var string|null */ | ||
private $bundleName; | ||
|
||
/** @var string|null */ | ||
private $objectName; | ||
|
||
/** @var int|null */ | ||
private $objectId; | ||
|
||
/** | ||
* LeadManipulator constructor. | ||
* | ||
* @param string|null $bundleName | ||
* @param string|null $objectName | ||
* @param int|null $objectId | ||
*/ | ||
public function __construct($bundleName = null, $objectName = null, $objectId = null) | ||
{ | ||
$this->bundleName = $bundleName; | ||
$this->objectName = $objectName; | ||
$this->objectId = $objectId; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getBundleName() | ||
{ | ||
return $this->bundleName; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getObjectName() | ||
{ | ||
return $this->objectName; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getObjectId() | ||
{ | ||
return $this->objectId; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
use Mautic\CoreBundle\Doctrine\Mapping\ClassMetadataBuilder; | ||
use Mautic\CoreBundle\Entity\FormEntity; | ||
use Mautic\CoreBundle\Entity\IpAddress; | ||
use Mautic\LeadBundle\DataObject\LeadManipulator; | ||
use Mautic\LeadBundle\Model\FieldModel; | ||
use Mautic\NotificationBundle\Entity\PushID; | ||
use Mautic\StageBundle\Entity\Stage; | ||
|
@@ -199,6 +200,9 @@ class Lead extends FormEntity implements CustomFieldEntityInterface | |
*/ | ||
private $color; | ||
|
||
/** @var LeadManipulator */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this annotation use the new lines as all of the annotations above and bellow? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, it's just so long.. |
||
private $manipulator = null; | ||
|
||
/** | ||
* Sets if the IP was just created by LeadModel::getCurrentLead(). | ||
* | ||
|
@@ -1286,6 +1290,26 @@ protected function getFirstSocialIdentity() | |
return false; | ||
} | ||
|
||
/** | ||
* @param LeadManipulator|null $manipulator | ||
* | ||
* @return self | ||
*/ | ||
public function setManipulator(LeadManipulator $manipulator = null) | ||
{ | ||
$this->manipulator = $manipulator; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return LeadManipulator|null | ||
*/ | ||
public function getManipulator() | ||
{ | ||
return $this->manipulator; | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ | |
use Mautic\CoreBundle\Helper\PathsHelper; | ||
use Mautic\CoreBundle\Model\FormModel; | ||
use Mautic\EmailBundle\Helper\EmailValidator; | ||
use Mautic\LeadBundle\DataObject\LeadManipulator; | ||
use Mautic\LeadBundle\Entity\Company; | ||
use Mautic\LeadBundle\Entity\CompanyChangeLog; | ||
use Mautic\LeadBundle\Entity\DoNotContact; | ||
|
@@ -497,6 +498,21 @@ public function saveEntity($entity, $unlock = true) | |
$entity->addCompanyChangeLogEntry('form', 'Identify Company', 'Lead added to the company, '.$company['companyname'], $company['id']); | ||
} | ||
} | ||
$manipulator = $entity->getManipulator(); | ||
if ($manipulator !== null) { | ||
$manipulationLog = new LeadEventLog(); | ||
$manipulationLog->setLead($entity); | ||
$manipulationLog->setBundle($manipulator->getBundleName()); | ||
$manipulationLog->setObject($manipulator->getObjectName()); | ||
$manipulationLog->setObjectId($manipulator->getObjectId()); | ||
if ($entity->isNewlyCreated()) { | ||
$manipulationLog->setAction('create'); | ||
} else { | ||
$manipulationLog->setAction('identified'); | ||
} | ||
$entity->addEventLog($manipulationLog); | ||
$entity->setManipulator(null); | ||
} | ||
|
||
$this->setEntityDefaultValues($entity); | ||
|
||
|
@@ -1906,6 +1922,10 @@ public function import($fields, $data, $owner = null, $list = null, $tags = null | |
} | ||
|
||
if ($persist) { | ||
$lead->setManipulator(new LeadManipulator( | ||
'lead', | ||
'lead' | ||
)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe I'm not understanding the task right, but how can you tell if the source of the lead is import over manual creation over UI? This code is called 4 times on 4 different places. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's already long time, so I did not fully recalled what is bundle name and what is object name. Where do you see problem? It's manipulated from lead bundle, lead model so it's lead-lead if I'm right. I'm not sure if it says something about UI |
||
$this->saveEntity($lead); | ||
|
||
if ($list !== null) { | ||
|
@@ -2911,6 +2931,10 @@ protected function createNewContact(IpAddress $ip, $persist = true) | |
if ($persist) { | ||
// Set to prevent loops | ||
$this->currentLead = $lead; | ||
$lead->setManipulator(new LeadManipulator( | ||
'lead', | ||
'lead' | ||
)); | ||
$this->saveEntity($lead, false); | ||
|
||
$fields = $this->getLeadDetails($lead); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reason why the first 2 params are nullable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because in database, they can be nullable. I thought maybe there is use case when it's possible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I was thinking we should write the code as strict as possible.