function group_pathauto_bulk_update_batch_process in Group 7
Batch processing callback; Generate aliases for groups.
1 string reference to 'group_pathauto_bulk_update_batch_process'
- group_pathauto in ./
group.pathauto.inc - Implements hook_pathauto().
File
- ./
group.pathauto.inc, line 64 - Hook implementations for the Pathauto module.
Code
function group_pathauto_bulk_update_batch_process(&$context) {
if (!isset($context['sandbox']['current'])) {
$context['sandbox']['count'] = 0;
$context['sandbox']['current'] = 0;
}
$query = db_select('groups', 'g');
$query
->leftJoin('url_alias', 'ua', "CONCAT('group/', g.gid) = ua.source");
$query
->addField('g', 'gid');
$query
->isNull('ua.source');
$query
->condition('g.gid', $context['sandbox']['current'], '>');
$query
->orderBy('g.gid');
$query
->addTag('pathauto_bulk_update');
$query
->addMetaData('entity', 'group');
// Get the total amount of items to process.
if (!isset($context['sandbox']['total'])) {
$context['sandbox']['total'] = $query
->countQuery()
->execute()
->fetchField();
// If there are no groups to update, the stop immediately.
if (!$context['sandbox']['total']) {
$context['finished'] = 1;
return;
}
}
$query
->range(0, 25);
$gids = $query
->execute()
->fetchCol();
group_pathauto_update_alias_multiple($gids, 'bulkupdate');
$context['sandbox']['count'] += count($gids);
$context['sandbox']['current'] = max($gids);
$context['message'] = t('Updated alias for group @gid.', array(
'@gid' => end($gids),
));
if ($context['sandbox']['count'] != $context['sandbox']['total']) {
$context['finished'] = $context['sandbox']['count'] / $context['sandbox']['total'];
}
}