foreach ($wrongVersionedDocuments as $wrongVersionedDocument) { /** get the order version which was created nearest before the document creation */
$orders =
$this->
getOrders( $connection,
$wrongVersionedDocument['order_id'
],
$wrongVersionedDocument['created_at'
] );
if (\
is_array($orders) && \
count($orders) === 1
) { /* Update the document version with the version of the order */
$this->
updateDocument($connection,
$orders[0
]['version_id'
],
$wrongVersionedDocument['id'
]);
} else { /** if no order prior to the document creation was found, get last version of order */
$orders =
$this->
getOrders( $connection,
$wrongVersionedDocument['order_id'
] );
if (\
is_array($orders) && \
count($orders) === 1
) { /* Update the document version with the version of the order */
$this->
updateDocument($connection,
$orders[0
]['version_id'
],
$wrongVersionedDocument['id'
]);
} }