Skip to content
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

Merged
merged 24 commits into from
Apr 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
9d921e3
LeadManipulator + event log
Hadamcik Nov 27, 2017
7643b19
LeadModel +setManipulator
Hadamcik Nov 27, 2017
e88ec04
Fix manipulators
Hadamcik Nov 27, 2017
f504a28
Page hits fix
Hadamcik Nov 27, 2017
62c6882
Merge event log
Hadamcik Nov 28, 2017
c6add31
Pull staging
Hadamcik Nov 28, 2017
8143b25
PHPDoc
Hadamcik Mar 27, 2018
7de7a6b
Pull upstream staging
Hadamcik Mar 27, 2018
47ea3c0
Log import ID
Hadamcik Mar 28, 2018
aab73cf
Merge branch 'staging' of github.com:mautic/mautic into staging.track…
Hadamcik Mar 28, 2018
c16a7f0
Force reformat
Hadamcik Mar 28, 2018
0ae20af
Fixed issue with tracking pixel where $page is null and also only man…
alanhartless Mar 29, 2018
cd52227
Don't store a create/identified event everytime the contact is saved
alanhartless Mar 29, 2018
3c522bd
Don't store empty logs for deleted contacts
alanhartless Mar 29, 2018
cfc0aec
Added action index
alanhartless Mar 30, 2018
22778b6
Do not create visitors for certain requests (javascript endpoints tha…
alanhartless Mar 30, 2018
2f03a0b
Display entries in the timeline
alanhartless Mar 30, 2018
ef4ba89
Store a description to display in the timeline
alanhartless Mar 30, 2018
b5423e0
Fixed tests
alanhartless Apr 2, 2018
b5ef6f8
LandingPage tests
Hadamcik Apr 5, 2018
8b5b79c
Fix tests + skip second visit test
Hadamcik Apr 5, 2018
855863b
Merge branch 'staging' of github.com:Dreiser/mautic into staging.trac…
Hadamcik Apr 5, 2018
f9bf1ed
Pull staging
Hadamcik Apr 5, 2018
e3d2e1f
Set current lead missing - fix
Hadamcik Apr 5, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/bundles/CoreBundle/Controller/JsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class JsController extends CommonController
*/
public function indexAction()
{
// Don't store a visitor with this request
defined('MAUTIC_NON_TRACKABLE_REQUEST') || define('MAUTIC_NON_TRACKABLE_REQUEST', 1);

$dispatcher = $this->dispatcher;
$debug = $this->factory->getKernel()->isDebug();
$event = new BuildJsEvent($this->getJsHeader(), $debug);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class DynamicContentApiController extends CommonController
*/
public function processAction($objectAlias)
{
// Don't store a visitor with this request
defined('MAUTIC_NON_TRACKABLE_REQUEST') || define('MAUTIC_NON_TRACKABLE_REQUEST', 1);

$method = $this->request->getMethod();
if (method_exists($this, $method.'Action')) {
return $this->{$method.'Action'}($objectAlias);
Expand All @@ -42,6 +45,9 @@ public function processAction($objectAlias)

public function getAction($objectAlias)
{
// Don't store a visitor with this request
defined('MAUTIC_NON_TRACKABLE_REQUEST') || define('MAUTIC_NON_TRACKABLE_REQUEST', 1);

/** @var LeadModel $model */
$model = $this->getModel('lead');
/** @var DynamicContentHelper $helper */
Expand Down
3 changes: 3 additions & 0 deletions app/bundles/FormBundle/Controller/PublicController.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,9 @@ public function previewAction($id = 0)
*/
public function generateAction()
{
// Don't store a visitor with this request
defined('MAUTIC_NON_TRACKABLE_REQUEST') || define('MAUTIC_NON_TRACKABLE_REQUEST', 1);

$formId = InputHelper::int($this->request->get('id'));

$model = $this->getModel('form.form');
Expand Down
7 changes: 7 additions & 0 deletions app/bundles/FormBundle/Model/SubmissionModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use Mautic\FormBundle\Helper\FormFieldHelper;
use Mautic\FormBundle\Helper\FormUploader;
use Mautic\FormBundle\Validator\UploadFieldValidator;
use Mautic\LeadBundle\DataObject\LeadManipulator;
use Mautic\LeadBundle\Entity\Company;
use Mautic\LeadBundle\Entity\CompanyChangeLog;
use Mautic\LeadBundle\Entity\Lead;
Expand Down Expand Up @@ -1012,6 +1013,12 @@ protected function createLeadFromSubmit(Form $form, array $leadFieldMatches, $le
$lead->setLastActive(new \DateTime());

//create a new lead
$lead->setManipulator(new LeadManipulator(
'form',
'submission',
$form->getId(),
$form->getName()
));
$this->leadModel->saveEntity($lead, false);

if (!$inKioskMode) {
Expand Down
14 changes: 14 additions & 0 deletions app/bundles/LeadBundle/Config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,13 @@
'mautic.lead.configbundle.subscriber' => [
'class' => Mautic\LeadBundle\EventListener\ConfigSubscriber::class,
],
'mautic.lead.timeline_events.subscriber' => [
'class' => \Mautic\LeadBundle\EventListener\TimelineEventLogSubscriber::class,
'arguments' => [
'translator',
'mautic.lead.repository.lead_event_log',
],
],
],
'forms' => [
'mautic.form.type.lead' => [
Expand Down Expand Up @@ -732,6 +739,13 @@
\Mautic\LeadBundle\Entity\Lead::class,
],
],
'mautic.lead.repository.lead_event_log' => [
'class' => Doctrine\ORM\EntityRepository::class,
'factory' => ['@doctrine.orm.entity_manager', 'getRepository'],
'arguments' => [
\Mautic\LeadBundle\Entity\LeadEventLog::class,
],
],
'mautic.lead.repository.lead_device' => [
'class' => Doctrine\ORM\EntityRepository::class,
'factory' => ['@doctrine.orm.entity_manager', 'getRepository'],
Expand Down
13 changes: 13 additions & 0 deletions app/bundles/LeadBundle/Controller/LeadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Mautic\CoreBundle\Controller\FormController;
use Mautic\CoreBundle\Helper\EmojiHelper;
use Mautic\CoreBundle\Model\IteratorExportDataModel;
use Mautic\LeadBundle\DataObject\LeadManipulator;
use Mautic\LeadBundle\Entity\DoNotContact;
use Mautic\LeadBundle\Entity\Lead;
use Mautic\LeadBundle\Model\LeadModel;
Expand Down Expand Up @@ -441,6 +442,12 @@ public function newAction()
$model->setFieldValues($lead, $data, true);

//form is valid so process the data
$lead->setManipulator(new LeadManipulator(
'lead',
'lead',
null,
$this->get('mautic.helper.user')->getUser()->getName()
));
$model->saveEntity($lead);

if (!empty($companies)) {
Expand Down Expand Up @@ -622,6 +629,12 @@ public function editAction($objectId, $ignorePost = false)
$model->setFieldValues($lead, $data, true);

//form is valid so process the data
$lead->setManipulator(new LeadManipulator(
'lead',
'lead',
$objectId,
$this->get('mautic.helper.user')->getUser()->getName()
));
$model->saveEntity($lead, $form->get('buttons')->get('save')->isClicked());
$model->modifyCompanies($lead, $companies);

Expand Down
83 changes: 83 additions & 0 deletions app/bundles/LeadBundle/DataObject/LeadManipulator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?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;

/**
* @var string|null
*/
private $objectDescription;

/**
* LeadManipulator constructor.
*
* @param null $bundleName
* @param null $objectName
* @param null $objectId
* @param null $objectDescription
*/
public function __construct($bundleName = null, $objectName = null, $objectId = null, $objectDescription = null)
{
$this->bundleName = $bundleName;
$this->objectName = $objectName;
$this->objectId = $objectId;
$this->objectDescription = $objectDescription;
}

/**
* @return string
*/
public function getBundleName()
{
return $this->bundleName;
}

/**
* @return string
*/
public function getObjectName()
{
return $this->objectName;
}

/**
* @return int
*/
public function getObjectId()
{
return $this->objectId;
}

public function getObjectDescription()
{
return $this->objectDescription;
}
}
36 changes: 35 additions & 1 deletion app/bundles/LeadBundle/Entity/Lead.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -199,6 +200,11 @@ class Lead extends FormEntity implements CustomFieldEntityInterface
*/
private $color;

/**
* @var LeadManipulator
*/
private $manipulator = null;

/**
* Sets if the IP was just created by LeadModel::getCurrentLead().
*
Expand Down Expand Up @@ -1264,6 +1270,14 @@ public function isAnonymous()
);
}

/**
* @return bool
*/
public function wasAnonymous()
{
return $this->dateIdentified == null && $this->isAnonymous() === false;
}

/**
* @return bool
*/
Expand All @@ -1286,6 +1300,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
*/
Expand Down Expand Up @@ -1553,7 +1587,7 @@ public function checkAttributionDate()
*/
public function checkDateIdentified()
{
if ($this->dateIdentified == null && $this->isAnonymous() === false) {
if ($this->wasAnonymous()) {
$this->dateIdentified = new \DateTime();
$this->changes['dateIdentified'] = ['', $this->dateIdentified];
}
Expand Down
3 changes: 2 additions & 1 deletion app/bundles/LeadBundle/Entity/LeadEventLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public static function loadMetadata(ORM\ClassMetadata $metadata)
->addIndex(['lead_id'], 'lead_id_index')
->addIndex(['object', 'object_id'], 'lead_object_index')
->addIndex(['bundle', 'object', 'action', 'object_id'], 'lead_timeline_index')
->addIndex(['action'], 'lead_timeline_action_index')
->addIndex(['date_added'], 'lead_date_added_index')
->addId()
->addNullableField('userId', Type::INTEGER, 'user_id')
Expand All @@ -101,7 +102,7 @@ public static function loadMetadata(ORM\ClassMetadata $metadata)
->addNullableField('properties', Type::JSON_ARRAY);

$builder->createManyToOne('lead', Lead::class)
->addJoinColumn('lead_id', 'id', true, false, 'SET NULL')
->addJoinColumn('lead_id', 'id', true, false, 'CASCADE')
->inversedBy('eventLog')
->build();
}
Expand Down