function menu_rebuild

You are here

7 menu.inc menu_rebuild()
4.6 menu.inc menu_rebuild()
4.7 menu.inc menu_rebuild()
5 menu.inc menu_rebuild()
6 menu.inc menu_rebuild()

Populates the database tables used by various menu functions.

This function will clear and populate the {menu_router} table, add entries to {menu_links} for new router items, and then remove stale items from {menu_links}. If called from update.php or install.php, it will also schedule a call to itself on the first real page load from menu_execute_active_handler(), because the maintenance page environment is different and leaves stale data in the menu tables.

Return value

TRUE if the menu was rebuilt, FALSE if another thread was rebuilding in parallel and the current thread just waited for completion.

Related topics

22 calls to menu_rebuild()
BlockHiddenRegionTestCase::testBlockNotInHiddenRegion in modules/block/block.test
Tests that hidden regions do not inherit blocks when a theme is enabled.
DrupalWebTestCase::drupalCreateContentType in modules/simpletest/drupal_web_test_case.php
Creates a custom content type based on default settings.
drupal_flush_all_caches in includes/common.inc
Flushes all cached data on the site.
example_profile_tasks in developer/example.profile
Perform any final installation tasks for this profile.
field_ui_field_attach_rename_bundle in modules/field_ui/field_ui.module
Implements hook_field_attach_rename_bundle().

... See full list

File

includes/menu.inc, line 2709
API for the Drupal menu system.

Code

function menu_rebuild() {
  if (!lock_acquire('menu_rebuild')) {
    // Wait for another request that is already doing this work.
    // We choose to block here since otherwise the router item may not
    // be available in menu_execute_active_handler() resulting in a 404.
    lock_wait('menu_rebuild');
    return FALSE;
  }

  $transaction = db_transaction();

  try {
    list($menu, $masks) = menu_router_build();
    _menu_router_save($menu, $masks);
    _menu_navigation_links_rebuild($menu);
    // Clear the menu, page and block caches.
    menu_cache_clear_all();
    _menu_clear_page_cache();

    if (defined('MAINTENANCE_MODE')) {
      variable_set('menu_rebuild_needed', TRUE);
    }
    else {
      variable_del('menu_rebuild_needed');
    }
  }
  catch (Exception $e) {
    $transaction->rollback();
    watchdog_exception('menu', $e);
  }

  lock_release('menu_rebuild');
  return TRUE;
}

Comments

In Drupal 8, the function has been renamed menu_router_rebuild().

Calling this recursively can easly cause admin pages to take many minutes to load.

For example if you call this on a per field basis and have 20 fields on a page you are looking at a maximum 10 minute stall plus the actual render time of the page.

I want to add one menu item in hook_node_insert() of drupal7....how we can do that...plz explain the way how to do ?

@sandeep49: Need support? Need help programming? Connect with the Drupal community.