Skip to content

Commit 1f3998d

Browse files
committed
MAGETWO-64802: Implement corrupted data reporting for fieldDataConverter
1 parent da1a383 commit 1f3998d

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

lib/internal/Magento/Framework/DB/FieldDataConverter.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ public function convert(
7878
foreach ($iterator as $selectByRange) {
7979
$rows = $connection->fetchAll($selectByRange);
8080
foreach ($rows as $row) {
81+
if ($this->isValidJsonValue($row[$field])) {
82+
// skip valid JSON values (for data rows that have been already converter)
83+
continue;
84+
}
8185
try {
8286
$bind = [$field => $this->dataConverter->convert($row[$field])];
8387
$where = [$identifier . ' = ?' => (int) $row[$identifier]];
@@ -102,4 +106,20 @@ public function convert(
102106
}
103107
}
104108
}
109+
110+
/**
111+
* Is a valid JSON serialized value
112+
*
113+
* @param string $value
114+
* @return bool
115+
*/
116+
private function isValidJsonValue($value)
117+
{
118+
if (in_array($value, ['null', 'false', '0', '""', '[]'])
119+
|| (json_decode($value) !== null && !json_last_error())
120+
) {
121+
return true;
122+
}
123+
return false;
124+
}
105125
}

0 commit comments

Comments
 (0)