Index: taxonomy_menu.batch.inc =================================================================== RCS file: taxonomy_menu.batch.inc diff -N taxonomy_menu.batch.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ taxonomy_menu.batch.inc 10 Aug 2009 12:11:57 -0000 @@ -0,0 +1,123 @@ + 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/content/taxonomy/edit/vocabulary/'. $vid, + '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("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; +} Index: taxonomy_menu.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/taxonomy_menu/taxonomy_menu.module,v retrieving revision 1.19.2.2.2.36 diff -u -p -r1.19.2.2.2.36 taxonomy_menu.module --- taxonomy_menu.module 31 May 2009 11:56:03 -0000 1.19.2.2.2.36 +++ taxonomy_menu.module 10 Aug 2009 12:12:01 -0000 @@ -13,6 +13,9 @@ //include the database layer require_once(drupal_get_path('module', 'taxonomy_menu') .'/taxonomy_menu.database.inc'); +//include the batch functions +require_once(drupal_get_path('module', 'taxonomy_menu') .'/taxonomy_menu.batch.inc'); + /** * Implementation of hook_form_alter(). * @@ -224,15 +227,8 @@ function _taxonomy_menu_insert_link_item $mlid = taxonomy_menu_handler('insert', $args); } - //cycle through terms for the vocab - foreach (taxonomy_get_tree($vid) as $term) { - $args = array( - 'term' => $term, - 'menu_name' => $menu_name, - ); - - $mlid = taxonomy_menu_handler('insert', $args); - } + //let batch api take care of inserting the menu items + _taxonomy_menu_insert_link_items_batch($vid); } /** * Implementation of hook_taxonomy().