8
8
use Magento \Framework \Mview \View \AdditionalColumnsProcessor \DefaultProcessor ;
9
9
use Magento \Framework \Mview \View \ChangelogBatchWalker ;
10
10
use Magento \Framework \Mview \View \SubscriptionInterface ;
11
+ use Magento \Framework \App \ResourceConnection ;
11
12
12
13
class Converter implements \Magento \Framework \Config \ConverterInterface
13
14
{
@@ -22,13 +23,21 @@ class Converter implements \Magento\Framework\Config\ConverterInterface
22
23
private $ defaultIterator ;
23
24
24
25
/**
26
+ * @var ResourceConnection
27
+ */
28
+ private $ resourceConnection ;
29
+
30
+ /**
31
+ * @param ResourceConnection $resourceConnection
25
32
* @param string $defaultProcessor
26
33
* @param string $defaultIterator
27
34
*/
28
35
public function __construct (
36
+ ResourceConnection $ resourceConnection ,
29
37
string $ defaultProcessor = DefaultProcessor::class,
30
38
string $ defaultIterator = ChangelogBatchWalker::class
31
39
) {
40
+ $ this ->resourceConnection = $ resourceConnection ;
32
41
$ this ->defaultProcessor = $ defaultProcessor ;
33
42
$ this ->defaultIterator = $ defaultIterator ;
34
43
}
@@ -99,7 +108,15 @@ protected function convertChild(\DOMNode $childNode, $data)
99
108
continue ;
100
109
}
101
110
$ 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
+
103
120
$ subscriptionModel = $ this ->getAttributeValue ($ subscription , 'subscription_model ' );
104
121
105
122
if (!empty ($ subscriptionModel )
@@ -155,4 +172,23 @@ private function getAdditionalColumns(\DOMNode $subscription): array
155
172
156
173
return $ additionalColumns ;
157
174
}
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
+ }
158
194
}
0 commit comments