function activity_batch_regenerate_step in Activity 6.2
Same name and namespace in other branches
- 7 activity.batch.inc \activity_batch_regenerate_step()
Batch regeneration step.
Parameters
$aid: The actions.aid for this template.
$hook: The name of the hook being recorded.
$op: The op for the hook being recorded.
$batch_context: An array representing the context for the batch operation.
1 string reference to 'activity_batch_regenerate_step'
- activity_batch_regenerate in ./
activity.admin.inc - Set a batch process to regenerate activity for a specific hook and op pair.
File
- ./
activity.admin.inc, line 784 - activity.admin.inc Contains administrative forms for activity.module
Code
function activity_batch_regenerate_step($aid, $hook, $op, &$batch_context) {
$module = activity_module_name($hook);
$info = activity_get_module_info($module);
$load_callback = $info->context_load_callback;
// Set up the sandbox for the regeneration.
if (!isset($batch_context['sandbox']['progress'])) {
$batch_context['sandbox']['progress'] = -1;
$parameters = db_result(db_query("SELECT a.parameters FROM {actions} a WHERE aid = '%s'", $aid));
$batch_context['sandbox']['parameters'] = unserialize($parameters);
$batch_context['sandbox']['list'] = activity_batch_load($aid, 0, 0);
$batch_context['sandbox']['sql_limit'] = empty($batch_context['sandbox']['list']);
$batch_context['sandbox']['limit'] = 50;
}
if (!empty($batch_context['sandbox']['finished_last_cycle'])) {
$batch_context['sandbox']['limit'] += 10;
}
$batch_context['sandbox']['finished_last_cycle'] = FALSE;
if ($batch_context['sandbox']['sql_limit']) {
$list = activity_batch_load($aid, $batch_context['sandbox']['progress'] + 1, $batch_context['sandbox']['limit']);
$batch_context['finished'] = 0.5;
}
else {
$list =& $batch_context['sandbox']['list'];
$batch_context['finished'] = ($batch_context['sandbox']['progress'] == -1 ? 0 : $batch_context['sandbox']['progress']) / count($list);
}
if (!empty($list)) {
$count = 0;
foreach ($list as $key => $event) {
$context = array();
if (++$count > $batch_context['sandbox']['limit']) {
break;
}
else {
$context = $load_callback($hook, $op, $event['id']);
if (!empty($context)) {
$context += array(
'created' => $event['created'],
'actor' => $event['actor'],
);
activity_record(NULL, $context + $batch_context['sandbox']['parameters']);
}
$batch_context['sandbox']['progress']++;
}
unset($list[$key]);
}
$batch_context['message'] = t('Processing activity message %progress% ...', array(
'%progress%' => $batch_context['sandbox']['progress'],
));
$batch_context['sandbox']['finished_last_cycle'] = TRUE;
}
else {
$batch_context['finished'] = 1;
}
}