function pathauto_entity_bulk_update_batch_callback in Pathauto Entity 7
Batch processing callback; Generate aliases for entities.
Differs from standard bulk update callback functions by having $settings as parameter, which we need to know which entity type should URL aliases be generated for.
See also
pathauto_entity_bulk_update_batch_process()
2 string references to 'pathauto_entity_bulk_update_batch_callback'
- pathauto_entity_bulk_update_batch_process in includes/
pathauto_entity.batch.inc - Common batch processing callback for entity-based operations.
- pathauto_entity_pathauto in ./
pathauto_entity.module - Implements hook_pathauto().
File
- includes/
pathauto_entity.batch.inc, line 55 - Pathauto Entity batch callback implementations.
Code
function pathauto_entity_bulk_update_batch_callback($settings, &$context) {
if (!isset($context['sandbox']['count'])) {
// First pass. Build an array with all the pairs of id and entity type to process.
$context['sandbox']['count'] = 0;
$context['sandbox']['items'] = array();
$entity_type = $settings->module;
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', $entity_type);
$result = $query
->execute();
$ids = isset($result[$entity_type]) ? array_keys($result[$entity_type]) : array();
foreach ($ids as $id) {
$context['sandbox']['items'][] = array(
'id' => $id,
'type' => $entity_type,
);
}
$context['sandbox']['total'] = count($context['sandbox']['items']);
// If there are no items to update, stop immediately.
if (!$context['sandbox']['total']) {
$context['finished'] = 1;
return;
}
}
// Extract 25 items to be processed in this pass.
$items_to_process = array_slice($context['sandbox']['items'], $context['sandbox']['count'], 25);
module_load_include('inc', 'pathauto');
foreach ($items_to_process as $item) {
$entity = entity_load($item['type'], array(
$item['id'],
));
$entity = reset($entity);
pathauto_entity_update_alias($item['type'], $entity, 'bulkupdate');
}
// Update progress stats.
$context['sandbox']['count'] += count($items_to_process);
if ($context['sandbox']['count'] != $context['sandbox']['total']) {
$context['finished'] = $context['sandbox']['count'] / $context['sandbox']['total'];
}
}