Skip to content

Commit 9913305

Browse files
committed
Mview patch update
-- move framework logic to saas-export
1 parent 7237a30 commit 9913305

File tree

6 files changed

+60
-32
lines changed

6 files changed

+60
-32
lines changed

lib/internal/Magento/Framework/Mview/Config/Converter.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ public function convert($source)
5252
$data['view_id'] = $viewId;
5353
$data['action_class'] = $this->getAttributeValue($viewNode, 'class');
5454
$data['group'] = $this->getAttributeValue($viewNode, 'group');
55-
$data['store_scope'] = $this->getAttributeValue($viewNode, 'store_scope');
5655
$data['iterator'] = $this->getAttributeValue($viewNode, 'iterator') ?: $this->defaultIterator;
5756
$data['subscriptions'] = [];
5857

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ private function getMviewConfigMock()
5959
$mviewConfigMock->expects($this->any())
6060
->method('getView')
6161
->willReturn([
62-
'attribute_scope' => false,
63-
'store_scope' => false
62+
'subscriptions' => []
6463
]);
6564
return $mviewConfigMock;
6665
}

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77

88
namespace Magento\Framework\Mview\Test\Unit\View;
99

10+
use Magento\Framework\App\ObjectManager;
1011
use Magento\Framework\App\ResourceConnection;
1112
use Magento\Framework\DB\Adapter\Pdo\Mysql;
1213
use Magento\Framework\DB\Ddl\Trigger;
1314
use Magento\Framework\DB\Ddl\TriggerFactory;
1415
use Magento\Framework\Mview\Config;
16+
use Magento\Framework\Mview\View\AdditionalColumnsProcessor\DefaultProcessor;
1517
use Magento\Framework\Mview\View\ChangelogInterface;
1618
use Magento\Framework\Mview\View\CollectionInterface;
1719
use Magento\Framework\Mview\View\StateInterface;
@@ -49,6 +51,7 @@ class SubscriptionTest extends TestCase
4951

5052
protected function setUp(): void
5153
{
54+
$this->tableName = 'test_table';
5255
$this->connectionMock = $this->createMock(Mysql::class);
5356
$this->resourceMock = $this->createMock(ResourceConnection::class);
5457

@@ -63,7 +66,10 @@ protected function setUp(): void
6366
$this->resourceMock->expects($this->atLeastOnce())
6467
->method('getConnection')
6568
->willReturn($this->connectionMock);
66-
69+
ObjectManager::getInstance()->expects($this->any())
70+
->method('get')
71+
->with(DefaultProcessor::class)
72+
->willReturn(2);
6773
$this->triggerFactoryMock = $this->createMock(TriggerFactory::class);
6874
$this->viewCollectionMock = $this->getMockForAbstractClass(
6975
CollectionInterface::class,
@@ -93,8 +99,11 @@ protected function setUp(): void
9399
$mviewConfigMock->expects($this->any())
94100
->method('getView')
95101
->willReturn([
96-
'attribute_scope' => false,
97-
'store_scope' => false
102+
'subscriptions' => [
103+
$this->tableName => [
104+
'processor' => DefaultProcessor::class
105+
]
106+
]
98107
]);
99108
$this->mviewConfig = $mviewConfigMock;
100109
$this->model = new Subscription(

lib/internal/Magento/Framework/Mview/Test/Unit/ViewTest.php

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\Framework\Mview\Test\Unit;
99

10+
use Laminas\Log\Filter\Mock;
1011
use Magento\Framework\Mview\ActionFactory;
1112
use Magento\Framework\Mview\ActionInterface;
1213
use Magento\Framework\Mview\ConfigInterface;
@@ -53,6 +54,11 @@ class ViewTest extends TestCase
5354
*/
5455
protected $subscriptionFactoryMock;
5556

57+
/**
58+
* @var MockObject|View\ChangeLogBatchIteratorInterface
59+
*/
60+
private $iteratorMock;
61+
5662
/**
5763
* @inheritdoc
5864
*/
@@ -67,6 +73,7 @@ protected function setUp(): void
6773
true,
6874
['getView']
6975
);
76+
$this->iteratorMock = $this->createMock(View\ChangeLogBatchIteratorInterface::class);
7077
$this->actionFactoryMock = $this->createPartialMock(ActionFactory::class, ['get']);
7178
$this->stateMock = $this->createPartialMock(
7279
State::class,
@@ -97,7 +104,10 @@ protected function setUp(): void
97104
$this->actionFactoryMock,
98105
$this->stateMock,
99106
$this->changelogMock,
100-
$this->subscriptionFactoryMock
107+
$this->subscriptionFactoryMock,
108+
[],
109+
[],
110+
$this->iteratorMock
101111
);
102112
}
103113

@@ -334,7 +344,7 @@ public function testUpdate()
334344
$currentVersionId
335345
);
336346
$this->changelogMock->expects(
337-
$this->once()
347+
$this->any()
338348
)->method(
339349
'getList'
340350
)->with(
@@ -345,6 +355,7 @@ public function testUpdate()
345355
);
346356

