Skip to content

Commit

Permalink
Segment public name property for preference center (#8238)
Browse files Browse the repository at this point in the history
* Segment public name property for preference center

* Lead lists public_name migration update

* Updated tests for segment public name

* Migrate segment public name property feature to v3

* Add default value for segment public_name field

* Update failing campaign test schema

* Fix test

Co-authored-by: Dennis Ameling <dennis@dennisameling.com>
  • Loading branch information
patrykgruszka and dennisameling committed Nov 21, 2020
1 parent 30d909d commit 60bdfc8
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/bundles/CampaignBundle/Tests/Command/campaign_schema.sql
Expand Up @@ -39,9 +39,9 @@ VALUES
(15,1,3,'Tag EmailNotOpen Again',NULL,'lead.changetags','action',3,'a:16:{s:14:\"canvasSettings\";a:2:{s:8:\"droppedX\";s:4:\"1612\";s:8:\"droppedY\";s:3:\"374\";}s:4:\"name\";s:22:\"Tag EmailNotOpen Again\";s:11:\"triggerMode\";s:8:\"interval\";s:11:\"triggerDate\";N;s:15:\"triggerInterval\";s:1:\"6\";s:19:\"triggerIntervalUnit\";s:1:\"i\";s:6:\"anchor\";s:2:\"no\";s:10:\"properties\";a:1:{s:8:\"add_tags\";a:1:{i:0;s:1:\"9\";}}s:4:\"type\";s:15:\"lead.changetags\";s:9:\"eventType\";s:6:\"action\";s:15:\"anchorEventType\";s:8:\"decision\";s:10:\"campaignId\";s:1:\"1\";s:6:\"_token\";s:43:\"Wd8bGtv2HJ6Nyf3K90Efoo2Rn2VkDWwXhwzCIPMiD-M\";s:7:\"buttons\";a:1:{s:4:\"save\";s:0:\"\";}s:8:\"add_tags\";a:1:{i:0;s:12:\"EmailNotOpen\";}s:11:\"remove_tags\";a:0:{}}',NULL,6,'i','interval','no','newf16dfec5f2a65aa9c527675e7be516020a90daa6',NULL,NULL),
(16,1,12,'Tag ChainedAction',NULL,'lead.changetags','action',4,'a:16:{s:14:\"canvasSettings\";a:2:{s:8:\"droppedX\";s:3:\"168\";s:8:\"droppedY\";s:3:\"439\";}s:4:\"name\";s:14:\"Chained Action\";s:11:\"triggerMode\";s:9:\"immediate\";s:11:\"triggerDate\";N;s:15:\"triggerInterval\";s:1:\"1\";s:19:\"triggerIntervalUnit\";s:1:\"d\";s:6:\"anchor\";s:6:\"bottom\";s:10:\"properties\";a:1:{s:8:\"add_tags\";a:1:{i:0;s:2:\"10\";}}s:4:\"type\";s:15:\"lead.changetags\";s:9:\"eventType\";s:6:\"action\";s:15:\"anchorEventType\";s:6:\"action\";s:10:\"campaignId\";s:1:\"1\";s:6:\"_token\";s:43:\"6xgHe74aRnc1V7AGzdang3-iJ0Ub5BKfbdU5NsxQmv0\";s:7:\"buttons\";a:1:{s:4:\"save\";s:0:\"\";}s:8:\"add_tags\";a:1:{i:0;s:13:\"ChainedAction\";}s:11:\"remove_tags\";a:0:{}}',NULL,1,'d','immediate',NULL,'new60f74507aeccf217f78647e41ae29af51debe666',NULL,NULL);

INSERT INTO `#__lead_lists` (`id`,`is_preference_center`, `is_published`,`date_added`,`created_by`,`created_by_user`,`date_modified`,`modified_by`,`modified_by_user`,`checked_out`,`checked_out_by`,`checked_out_by_user`,`name`,`description`,`alias`,`filters`,`is_global`)
INSERT INTO `#__lead_lists` (`id`,`is_preference_center`, `is_published`,`date_added`,`created_by`,`created_by_user`,`date_modified`,`modified_by`,`modified_by_user`,`checked_out`,`checked_out_by`,`checked_out_by_user`,`name`,`description`,`alias`,`filters`,`is_global`, `public_name`)
VALUES
(1,0,1,'2018-01-04 23:41:20',1,'Admin User',NULL,NULL,NULL,NULL,NULL,NULL,'Campaign Test',NULL,'campaign-test','a:0:{}',1);
(1,0,1,'2018-01-04 23:41:20',1,'Admin User',NULL,NULL,NULL,NULL,NULL,NULL,'Campaign Test',NULL,'campaign-test','a:0:{}',1,'campaign-test');

INSERT INTO `#__campaign_leadlist_xref` (`campaign_id`,`leadlist_id`)
VALUES
Expand Down
Expand Up @@ -38,6 +38,7 @@ public function load(ObjectManager $manager)

$list = new LeadList();
$list->setName('United States');
$list->setPublicName('United States');
$list->setAlias('us');
$list->setCreatedBy($adminUser);
$list->setIsGlobal(true);
Expand Down
35 changes: 35 additions & 0 deletions app/bundles/LeadBundle/Entity/LeadList.php
Expand Up @@ -35,6 +35,11 @@ class LeadList extends FormEntity
*/
private $name;

/**
* @var string
*/
private $publicName;

/**
* @var string
*/
Expand Down Expand Up @@ -84,6 +89,10 @@ public static function loadMetadata(ORM\ClassMetadata $metadata)

$builder->addField('alias', 'string');

$builder->createField('publicName', 'string')
->columnName('public_name')
->build();

$builder->addField('filters', 'array');

$builder->createField('isGlobal', 'boolean')
Expand Down Expand Up @@ -125,6 +134,7 @@ public static function loadApiMetadata(ApiMetadataDriver $metadata)
[
'id',
'name',
'publicName',
'alias',
'description',
]
Expand Down Expand Up @@ -199,6 +209,31 @@ public function getDescription()
return $this->description;
}

