function commerce_promotion_post_update_8 in Commerce Core 8.2
Re-save promotions to populate the condition operator field.
File
- modules/
promotion/ commerce_promotion.post_update.php, line 201 - Post update functions for Promotion.
Code
function commerce_promotion_post_update_8(&$sandbox = NULL) {
$promotion_storage = \Drupal::entityTypeManager()
->getStorage('commerce_promotion');
if (!isset($sandbox['current_count'])) {
$query = $promotion_storage
->getQuery();
$sandbox['total_count'] = $query
->count()
->execute();
$sandbox['current_count'] = 0;
if (empty($sandbox['total_count'])) {
$sandbox['#finished'] = 1;
return;
}
}
$query = $promotion_storage
->getQuery();
$query
->range($sandbox['current_count'], 25);
$result = $query
->execute();
if (empty($result)) {
$sandbox['#finished'] = 1;
return;
}
/** @var \Drupal\commerce_promotion\Entity\PromotionInterface[] $promotions */
$promotions = $promotion_storage
->loadMultiple($result);
foreach ($promotions as $promotion) {
$promotion
->setConditionOperator('AND');
$promotion
->save();
}
$sandbox['current_count'] += 25;
if ($sandbox['current_count'] >= $sandbox['total_count']) {
$sandbox['#finished'] = 1;
}
else {
$sandbox['#finished'] = ($sandbox['total_count'] - $sandbox['current_count']) / $sandbox['total_count'];
}
}