123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- <?php
- function callback_batch_operation($MULTIPLE_PARAMS, &$context) {
- if (!isset($context['sandbox']['progress'])) {
- $context['sandbox']['progress'] = 0;
- $context['sandbox']['current_node'] = 0;
- $context['sandbox']['max'] = db_query('SELECT COUNT(DISTINCT nid) FROM {node}')->fetchField();
- }
-
-
- $limit = 5;
-
- $result = db_query_range("SELECT nid FROM {node} WHERE nid > %d ORDER BY nid ASC", $context['sandbox']['current_node'], 0, $limit);
- while ($row = db_fetch_array($result)) {
-
- $node = node_load($row['nid'], NULL, TRUE);
- $node->value1 = $options1;
- $node->value2 = $options2;
- node_save($node);
-
- $context['results'][] = check_plain($node->title);
-
- $context['sandbox']['progress']++;
- $context['sandbox']['current_node'] = $node->nid;
- $context['message'] = t('Now processing %node', array('%node' => $node->title));
- }
-
-
- if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
- $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
- }
- }
- function callback_batch_finished($success, $results, $operations) {
- if ($success) {
-
- $message = t("!count items were processed.", array(
- '!count' => count($results),
- ));
- $message .= theme('item_list', array('items' => $results));
- drupal_set_message($message);
- }
- else {
-
-
- $error_operation = reset($operations);
- $message = t('An error occurred while processing %error_operation with arguments: @arguments', array(
- '%error_operation' => $error_operation[0],
- '@arguments' => print_r($error_operation[1], TRUE)
- ));
- drupal_set_message($message, 'error');
- }
- }
|