FALSE, 'merge_fields' => array(), 'keep_only_unique' => TRUE, 'redirect' => TERM_MERGE_NO_REDIRECT, 'synonyms' => array(), 'step' => 40, ); $total = count($term_branch); // To speed up the process we take advantage of taxonomy_term_load_multiple() // instead of just repeating calls to taxonomy_term_load(). $till = min($total, $context['sandbox']['current'] + $merge_settings['step']); $length = $till - $context['sandbox']['current']; $term_branch = array_slice($term_branch, $context['sandbox']['current'], $length); $term_branch = array_values(taxonomy_term_load_multiple($term_branch)); for ($i = 0; $i < $merge_settings['step'] && $context['sandbox']['current'] < $total; $i++) { actions_do('term_merge_action', $term_branch[$i], array( 'term_trunk' => $term_trunk, 'term_branch_keep' => $merge_settings['term_branch_keep'], 'merge_fields' => $merge_settings['merge_fields'], 'keep_only_unique' => $merge_settings['keep_only_unique'], 'redirect' => $merge_settings['redirect'], 'synonyms' => $merge_settings['synonyms'], )); $context['sandbox']['current']++; } if ($context['sandbox']['current'] != $total) { $context['finished'] = $context['sandbox']['current'] / $total; $term = $term_branch[$i - 1]; $context['message'] = t('Merged up to @term', array('@term' => $term->name)); } } /** * Batch 'finished' callback. * * Process results of Term Merge batch. */ function term_merge_batch_finished($success, $results, $operations) { if ($success) { drupal_set_message(t('The terms have been successfully merged.')); } else { // An error happened. We have to notify the user. drupal_set_message(t('An error occurred. We are sorry, please, report this error to the maintainers of Term Merge module.'), 'error'); } }