You are here

function scald_admin_actions_batch in Scald: Media Management made easy 6

1 string reference to 'scald_admin_actions_batch'
scald_admin_actions_form_submit in ./scald.admin.inc
Submit handler for Scald Actions admin form.

File

./scald.admin.inc, line 753

Code

function scald_admin_actions_batch($roles, &$context) {
  if (!isset($context['sandbox']['last_uid'])) {

    // Since *all* users have the Authenticated role, it doesn't appear in
    //  {users_roles} and a special case is needed.
    $context['sandbox']['all_users'] = in_array(DRUPAL_AUTHENTICATED_RID, $roles);
    $context['sandbox']['progress'] = 0;
    $context['sandbox']['last_uid'] = 0;
    $context['sandbox']['total'] = db_result(db_query("\n      SELECT\n        COUNT(DISTINCT uid)\n      FROM " . ($context['sandbox']['all_users'] ? '{users}' : '{users_roles}') . " WHERE " . ($context['sandbox']['all_users'] ? "" : "rid IN (" . implode(', ', $roles) . ") AND ") . "uid > %d\n      ORDER BY\n        uid ASC\n    "));
  }
  $users_results = db_query_range("\n      SELECT\n        DISTINCT uid\n      FROM " . ($context['sandbox']['all_users'] ? '{users}' : '{users_roles}') . " WHERE " . ($context['sandbox']['all_users'] ? "" : "rid IN (" . implode(', ', $roles) . ") AND ") . "uid > %d\n      ORDER BY\n        uid ASC\n    ", $context['sandbox']['last_uid'], 0, SCALD_ADMIN_ACTIONS_BATCH_LIMIT);
  while ($users_raw = db_fetch_array($users_results)) {
    $current = user_load($users_raw['uid']);
    user_save($current);
    $context['sandbox']['progress']++;
    $context['sandbox']['last_uid'] = $users_raw['uid'];
  }
  $context['message'] = t('Updated @current of @total users.', array(
    '@current' => $context['sandbox']['progress'],
    '@total' => $context['sandbox']['total'],
  ));
  $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['total'];
}