array( array('_taxonomy_menu_insert_link_items_process', array($terms, $menu_name)), ), 'finished' => '_taxonomy_menu_insert_link_items_success', 'title' => t('Rebuilding Taxonomy Menu'), 'init_message' => t('The menu items have been deleted, and are about to be regenerated.'), 'progress_message' => t('Import progress: Completed @current of @total stages.'), 'redirect' => 'admin/structure/taxonomy', 'error_message' => t('The Taxonomy Menu rebuild process encountered an error.'), ); batch_set($batch); batch_process(); } /* * Insert 10 menu link items */ function _taxonomy_menu_insert_link_items_process($terms, $menu_name, &$context) { _taxonomy_menu_batch_init_context($context, $start, $end, 10); // Loop through $terms to process each term. for ($i=$start; $i $terms[$i], 'menu_name' => $menu_name, ); $mlid = taxonomy_menu_handler('insert', $args); } _taxonomy_menu_batch_update_context($context, $end, count($terms), 'Creating Menu Items'); } /* * Set a message stating the menu has been updated */ function _taxonomy_menu_insert_link_items_success() { // TODO state menu name here. drupal_set_message(t('The Taxonomy Menu has been updated.')); } /* * Initialise the batch context * @param array $context Batch context array. * @param int $start The item to start on in this pass * @param int $end The end item of this pass * @param int $items The number of items to process in this pass */ function _taxonomy_menu_batch_init_context(&$context, &$start, &$end, $items) { // Initialize sandbox the first time through. if(!isset($context['sandbox']['progress'])) { $context['sandbox']['progress'] = 0; } $start = $context['sandbox']['progress']; $end = $start + $items; } /* * Update the batch context * * @param array $context Batch context array. * @param int $end The end point of the most recent pass * @param int $total The total number of items to process in this batch * @param str $msg Message for the progress bar */ function _taxonomy_menu_batch_update_context(&$context, $end, $total, $msg) { //Update context array if ($end > $total) { $context['finished'] = 1; return; } $context['message'] = "{$msg}: {$end} of {$total}"; $context['sandbox']['progress'] = $end; $context['finished'] = $end/$total; }