/**
* Get publicName.
*
* @return string
*/
public function getPublicName()
{
return $this->publicName;
}

/**
* Set publicName.
*
* @param string $publicName
*
* @return LeadList
*/
public function setPublicName($publicName)
{
$this->isChanged('publicName', $publicName);
$this->publicName = $publicName;

return $this;
}

/**
* Set filters.
*
Expand Down
2 changes: 1 addition & 1 deletion app/bundles/LeadBundle/Entity/LeadListRepository.php
Expand Up @@ -266,7 +266,7 @@ public function getPreferenceCenterList()
$q = $this->getEntityManager()->createQueryBuilder()
->from(LeadList::class, 'l', 'l.id');

$q->select('partial l.{id, name, alias}')
$q->select('partial l.{id, name, publicName, alias}')
->where($q->expr()->eq('l.isPublished', 'true'))
->setParameter(':true', true, 'boolean')
->andWhere($q->expr()->eq('l.isPreferenceCenter', ':true'))
Expand Down
6 changes: 5 additions & 1 deletion app/bundles/LeadBundle/Form/Type/LeadListType.php
Expand Up @@ -39,7 +39,11 @@ public function configureOptions(OptionsResolver $resolver)

$choices = [];
foreach ($lists as $l) {
$choices[$l['name']] = $l['id'];
if (empty($options['preference_center_only'])) {
$choices[$l['name']] = $l['id'];
} else {
$choices[empty($l['publicName']) ? $l['name'] : $l['publicName']] = $l['id'];
}
}

return $choices;
Expand Down
14 changes: 14 additions & 0 deletions app/bundles/LeadBundle/Form/Type/ListType.php
Expand Up @@ -138,6 +138,20 @@ public function buildForm(FormBuilderInterface $builder, array $options)
]
);

$builder->add(
'publicName',
TextType::class,
[
'label' => 'mautic.lead.list.form.publicname',
'label_attr' => ['class' => 'control-label'],
'attr' => [
'class' => 'form-control',
'tooltip' => 'mautic.lead.list.form.publicname.tooltip',
],
'required' => false,
]
);

$builder->add(
'alias',
TextType::class,
Expand Down
8 changes: 8 additions & 0 deletions app/bundles/LeadBundle/Model/ListModel.php
Expand Up @@ -11,6 +11,7 @@

namespace Mautic\LeadBundle\Model;

use Doctrine\DBAL\DBALException;
use Mautic\CoreBundle\Helper\Chart\BarChart;
use Mautic\CoreBundle\Helper\Chart\ChartQuery;
use Mautic\CoreBundle\Helper\Chart\LineChart;
Expand Down Expand Up @@ -119,6 +120,8 @@ public function getPermissionBase()
* @param bool $unlock
*
* @return mixed|void
*
* @throws DBALException
*/
public function saveEntity($entity, $unlock = true)
{
Expand Down Expand Up @@ -151,6 +154,11 @@ public function saveEntity($entity, $unlock = true)
}
$entity->setAlias($alias);

