You are here

function activity_batch_recreate_messages_step in Activity 7

Batch operation callback to generate new messages.

Parameters

$action_id: The {actions}.aid to generate messages for.

array $context: The context of this batch operation.

1 string reference to 'activity_batch_recreate_messages_step'
activity_admin_recreate in ./activity.admin.inc
Page callback to set up a batch process.

File

./activity.batch.inc, line 76
: Contains Batch API functions for long running processing.

Code

function activity_batch_recreate_messages_step($action_id, &$context) {
  if (!isset($context['sandbox']['last_aid'])) {
    $context['sandbox'] = array(
      'last_aid' => 0,
      'progress' => 0,
      'max' => db_query("SELECT COUNT(aid) FROM {activity} WHERE actions_id = :action_id", array(
        ":action_id" => $action_id,
      ))
        ->fetchField(),
    );
  }
  $limit = 50;
  $records = db_select('activity', 'a')
    ->fields('a')
    ->condition('a.actions_id', $action_id)
    ->condition('a.aid', $context['sandbox']['last_aid'], '>')
    ->range(0, $limit)
    ->execute()
    ->fetchAll();
  $context['sandbox']['progress'] += count($records);
  activity_recreate_messages($records);
  if ($context['sandbox']['progress'] < $context['sandbox']['max']) {
    $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
  }
  else {
    unset($context['sandbox']);
  }
}