Skip to content

Commit 9885c79

Browse files
authored
Adding a check to verify the index key is found in the row keys and throwing exception when not. Moving costly function call outside loop. (#227)
Adding Check in QueryDataProvider to verify no data mismatch between record received and query configuration, explicitly throwing exception when there's a discrepancy. Moving costly function call outside of the loops.
1 parent 84dd607 commit 9885c79

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

DataExporter/Model/Provider/QueryDataProvider.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\DataExporter\Model\Provider;
99

10+
use Magento\DataExporter\Exception\UnableSendData;
1011
use Magento\DataExporter\Export\Request\Node;
1112
use Magento\DataExporter\Export\Request\Info;
1213
use Magento\QueryXml\Model\QueryProcessor;
@@ -165,9 +166,19 @@ public function get(array $values, Node $node, Info $info): array
165166
if (!$isRoot) {
166167
$result = [];
167168
$cursor = $this->queryProcessor->execute($queryName, $arguments);
169+
$nodeIndexFields = $this->getNodeIndexFields($node);
168170
while ($row = $cursor->fetch()) {
169171
$index = [];
170-
foreach ($this->getNodeIndexFields($node) as $indexField) {
172+
foreach ($nodeIndexFields as $indexField) {
173+
if(!isset($row[$indexField])) {
174+
$errormsg = __(
175+
'Data mismatch in query "%1", expected indexField: "%2". row: "%3". Verify query.xml configuration and clean data cache.',
176+
$queryName,
177+
$indexField,
178+
var_export($row, true)
179+
);
180+
throw new UnableSendData($errormsg);
181+
}
171182
$index[$indexField] = $row[$indexField];
172183
}
173184
$result[] = array_merge($index, [$field['name'] => $row]);

0 commit comments

Comments
 (0)