347357
$actionMock = $this->getMockForAbstractClass(ActionInterface::class);
358+
$this->iteratorMock->expects($this->once())->method('walk')->willReturn($listId);
348359
$actionMock->expects($this->once())->method('execute')->with($listId)->willReturnSelf();
349360
$this->actionFactoryMock->expects(
350361
$this->once()
@@ -390,7 +401,7 @@ public function testUpdateEx(): void
390401
->expects($this->once())
391402
->method('getVersion')
392403
->willReturn($currentVersionId);
393-
404+
$this->iteratorMock->expects($this->any())->method('walk')->willReturn($this->generateChangeLog(150, 1, 150));
394405
$this->changelogMock->method('getList')
395406
->willReturnMap(
396407
[
@@ -401,7 +412,7 @@ public function testUpdateEx(): void
401412
);
402413

403414
$actionMock = $this->getMockForAbstractClass(ActionInterface::class);
404-
$actionMock->expects($this->once())
415+
$actionMock->expects($this->any())
405416
->method('execute')
406417
->with($this->generateChangeLog(150, 1, 150))
407418
->willReturnSelf();
@@ -457,7 +468,7 @@ public function testUpdateWithException()
457468
$this->stateMock->expects($this->atLeastOnce())
458469
->method('getMode')
459470
->willReturn(StateInterface::MODE_ENABLED);
460-
$this->stateMock->expects($this->exactly(2))
471+
$this->stateMock->expects($this->any())
461472
->method('getStatus')
462473
->willReturn(StateInterface::STATUS_IDLE);
463474
$this->stateMock->expects($this->exactly(2))
@@ -472,16 +483,9 @@ public function testUpdateWithException()
472483
)->willReturn(
473484
$currentVersionId
474485
);
475-
$this->changelogMock->expects(
476-
$this->once()
477-
)->method(
478-
'getList'
479-
)->with(
480-
$lastVersionId,
481-
$currentVersionId
482-
)->willReturn(
483-
$listId
484-
);
486+
$this->iteratorMock->expects($this->any())
487+
->method('walk')
488+
->willReturn([2,3]);
485489

486490
$actionMock = $this->createPartialMock(ActionInterface::class, ['execute']);
487491
$actionMock->expects($this->once())->method('execute')->with($listId)->willReturnCallback(
@@ -767,8 +771,11 @@ public function testGetUpdated()
767771
protected function loadView()
768772
{
769773
$viewId = 'view_test';
774+
$this->changelogMock->expects($this->any())
775+
->method('getViewId')
776+
->willReturn($viewId);
770777
$this->configMock->expects(
771-
$this->once()
778+
$this->any()
772779
)->method(
773780
'getView'
774781
)->with(
@@ -788,7 +795,7 @@ protected function getViewData()
788795
'view_id' => 'view_test',
789796
'action_class' => 'Some\Class\Name',
790797
'group' => 'some_group',
791-
'subscriptions' => ['some_entity' => ['name' => 'some_entity', 'column' => 'entity_id']]
798+
'subscriptions' => ['some_entity' => ['name' => 'some_entity', 'column' => 'entity_id']],
792799
];
793800
}
794801
}

lib/internal/Magento/Framework/Mview/Test/Unit/_files/mview_config.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,19 @@
2020
'some_entity' => [
2121
'name' => 'some_entity',
2222
'column' => 'entity_id',
23-
'subscription_model' => null
23+
'subscription_model' => null,
24+
'additional_columns' => [],
25+
'processor' => \Magento\Framework\Mview\View\AdditionalColumnsProcessor\DefaultProcessor::class
2426
],
2527
'some_product_relation' => [
2628
'name' => 'some_product_relation',
2729
'column' => 'product_id',
28-
'subscription_model' => null
30+
'subscription_model' => null,
31+
'additional_columns' => [],
32+
'processor' => \Magento\Framework\Mview\View\AdditionalColumnsProcessor\DefaultProcessor::class
2933
],
3034
],
35+
'iterator' => \Magento\Framework\Mview\View\ChangeLogBatchIterator::class
3136
],
3237
]
3338
];

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

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use InvalidArgumentException;
1212
use Magento\Framework\App\ObjectManager;
1313
use Magento\Framework\DataObject;
14+
use Magento\Framework\Mview\View\ChangeLogBatchIterator;
1415
use Magento\Framework\Mview\View\ChangeLogBatchIteratorInterface;
1516
use Magento\Framework\Mview\View\ChangelogTableNotExistsException;
1617
use Magento\Framework\Mview\View\SubscriptionFactory;
@@ -65,9 +66,9 @@ class View extends DataObject implements ViewInterface
6566
private $changelogBatchSize;
6667

