if (empty($promotions)) { return;
} $update =
new RetryableQuery( $this->connection,
$this->connection->
prepare('UPDATE promotion SET order_count = :count, orders_per_customer_count = :customerCount WHERE id = :id'
) );
// group the promotions to update each promotion with a single update statement
$promotions =
$this->
groupByPromotion($promotions);
foreach ($promotions as $id =>
$totals) { $total =
array_sum($totals);
$update->
execute([ 'id' => Uuid::
fromHexToBytes($id),
'count' =>
(int) $total,
'customerCount' =>
json_encode($totals, \JSON_THROW_ON_ERROR
),
]);
} }