public static function ContentEntitySourcePluginUi::createContinuousJobItemsBatch

Creates continuous job items for entity.

Batch callback function.

File

sources/content/src/ContentEntitySourcePluginUi.php, line 520

Class

ContentEntitySourcePluginUi
Content entity source plugin UI.

Namespace

Drupal\tmgmt_content

Code

public static function createContinuousJobItemsBatch($item_type, array $search_property_params, &$context) {
  if (empty($context['sandbox'])) {
    $context['sandbox']['offset'] = 0;
    $context['results']['job_items'] = 0;
    $context['sandbox']['progress'] = 0;
    $query = static::buildTranslatableEntitiesQuery($item_type, $search_property_params);
    $context['sandbox']['max'] = $query
      ->countQuery()
      ->execute()
      ->fetchField();
  }
  $limit = \Drupal::config('tmgmt.settings')
    ->get('source_list_limit');
  $entities = static::getTranslatableEntities($item_type, $search_property_params, FALSE, $context['sandbox']['offset'], $limit);
  $context['sandbox']['offset'] += $limit;

  // Loop through entities and add them to continuous jobs.
  foreach ($entities as $entity) {
    $context['results']['job_items'] += tmgmt_content_create_continuous_job_items($entity);
    $context['sandbox']['progress']++;
  }
  $context['message'] = t('Processed @number sources out of @max', array(
    '@number' => $context['sandbox']['progress'],
    '@max' => $context['sandbox']['max'],
  ));
  if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
    $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
  }
  elseif (count($entities) < $limit) {
    $context['finished'] = 1;
  }
}