function activity_batch_delete in Activity 7
Same name and namespace in other branches
- 6.2 activity.admin.inc \activity_batch_delete()
Batch deletion step.
Parameters
$aid: The actions.aid for this template.
$batch_context: The context array for this batch operation.
2 string references to 'activity_batch_delete'
- activity_actions_delete_form_submit in ./
activity.admin.inc - Process activity_actions_delete form submissions.
- activity_batch_regenerate in ./
activity.admin.inc - Set a batch process to regenerate activity for a specific hook and op pair.
File
- ./
activity.batch.inc, line 112 - : Contains Batch API functions for long running processing.
Code
function activity_batch_delete($aid, &$batch_context) {
if (!isset($batch_context['sandbox']['last_activity_id'])) {
$batch_context['sandbox']['last_activity_id'] = 0;
$batch_context['sandbox']['progress'] = 0;
$batch_context['sandbox']['max'] = db_query("SELECT COUNT(aid) FROM {activity} WHERE actions_id = :aid", array(
':aid' => $aid,
))
->fetchField();
}
$limit = 200;
$activity_to_be_deleted = db_select('activity', 'a')
->fields('a', array(
'aid',
))
->condition('a.aid', $batch_context['sandbox']['last_activity_id'], '>')
->condition('a.actions_id', $aid)
->orderBy('a.aid', 'ASC')
->range(0, $limit)
->execute()
->fetchAll();
$activity_ids = array();
if (!empty($activity_to_be_deleted)) {
foreach ($activity_to_be_deleted as $row) {
$activity_ids[] = $row->aid;
$batch_context['sandbox']['last_activity_id'] = $row->aid;
$batch_context['sandbox']['progress']++;
}
activity_delete($activity_ids);
}
// Check if not finished.
if (!empty($activity_to_be_deleted) && $batch_context['sandbox']['progress'] < $batch_context['sandbox']['max']) {
$batch_context['finished'] = $batch_context['sandbox']['progress'] / $batch_context['sandbox']['max'];
}
else {
// If finished, delete the sandbox.
unset($batch_context['sandbox']);
}
}