Skip to content

Commit 3a6478e

Browse files
Merge branch 'AC-13182' into AC-13289-latest
2 parents 9959b49 + 1ef7e6f commit 3a6478e

File tree

2 files changed

+56
-4
lines changed

2 files changed

+56
-4
lines changed

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

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Magento\Framework\Mview\View\AdditionalColumnsProcessor\DefaultProcessor;
99
use Magento\Framework\Mview\View\ChangelogBatchWalker;
1010
use Magento\Framework\Mview\View\SubscriptionInterface;
11+
use Magento\Framework\App\ResourceConnection;
1112

1213
class Converter implements \Magento\Framework\Config\ConverterInterface
1314
{
@@ -22,13 +23,21 @@ class Converter implements \Magento\Framework\Config\ConverterInterface
2223
private $defaultIterator;
2324

2425
/**
26+
* @var ResourceConnection
27+
*/
28+
private $resourceConnection;
29+
30+
/**
31+
* @param ResourceConnection $resourceConnection
2532
* @param string $defaultProcessor
2633
* @param string $defaultIterator
2734
*/
2835
public function __construct(
36+
ResourceConnection $resourceConnection,
2937
string $defaultProcessor = DefaultProcessor::class,
3038
string $defaultIterator = ChangelogBatchWalker::class
3139
) {
40+
$this->resourceConnection = $resourceConnection;
3241
$this->defaultProcessor = $defaultProcessor;
3342
$this->defaultIterator = $defaultIterator;
3443
}
@@ -99,7 +108,15 @@ protected function convertChild(\DOMNode $childNode, $data)
99108
continue;
100109
}
101110
$name = $this->getAttributeValue($subscription, 'name');
102-
$column = $this->getAttributeValue($subscription, 'entity_column');
111+
$configColumn = $this->getAttributeValue($subscription, 'entity_column');
112+
$column = $this->checkifcolumnexist($name, $configColumn);
113+
114+
if (empty($column)) {
115+
throw new \InvalidArgumentException(
116+
'Column ' . $configColumn . ' does not exist in table ' . $name
117+
);
118+
}
119+
103120
$subscriptionModel = $this->getAttributeValue($subscription, 'subscription_model');
104121

105122
if (!empty($subscriptionModel)
@@ -155,4 +172,23 @@ private function getAdditionalColumns(\DOMNode $subscription): array
155172

156173
return $additionalColumns;
157174
}
175+
176+
/**
177+
* Check if column exists in table, otherwise return primary key column
178+
*
179+
* @param string $tableName
180+
* @param string $columnName
181+
* @return string
182+
*/
183+
public function checkifcolumnexist($tableName, $columnName) : string
184+
{
185+
$connection = $this->resourceConnection->getConnection();
186+
$tableName = $this->resourceConnection->getTableName($tableName);
187+
188+
if (!$connection->isTableExists($tableName) || $connection->tableColumnExists($tableName, $columnName)) {
189+
return $columnName;
190+
}
191+
192+
return '';
193+
}
158194
}

lib/internal/Magento/Framework/Mview/Test/Unit/Config/ConverterTest.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2015 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

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

10+
use Magento\Framework\App\ResourceConnection;
11+
use Magento\Framework\DB\Adapter\AdapterInterface;
1012
use Magento\Framework\Mview\Config\Converter;
1113
use PHPUnit\Framework\MockObject\MockObject;
1214
use PHPUnit\Framework\TestCase;
@@ -18,13 +20,27 @@ class ConverterTest extends TestCase
1820
*/
1921
protected $_model;
2022

23+
/**
24+
* @var ResourceConnection|MockObject
25+
*/
26+
protected $resourceConnectionMock;
27+
28+
/**
29+
* @var \Magento\Framework\DB\Adapter\AdapterInterface|MockObject
30+
*/
31+
protected $connectionMock;
32+
2133
protected function setUp(): void
2234
{
23-
$this->_model = new Converter();
35+
$this->connectionMock = $this->createMock(AdapterInterface::class);
36+
$this->resourceConnectionMock = $this->createMock(ResourceConnection::class);
37+
$this->_model = new Converter($this->resourceConnectionMock);
2438
}
2539

2640
public function testConvert()
2741
{
42+
$this->resourceConnectionMock->method('getConnection')
43+
->willReturn($this->connectionMock);
2844
$data = include __DIR__ . '/../_files/mview_config.php';
2945
$dom = new \DOMDocument();
3046
$dom->loadXML($data['inputXML']);

0 commit comments

Comments
 (0)