FOF30\Utils\InstallScript::_rebuildMenu PHP Метод

_rebuildMenu() приватный Метод

Tells Joomla! to rebuild its menu structure to make triple-sure that the Components menu items really do exist in the correct place and can really be rendered.
private _rebuildMenu ( )
    private function _rebuildMenu()
    {
        /** @var \JTableMenu $table */
        $table = \JTable::getInstance('menu');
        $db = $table->getDbo();
        // We need to rebuild the menu based on its root item. By default this is the menu item with ID=1. However, some
        // crappy upgrade scripts enjoy screwing it up. Hey, ho, the workaround way I go.
        $query = $db->getQuery(true)->select($db->qn('id'))->from($db->qn('#__menu'))->where($db->qn('id') . ' = ' . $db->q(1));
        $rootItemId = $db->setQuery($query)->loadResult();
        if (is_null($rootItemId)) {
            // Guess what? The Problem has happened. Let's find the root node by title.
            $rootItemId = null;
            $query = $db->getQuery(true)->select($db->qn('id'))->from($db->qn('#__menu'))->where($db->qn('title') . ' = ' . $db->q('Menu_Item_Root'));
            $rootItemId = $db->setQuery($query, 0, 1)->loadResult();
        }
        if (is_null($rootItemId)) {
            // For crying out loud, did that idiot changed the title too?! Let's find it by alias.
            $rootItemId = null;
            $query = $db->getQuery(true)->select($db->qn('id'))->from($db->qn('#__menu'))->where($db->qn('alias') . ' = ' . $db->q('root'));
            $rootItemId = $db->setQuery($query, 0, 1)->loadResult();
        }
        if (is_null($rootItemId)) {
            // Dude. Dude! Duuuuuuude! The alias is screwed up, too?! Find it by component ID.
            $rootItemId = null;
            $query = $db->getQuery(true)->select($db->qn('id'))->from($db->qn('#__menu'))->where($db->qn('component_id') . ' = ' . $db->q('0'));
            $rootItemId = $db->setQuery($query, 0, 1)->loadResult();
        }
        if (is_null($rootItemId)) {
            // Your site is more of a "shite" than a "site". Let's try with minimum lft value.
            $rootItemId = null;
            $query = $db->getQuery(true)->select($db->qn('id'))->from($db->qn('#__menu'))->order($db->qn('lft') . ' ASC');
            $rootItemId = $db->setQuery($query, 0, 1)->loadResult();
        }
        if (is_null($rootItemId)) {
            // I quit. Your site is broken.
            return false;
        }
        $table->rebuild($rootItemId);
    }