You are here

public static function RefreshBatch::process in Media Thumbnails 8

Batch process callback.

File

src/Batch/RefreshBatch.php, line 60

Class

RefreshBatch
Class RefreshBatch.

Namespace

Drupal\media_thumbnails\Batch

Code

public static function process($ids, &$context) {
  if (!isset($context['results']['processed'])) {
    $context['results']['processed'] = 0;
    $context['results']['updated'] = 0;
    $context['sandbox']['count'] = self::count();
  }

  /** @var \Drupal\Core\Entity\EntityTypeManager $entity_type_manager */
  $entity_type_manager = Drupal::service('entity_type.manager');
  $storage = $entity_type_manager
    ->getStorage('media');
  $media = $storage
    ->load($ids[$context['results']['processed']]);
  if ($media) {
    try {
      $media
        ->save();
    } catch (EntityStorageException $e) {
    }
  }
  $context['results']['processed']++;
  $context['finished'] = $context['sandbox']['count'] ? $context['results']['processed'] / $context['sandbox']['count'] : 1;
}