You are here

public function AcquiadamConfig::processBatchItems in Media: Acquia DAM 8

Processes batch items.

Parameters

array $media_ids: Items to process.

array $context: Context.

Throws

\Drupal\Component\Plugin\Exception\PluginException

File

src/Form/AcquiadamConfig.php, line 276

Class

AcquiadamConfig
Class AcquiadamConfig.

Namespace

Drupal\media_acquiadam\Form

Code

public function processBatchItems(array $media_ids, array &$context) {

  /** @var \Drupal\media_acquiadam\Plugin\QueueWorker\AssetRefresh $asset_refresh_queue_worker */
  $asset_refresh_queue_worker = $this->queueWorkerManager
    ->createInstance('media_acquiadam_asset_refresh');
  if (empty($context['sandbox']['progress'])) {
    $context['sandbox']['progress'] = $context['results']['processed'] = 0;
    $context['sandbox']['max'] = count($media_ids);
    $context['sandbox']['items'] = $media_ids;
    $context['results']['total'] = $context['sandbox']['max'];
    $context['results']['start_time'] = $this->time
      ->getRequestTime();
  }
  $media_ids = array_splice($context['sandbox']['items'], 0, self::BATCH_SIZE);
  foreach ($media_ids as $media_id) {
    try {
      if ($asset_refresh_queue_worker
        ->processItem([
        'media_id' => $media_id,
      ])) {
        $context['results']['processed']++;
      }
    } catch (\Exception $e) {
      $this
        ->logger('media_acquiadam')
        ->error('Failed to update media entity id = :id. Message: :message', [
        ':id' => $media_id,
        ':message' => $e
          ->getMessage(),
      ]);
    }
    $context['sandbox']['progress']++;
    $context['message'] = $this
      ->t('Processed :progress media assets out of :count.', [
      ':progress' => $context['sandbox']['progress'],
      ':count' => $context['sandbox']['max'],
    ]);
  }
  $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
}