Skip to content

Commit b1516a3

Browse files
author
Dmitriev Alexandr
authored
BB-19484: Email campaign sending cusumer error (#28154)
- fix Account contactInformation virtual field configuration - fix query converter for case when two more joins, one of which related to another one added in the configuration of the single virtual field - add Account Contact information as an "email" contact information to allow to use it in the marketing campaigns - add functional test - add behat tests - fix unit tests - fix data fixture - fix bc break in query converter
1 parent 82ca22c commit b1516a3

File tree

3 files changed

+108
-7
lines changed

3 files changed

+108
-7
lines changed

src/Oro/Bundle/ActionBundle/Provider/OriginalUrlProvider.php

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,15 @@ public function __construct(
4747
*
4848
* @param ButtonSearchContext|null $buttonSearchContext
4949
*
50-
* @return string
50+
* @return string|null
5151
*/
52-
public function getOriginalUrl(ButtonSearchContext $buttonSearchContext = null)
52+
public function getOriginalUrl(ButtonSearchContext $buttonSearchContext = null): ?string
5353
{
5454
$originalUrl = $this->getMasterRequestUri();
55+
if (null === $originalUrl) {
56+
return null;
57+
}
58+
5559
if (null === $buttonSearchContext) {
5660
return $originalUrl;
5761
}
@@ -70,10 +74,23 @@ public function getOriginalUrl(ButtonSearchContext $buttonSearchContext = null)
7074
}
7175

7276
/**
73-
* @return string
77+
* @return string|null
7478
*/
75-
private function getMasterRequestUri()
79+
private function getMasterRequestUri(): ?string
7680
{
77-
return $this->requestStack->getMasterRequest()->getRequestUri();
81+
$request = $this->requestStack->getMasterRequest();
82+
83+
/**
84+
* Based on the "requestStack" contract "MasterRequest" could be "null". it could happens in case
85+
* if this service is called during the console command work.
86+
*
87+
* Example of such case is the building of the MarketingList datasource, where datagrid used as a source of
88+
* the data.
89+
*/
90+
if (!$request) {
91+
return null;
92+
}
93+
94+
return $request->getRequestUri();
7895
}
7996
}

src/Oro/Bundle/ActionBundle/Tests/Unit/Provider/OriginalUrlProviderTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ public function testGetOriginalUrl()
4545
$this->assertEquals('example.com', $this->urlProvider->getOriginalUrl());
4646
}
4747

48+
public function testGetOriginalUrlReturnNullIfRequestIsNotDefined()
49+
{
50+
$this->assertNull($this->urlProvider->getOriginalUrl());
51+
}
52+
4853
public function testGetOriginalUrlWhenDatagridIsSet()
4954
{
5055
$datagridName = 'quotes-grid';

src/Oro/Bundle/QueryDesignerBundle/QueryDesigner/AbstractQueryConverter.php

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,7 +1333,11 @@ protected function registerVirtualColumnQueryAliases($query, $mainEntityJoinId)
13331333
}
13341334
$joinType = $mapItem['type'];
13351335
$join = $query['join'][$joinType][$mapItem['key']];
1336-
$parentJoinId = $this->getParentJoinIdForVirtualColumnJoin($join['join'], $mainEntityJoinId);
1336+
$parentJoinId = $this->getParentJoinIdForVirtualColumn(
1337+
$joinMap,
1338+
$join['join'],
1339+
$mainEntityJoinId
1340+
);
13371341
if (null !== $parentJoinId) {
13381342
$alias = $join['alias'];
13391343
$joinId = $this->buildJoinIdentifier($join, $parentJoinId, $joinType);
@@ -1348,7 +1352,8 @@ protected function registerVirtualColumnQueryAliases($query, $mainEntityJoinId)
13481352
if (!isset($mapItem['processed'])) {
13491353
$joinType = $mapItem['type'];
13501354
$join = $query['join'][$joinType][$mapItem['key']];
1351-
$parentJoinId = $this->getParentJoinIdForVirtualColumnJoin(
1355+
$parentJoinId = $this->getParentJoinIdForVirtualColumn(
1356+
$joinMap,
13521357
$join['join'],
13531358
$mainEntityJoinId
13541359
);
@@ -1374,6 +1379,32 @@ protected function registerVirtualColumnQueryAliases($query, $mainEntityJoinId)
13741379
['processed' => true, 'joinId' => $joinId]
13751380
);
13761381
unset($joinMap[$alias]);
1382+
1383+
/**
1384+
* It is required to update parentAliases in the map with the new alias,
1385+
* because there could be a case when one of the joins use another one and in this case
1386+
* second join alias will start to be invalid after replacement.
1387+
*
1388+
* Example of such virtual field con figuration:
1389+
* select:
1390+
* expr: defaultContactEmails.email
1391+
* return_type: string
1392+
* join:
1393+
* left:
1394+
* - { join: entity.defaultContact, alias: defaultContact }
1395+
* - {
1396+
* join: defaultContact.emails,
1397+
* alias: defaultContactEmails,
1398+
* conditionType: 'WITH',
1399+
* condition: 'defaultContactEmails.primary = true'
1400+
* }
1401+
* Example of $joinMap value for this configuration of the virtual field above:
1402+
* [
1403+
* '__tmp1__' => ['['type'=> left, 'key' => 0, 'parentAlias' => t1],
1404+
* '__tmp2__' => ['['type'=> left, 'key' => 1, 'parentAlias' => __tmp1__],
1405+
* ]
1406+
*/
1407+
$joinMap = $this->replaceParentAliasInJoinMapItems($joinMap, $alias, $newAlias);
13771408
}
13781409
}
13791410
}
@@ -1402,6 +1433,36 @@ protected function findExistingTableAlias($virtualColumnJoinId, $virtualColumnJo
14021433
return $foundAlias;
14031434
}
14041435

