Batch operations

Now that we have our batch definition in place, we are missing those three callback methods we are referencing in it. So, let's see the first one:

/** * Batch operation to remove the products which are no longer in the list of * products coming from the JSON file. * * @param $products * @param $context */ public function clearMissing($products, &$context) { if (!isset($context['results']['cleared'])) { $context['results']['cleared'] = []; } if (!$products) { return; } $ids = []; foreach ($products as $product) { $ids[] = $product->id; } $ids = $this->entityTypeManager->getStorage('product')->getQuery() ->condition('remote_id', $ids, 'NOT IN') ->execute(); if (!$ids) { $context['results']['cleared'] = []; return; } $entities ...

Get Drupal 8 Module Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.