How to create programmatically menu links with just created nodes during installation profile in aegir ?can't get nid! I am creating a set of nodes in an installation profile.  When I try to create menu links for them in the same PROFILE_NAME.install, the links don't get created.

I have also tried creating the menus links in a separate module, and using hook_update_N() to enable them, but that also does not work.

When I uninstall the module and reactivate it, it creates correctly my menu's links correctly.

I tried to use hook_install_tasks() and put it in MYPROFILE_NAME.profile or MYPROFILE_NAME.install, but this also doesn't work.

How can I create menu links for nodes created as part of an installation profile?

My code for creating the nodes in MY_PROFILE_NAME.install is:

// creation of my nodes (same content for all)
   $nodi = array(
       // i have other 14 nodes  
      'title' =&gt; array('Home'),
       // i have other 14 paths for the nodes
      'path' =&gt; array('home'),
   );
$titoli = array();
$titoli = $nodi['title'];
$percorsi = array();
$percorsi = $nodi['path'];
//CREAZIONI DEL CONTENUTO PROGRAMMATICAMENTE
  for($i = 0; $i&lt; count($titoli); $i++){
$testo_body = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec feugiat velit eget metus placerat,varius eros facilisis. Aenean aliquam imperdiet nisl ut dapibus...';
           $node = new stdClass(); // nuovo oggetto nodo
           $lingua = 'it'; 
           $node-&gt;type = "page"; //
           $node-&gt;title = $titoli[$i];
           $node-&gt;language = $lingua; 
           $node-&gt;path = array('alias' =&gt; $percorsi[$i]); // i think here is the problem !!!
           $node-&gt;uid = 1; // admin
           $node-&gt;status = 1;
           // Body field    
           $body_field_info = field_info_field('body');
           if (field_is_translatable('node', $body_field_info)) {
              $body_lingua = field_valid_language($lingua);
           }else{
              $body_lingua = LANGUAGE_NONE;
           }
           $node-&gt;body[$body_lingua][0]['value'] = $testo_body;
           $node-&gt;body[$body_lingua][0]['summary'] = 'text...';
           $node-&gt;body[$body_lingua][0]['format'] = 'full_html';
           $node = node_submit($node); // Prepare node for a submit
           node_save($node); // After this call we'll get a nid


And my code for creating the menu links is:


    // Create a Home link in the main menu.   
  $path = drupal_lookup_path('source', 'home');
  $item = array(
    'link_path' => $path,
    'router_path' => $path,
    'link_title' => st('Home'),
    'menu_name' => 'main-menu',
    'weight' => -50,
    'customized' => 1,
    'plid' => 0, // Parent menu item, 0 if menu item is on top level
  );
  menu_link_save($item);
  menu_rebuild();


Update 2

The menus are created in the menu_links table but with empty link_path so i can't get the nid created nodes.
I treid also to override the install_finished() and put my function for creating menus in .install or in .profile files, but it's the same.
Any ideas?
You can add a menu item using this

$item = array(
        'menu_name' =&gt; 'menu-name',
        'link_title' =&gt; 'Link title',
        'link_path' =&gt; 'node/'. $nid,
      );
menu_link_save($item);
//don't forget to clear menu cache after saving menu item
menu_cache_clear_all();


Hope this will help

Updated Answer
As I looked into Drupal 7 standard profile installation file, that is standard.install (Line no 413), you can see "Home" link creation there.

// Create a Home link in the main menu.
  $item = array(
    'link_title' =&gt; st('Home'),
    'link_path' =&gt; '&lt;front&gt;',
    'menu_name' =&gt; 'main-menu',
  );
  menu_link_save($item);

  // Update the menu router information.
  menu_rebuild();