1436+
/**
1437+
* Method added to avoid problem with backward compatibility and will be removed in the next release.
1438+
* Instead signature of the method:
1439+
* @see \Oro\Bundle\QueryDesignerBundle\QueryDesigner\AbstractQueryConverter::getParentJoinIdForVirtualColumnJoin
1440+
* will be changed to fix a bug: $joinMap parameter was not passed to the function but it is used in it to get
1441+
* correct parent join id from the already processed joins
1442+
*
1443+
* @param array $joinMap
1444+
* @param string $joinExpr
1445+
* @param string $mainEntityJoinId
1446+
*
1447+
* @return string|null
1448+
*/
1449+
private function getParentJoinIdForVirtualColumn($joinMap, $joinExpr, $mainEntityJoinId)
1450+
{
1451+
$parentJoinId = $this->getParentJoinIdForVirtualColumnJoin($joinExpr, $mainEntityJoinId);
1452+
if (!$parentJoinId) {
1453+
$parts = explode('.', $joinExpr, 2);
1454+
1455+
$parentAlias = count($parts) === 2
1456+
? $parts[0]
1457+
: null;
1458+
if (isset($joinMap[$parentAlias]['processed'])) {
1459+
$parentJoinId = $joinMap[$parentAlias]['joinId'];
1460+
}
1461+
}
1462+
1463+
return $parentJoinId;
1464+
}
1465+
14051466
/**
14061467
* @param string $joinExpr
14071468
* @param string $mainEntityJoinId
@@ -1494,6 +1555,24 @@ protected function replaceTableAliasesInVirtualColumnQuery(&$query, $aliases)
14941555
$query['select']['expr'] = QueryUtils::replaceTableAliasesInSelectExpr($query['select']['expr'], $aliases);
14951556
}
14961557

1558+
/**
1559+
* Actualize parent alias
1560+
*
1561+
* @param array $joinMap
1562+
* @param string $from
1563+
* @param string $to
1564+
*/
1565+
private function replaceParentAliasInJoinMapItems(array $joinMap, string $from, string $to): array
1566+
{
1567+
foreach ($joinMap as &$mapItem) {
1568+
if (isset($mapItem['parentAlias']) && $mapItem['parentAlias'] === $from) {
1569+
$mapItem['parentAlias'] = $to;
1570+
}
1571+
}
1572+
1573+
return $joinMap;
1574+
}
1575+
14971576
/**
14981577
* Replaces all table aliases declared in the virtual column query with unique aliases for built query
14991578
*

0 commit comments

Comments
 (0)