6768
/**
68-
* @var ChangeLogBatchIteratorInterface[]
69+
* @var ChangeLogBatchIteratorInterface
6970
*/
70-
private $strategies;
71+
private $iterator;
7172

7273
/**
7374
* @param ConfigInterface $config
@@ -77,7 +78,7 @@ class View extends DataObject implements ViewInterface
7778
* @param SubscriptionFactory $subscriptionFactory
7879
* @param array $data
7980
* @param array $changelogBatchSize
80-
* @param array $strategies
81+
* @param ChangeLogBatchIteratorInterface|null $changeLogBatchIterator
8182
*/
8283
public function __construct(
8384
ConfigInterface $config,
@@ -87,7 +88,7 @@ public function __construct(
8788
SubscriptionFactory $subscriptionFactory,
8889
array $data = [],
8990
array $changelogBatchSize = [],
90-
array $strategies = []
91+
ChangeLogBatchIteratorInterface $changeLogBatchIterator = null
9192
) {
9293
$this->config = $config;
9394
$this->actionFactory = $actionFactory;
@@ -96,7 +97,7 @@ public function __construct(
9697
$this->subscriptionFactory = $subscriptionFactory;
9798
$this->changelogBatchSize = $changelogBatchSize;
9899
parent::__construct($data);
99-
$this->strategies = $strategies;
100+
$this->iterator = $changeLogBatchIterator;
100101
}
101102

102103
/**
@@ -302,8 +303,12 @@ private function executeAction(ActionInterface $action, int $lastVersionId, int
302303

303304
$vsFrom = $lastVersionId;
304305
while ($vsFrom < $currentVersionId) {
305-
$iterator = $this->createIterator();
306+
$iterator = $this->getIterator();
306307
$ids = $iterator->walk($this->getChangelog(), $vsFrom, $currentVersionId, $batchSize);
308+
309+
if (empty($ids)) {
310+
break;
311+
}
307312
$vsFrom += $batchSize;
308313
$action->execute($ids);
309314
}
@@ -315,8 +320,12 @@ private function executeAction(ActionInterface $action, int $lastVersionId, int
315320
* @return ChangeLogBatchIteratorInterface|mixed
316321
* @throws Exception
317322
*/
318-
private function createIterator()
323+
private function getIterator()
319324
{
325+
if ($this->iterator) {
326+
return $this->iterator;
327+
}
328+
320329
$config = $this->config->getView($this->changelog->getViewId());
321330
$iteratorClass = $config['iterator'];
322331

0 commit comments

Comments
 (0)