/ Published in: PHP

This is the Batch API example shown on http://api.drupal.org/api/drupal/developer--hooks--install.php/function/hook_update_N/6.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php // However, for more complex operations that may take a long time, // you may hook into Batch API as in the following example. // Update 3 users at a time to have an exclamation point after their names. // (They're really happy that we can do batch API in this hook!) $sandbox['progress'] = 0; $sandbox['current_uid'] = 0; // We'll -1 to disregard the uid 0... $sandbox['max'] = db_result(db_query('SELECT COUNT(DISTINCT uid) FROM {users}')) - 1; } $users = db_query_range("SELECT uid, name FROM {users} WHERE uid > %d ORDER BY uid ASC", $sandbox['current_uid'], 0, 3); while ($user = db_fetch_object($users)) { $user->name .= '!'; $ret[] = update_sql("UPDATE {users} SET name = '$user->name' WHERE uid = $user->uid"); $sandbox['progress']++; $sandbox['current_uid'] = $user->uid; } return $ret; ?>
URL: http://api.drupal.org/api/drupal/developer--hooks--install.php/function/hook_update_N/6
Comments