$publicName = $entity->getPublicName();
if (empty($publicName)) {
$entity->setPublicName($entity->getName());
}

$event = $this->dispatchEvent('pre_save', $entity, $isNew);
$repo->saveEntity($entity);
$this->dispatchEvent('post_save', $entity, $isNew, $event);
Expand Down
Expand Up @@ -854,6 +854,7 @@ protected function createSegment($listConfig, ObjectManager $manager)

$list = new LeadList();
$list->setName($listConfig['name']);
$list->setPublicName($listConfig['name']);
$list->setAlias($listConfig['alias']);
$list->setCreatedBy($adminUser);
$list->setIsGlobal($listConfig['public']);
Expand Down
Expand Up @@ -36,6 +36,7 @@ private function createLeadList(User $user, string $name, bool $isGlobal): LeadL
{
$leadList = new LeadList();
$leadList->setName($name);
$leadList->setPublicName('Public'.$name);
$leadList->setAlias(mb_strtolower($name));
$leadList->setCreatedBy($user);
$leadList->setIsGlobal($isGlobal);
Expand Down
2 changes: 2 additions & 0 deletions app/bundles/LeadBundle/Translations/en_US/messages.ini
Expand Up @@ -431,6 +431,8 @@ mautic.lead.list.form.glue.and="and"
mautic.lead.list.form.glue.or="or"
mautic.lead.list.form.isglobal="Public Segment"
mautic.lead.list.form.isglobal.tooltip="This option enable segment usage in Mautic with contact preferences and any actions."
mautic.lead.list.form.publicname="Public name"
mautic.lead.list.form.publicname.tooltip="Name visible in Preference Center. Public name will be autogenerated if left empty."
mautic.lead.list.form.isPreferenceCenter="Available in Preference Center"
mautic.lead.list.form.isPreferenceCenter.tooltip="Segment can be editable by contact in preferences center."
mautic.lead.list.form.operator.between="between"
Expand Down
3 changes: 3 additions & 0 deletions app/bundles/LeadBundle/Views/List/form.html.php
Expand Up @@ -78,6 +78,9 @@
<div class="col-md-6">
<?php echo $view['form']->row($form['alias']); ?>
</div>
<div class="col-md-6">
<?php echo $view['form']->row($form['publicName']); ?>
</div>
</div>
<div class="row">
<div class="col-xs-12">
Expand Down
46 changes: 46 additions & 0 deletions app/migrations/Version20191206113956.php
@@ -0,0 +1,46 @@
<?php

/*
* @package Mautic
* @copyright 2019 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\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\SchemaException;
use Doctrine\Migrations\Exception\SkipMigration;
use Mautic\CoreBundle\Doctrine\AbstractMauticMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
class Version20191206113956 extends AbstractMauticMigration
{
/**
* @throws SkipMigration
* @throws SchemaException
*/
public function preUp(Schema $schema): void
{
$table = $schema->getTable($this->prefix.'lead_lists');

if ($table->hasColumn('public_name')) {
throw new SkipMigration('Schema includes this migration');
}
}

public function up(Schema $schema): void
{
$this->addSql("ALTER TABLE {$this->prefix}lead_lists ADD public_name VARCHAR(255) DEFAULT '' NOT NULL");
$this->addSql("UPDATE {$this->prefix}lead_lists SET public_name=name");
}

public function down(Schema $schema): void
{
$this->addSql("{$this->prefix}ALTER TABLE lead_lists DROP public_name");
}
}

0 comments on commit 60bdfc8

Please sign in to comment.