function activity_access_rebuild_process in Activity 6.2
Batch API processing operation. Rebuilding Access table.
Parameters
array $context: The batch api context array.
Return value
none
1 string reference to 'activity_access_rebuild_process'
- activity_access_batch_set in ./
activity.admin.inc - FAPI form submit function for the activity_rebuild button.
File
- ./
activity.admin.inc, line 635 - activity.admin.inc Contains administrative forms for activity.module
Code
function activity_access_rebuild_process(&$context) {
if (!isset($context['sandbox']['last_aid'])) {
// Set up the sandbox for the first time.
$context['sandbox']['last_aid'] = 0;
$context['sandbox']['progress'] = 0;
// Activity can be happening on the site. Any Activity happening after this point
// will not be rebuilt. This is ok, as in that case, the new Activity will receive
// any and all new Activity Access Realms.
$context['sandbox']['max'] = db_result(db_query("SELECT COUNT(aid) FROM {activity}"));
}
// Process 100 Activities at a time.
$limit = 100;
$activities = db_query_range("SELECT * FROM {activity} WHERE aid > %d ORDER BY aid ASC", $context['sandbox']['last_aid'], 0, $limit);
while ($activity = db_fetch_object($activities)) {
$grants = activity_get_grants($activity);
// Delete existing records.
db_query("DELETE FROM {activity_access} WHERE aid = %d", $activity->aid);
// Insert new ones.
foreach ($grants as $realm => $values) {
foreach ($values as $value) {
// insert one by one. In D7 we can use the DBTNG to insert multiple
$perm = new stdClass();
$perm->aid = $activity->aid;
$perm->realm = $realm;
$perm->value = $value;
drupal_write_record('activity_access', $perm);
}
}
// Update sandbox variables.
$context['sandbox']['last_aid'] = $activity->aid;
$context['sandbox']['progress']++;
}
// Check if not finished.
if ($context['sandbox']['progress'] < $context['sandbox']['max']) {
$context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
}
else {
// If finished, delete the sandbox.
unset($context['sandbox']);
}
}