function title_field_replacement_batch in Title 7
Batch operation: initialize a batch of replacing field values.
1 string reference to 'title_field_replacement_batch'
- title_field_replacement_batch_set in ./
title.module - Set a batch process to initialize replacing field values.
File
- ./
title.module, line 352
Code
function title_field_replacement_batch($entity_type, $bundle, $legacy_field, &$context) {
$info = entity_get_info($entity_type);
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', $entity_type);
// There is no general way to tell if an entity supports bundle conditions
// (for instance taxonomy terms and comments do not), hence we may need to
// loop over all the entities of the given type.
if (!empty($info['efq bundle conditions'])) {
$query
->entityCondition('bundle', $bundle);
}
if (empty($context['sandbox'])) {
$count_query = clone $query;
$total = $count_query
->count()
->execute();
$context['sandbox']['steps'] = 0;
$context['sandbox']['progress'] = 0;
$context['sandbox']['total'] = $total;
}
$step = variable_get('title_field_replacement_batch_size', 5);
$start = $step * $context['sandbox']['steps']++;
$results = $query
->entityCondition('entity_type', $entity_type)
->range($start, $step)
->execute();
if (!empty($results[$entity_type])) {
$ids = array_keys($results[$entity_type]);
title_field_replacement_init($entity_type, $bundle, $legacy_field, $ids);
$context['sandbox']['progress'] += count($ids);
}
if ($context['sandbox']['progress'] != $context['sandbox']['total']) {
$context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['total'];
}
}