migrateUSMainMenu (function)

Last updated: Mon, Apr 17, 2023 12:56 pm
Return to Knowledgebase

Purpose

Used to migrate the main menu items from an old version of Userspice to a newer version.

Location

users/helpers/menus.php

Parameters

# Parameter Data Type Required Description
1 $truncate = false bool Yes indicating whether to truncate (delete all data from) the us_menu_items table before migrating the main menu data. If set to true, the function will delete all data from the table before migrating the data. If set to false or not specified, the function will only delete the main menu data from the table. The default value is false.

Returns

Data Type Description of Returned Data
nothing

Further Documentation:

The migrateUSMainMenu() function is used to migrate the main menu items from an old version of Userspice to a newer version. It takes one optional parameter $truncate which, if set to true, will truncate the us_menu_items table before inserting new menu items. Otherwise, it will delete all main menu items in the us_menu_items table with a menu value of 1.

The function then queries the old menus table and loops through each menu item. For each item, it creates a new array of fields to be inserted into the us_menu_items table, based on the old menus table item's properties. If the dropdown value is 0, the type field is set to "link", otherwise it is set to "dropdown". If the label value is "{{hr}}", the type field is set to "separator" and the label field is set to an empty string. The label field is also replaced with a new label value from a pre-defined list of labels.

After inserting the new menu item into the us_menu_items table, it updates the permissions field based on the old groups_menus table data, then queries the us_menu_items table again to set the parent field for each item based on the oldIds and newIds arrays.

An example of how to use this function might be:


include_once("userspice/initialize.php");
migrateUSMainMenu();


This would migrate the main menu items from an old version of Userspice to the current version.