Skip to content

Commit 95d457d

Browse files
committed
Merge branch 'ACP2E-1458' of https://github.com/magento-l3/magento2ce into PR-2023-02-24
2 parents acb8ed5 + b518b4e commit 95d457d

File tree

6 files changed

+87
-4
lines changed

6 files changed

+87
-4
lines changed

app/code/Magento/Indexer/etc/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
<type name="Magento\Framework\Mview\View\Subscription">
3838
<arguments>
3939
<argument name="viewCollection" xsi:type="object" shared="false">Magento\Framework\Mview\View\CollectionInterface</argument>
40+
<argument name="ignoredUpdateColumns" xsi:type="array">
41+
<item name="updated_at" xsi:type="string">updated_at</item>
42+
</argument>
4043
</arguments>
4144
</type>
4245
<type name="Magento\Indexer\Model\Processor">

app/etc/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@
212212
<preference for="Magento\Framework\HTTP\ClientInterface" type="Magento\Framework\HTTP\Client\Curl" />
213213
<preference for="Magento\Framework\Interception\ConfigLoaderInterface" type="Magento\Framework\Interception\PluginListGenerator" />
214214
<preference for="Magento\Framework\Interception\ConfigWriterInterface" type="Magento\Framework\Interception\PluginListGenerator" />
215+
<preference for="Magento\Framework\Mview\View\SubscriptionStatementPostprocessorInterface" type="Magento\Framework\Mview\View\CompositeSubscriptionStatementPostprocessor" />
215216
<type name="Magento\Framework\Model\ResourceModel\Db\TransactionManager" shared="false" />
216217
<type name="Magento\Framework\Acl\Data\Cache">
217218
<arguments>

lib/internal/Magento/Framework/Mview/Test/Unit/View/SubscriptionTest.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Magento\Framework\Mview\View\CollectionInterface;
1919
use Magento\Framework\Mview\View\StateInterface;
2020
use Magento\Framework\Mview\View\Subscription;
21+
use Magento\Framework\Mview\View\SubscriptionStatementPostprocessorInterface;
2122
use Magento\Framework\Mview\ViewInterface;
2223
use PHPUnit\Framework\MockObject\MockObject;
2324
use PHPUnit\Framework\TestCase;
@@ -127,6 +128,9 @@ protected function setUp(): void
127128
]
128129
]
129130
]);
131+
$statementPostprocessorMock = $this->createMock(SubscriptionStatementPostprocessorInterface::class);
132+
$statementPostprocessorMock->method('process')
133+
->willReturnArgument(2);
130134
$this->model = new Subscription(
131135
$this->resourceMock,
132136
$this->triggerFactoryMock,
@@ -136,7 +140,8 @@ protected function setUp(): void
136140
'columnName',
137141
[],
138142
[],
139-
$mviewConfigMock
143+
$mviewConfigMock,
144+
$statementPostprocessorMock
140145
);
141146
}
142147

@@ -417,6 +422,9 @@ public function testBuildStatementIgnoredColumnSubscriptionLevel(): void
417422
]
418423
]
419424
]);
425+
$statementPostprocessorMock = $this->createMock(SubscriptionStatementPostprocessorInterface::class);
426+
$statementPostprocessorMock->method('process')
427+
->willReturnArgument(2);
420428

421429
$this->connectionMock->expects($this->any())
422430
->method('isTableExists')
@@ -464,7 +472,8 @@ public function testBuildStatementIgnoredColumnSubscriptionLevel(): void
464472
'columnName',
465473
[],
466474
$ignoredData,
467-
$mviewConfigMock
475+
$mviewConfigMock,
476+
$statementPostprocessorMock
468477
);
469478

470479
$method = new ReflectionMethod($model, 'buildStatement');
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Framework\Mview\View;
9+
10+
class CompositeSubscriptionStatementPostprocessor implements SubscriptionStatementPostprocessorInterface
11+
{
12+
/**
13+
* @var SubscriptionStatementPostprocessorInterface[]
14+
*/
15+
private $postprocessors;
16+
17+
/**
18+
* @param SubscriptionStatementPostprocessorInterface[] $postprocessors
19+
*/
20+
public function __construct(array $postprocessors = [])
21+
{
22+
$this->postprocessors = $postprocessors;
23+
}
24+
25+
/**
26+
* @inheritdoc
27+
*/
28+
public function process(string $tableName, string $event, string $statement): string
29+
{
30+
foreach ($this->postprocessors as $postprocessor) {
31+
$statement = $postprocessor->process($tableName, $event, $statement);
32+
}
33+
34+
return $statement;
35+
}
36+
}

lib/internal/Magento/Framework/Mview/View/Subscription.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ class Subscription implements SubscriptionInterface, SubscriptionTriggersInterfa
8787
*/
8888
private $mviewConfig;
8989

90+
/**
91+
* @var SubscriptionStatementPostprocessorInterface
92+
*/
93+
private $statementPostprocessor;
94+
9095
/**
9196
* @var Trigger[]
9297
*/
@@ -102,6 +107,8 @@ class Subscription implements SubscriptionInterface, SubscriptionTriggersInterfa
102107
* @param array $ignoredUpdateColumns
103108
* @param array $ignoredUpdateColumnsBySubscription
104109
* @param Config|null $mviewConfig
110+
* @param SubscriptionStatementPostprocessorInterface|null $statementPostprocessor
111+
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
105112
*/
106113
public function __construct(
107114
ResourceConnection $resource,
@@ -112,7 +119,8 @@ public function __construct(
112119
$columnName,
113120
$ignoredUpdateColumns = [],
114121
$ignoredUpdateColumnsBySubscription = [],
115-
Config $mviewConfig = null
122+
?Config $mviewConfig = null,
123+
?SubscriptionStatementPostprocessorInterface $statementPostprocessor = null
116124
) {
117125
$this->connection = $resource->getConnection();
118126
$this->triggerFactory = $triggerFactory;
@@ -124,6 +132,8 @@ public function __construct(
124132
$this->ignoredUpdateColumns = $ignoredUpdateColumns;
125133
$this->ignoredUpdateColumnsBySubscription = $ignoredUpdateColumnsBySubscription;
126134
$this->mviewConfig = $mviewConfig ?? ObjectManager::getInstance()->get(Config::class);
135+
$this->statementPostprocessor = $statementPostprocessor
136+
?? ObjectManager::getInstance()->get(SubscriptionStatementPostprocessorInterface::class);
127137
}
128138

129139
/**
@@ -324,13 +334,16 @@ protected function buildStatement(string $event, ViewInterface $view): string
324334
}
325335
$columns = $this->prepareColumns($view, $event);
326336

327-
return sprintf(
337+
$statement = sprintf(
328338
$trigger,
329339
$this->getProcessor()->getPreStatements(),
330340
$this->connection->quoteIdentifier($this->resource->getTableName($changelog->getName())),
331341
implode(', ', $columns['column_names']),
332342
implode(', ', $columns['column_values'])
333343
);
344+
$statement = $this->statementPostprocessor->process($this->getTableName(), $event, $statement);
345+
346+
return $statement;
334347
}
335348

336349
/**
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Framework\Mview\View;
9+
10+
interface SubscriptionStatementPostprocessorInterface
11+
{
12+
/**
13+
* Postprocess subscription statement.
14+
*
15+
* @param string $tableName
16+
* @param string $event
17+
* @param string $statement
18+
* @return string
19+
*/
20+
public function process(string $tableName, string $event, string $statement): string;
21+
}

0 commit comments

Comments
 (0)