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

bugfixCantBuildAdminMenus() защищенный Метод

Joomla! 1.6+ bugfix for "Can not build admin menus"
    protected function bugfixCantBuildAdminMenus()
    {
        $db = JFactory::getDbo();
        // If there are multiple #__extensions record, keep one of them
        $query = $db->getQuery(true);
        $query->select('extension_id')->from('#__extensions')->where($db->qn('type') . ' = ' . $db->q('component'))->where($db->qn('element') . ' = ' . $db->q($this->componentName));
        $db->setQuery($query);
        try {
            $ids = $db->loadColumn();
        } catch (Exception $exc) {
            return;
        }
        if (count($ids) > 1) {
            asort($ids);
            $extension_id = array_shift($ids);
            // Keep the oldest id
            foreach ($ids as $id) {
                $query = $db->getQuery(true);
                $query->delete('#__extensions')->where($db->qn('extension_id') . ' = ' . $db->q($id));
                $db->setQuery($query);
                try {
                    $db->execute();
                } catch (Exception $exc) {
                    // Nothing
                }
            }
        }
        // If there are multiple assets records, delete all except the oldest one
        $query = $db->getQuery(true);
        $query->select('id')->from('#__assets')->where($db->qn('name') . ' = ' . $db->q($this->componentName));
        $db->setQuery($query);
        $ids = $db->loadObjectList();
        if (count($ids) > 1) {
            asort($ids);
            $asset_id = array_shift($ids);
            // Keep the oldest id
            foreach ($ids as $id) {
                $query = $db->getQuery(true);
                $query->delete('#__assets')->where($db->qn('id') . ' = ' . $db->q($id));
                $db->setQuery($query);
                try {
                    $db->execute();
                } catch (Exception $exc) {
                    // Nothing
                }
            }
        }
        // Remove #__menu records for good measure! –– I think this is not necessary and causes the menu item to
        // disappear on extension update.
        /**
        		$query = $db->getQuery(true);
        		$query->select('id')
        		->from('#__menu')
        		->where($db->qn('type') . ' = ' . $db->q('component'))
        		->where($db->qn('menutype') . ' = ' . $db->q('main'))
        		->where($db->qn('link') . ' LIKE ' . $db->q('index.php?option=' . $this->componentName));
        		$db->setQuery($query);
        
        		try
        		{
        		$ids1 = $db->loadColumn();
        		}
        		catch (Exception $exc)
        		{
        		$ids1 = array();
        		}
        
        		if (empty($ids1))
        		{
        		$ids1 = array();
        		}
        
        		$query = $db->getQuery(true);
        		$query->select('id')
        		->from('#__menu')
        		->where($db->qn('type') . ' = ' . $db->q('component'))
        		->where($db->qn('menutype') . ' = ' . $db->q('main'))
        		->where($db->qn('link') . ' LIKE ' . $db->q('index.php?option=' . $this->componentName . '&%'));
        		$db->setQuery($query);
        
        		try
        		{
        		$ids2 = $db->loadColumn();
        		}
        		catch (Exception $exc)
        		{
        		$ids2 = array();
        		}
        
        		if (empty($ids2))
        		{
        		$ids2 = array();
        		}
        
        		$ids = array_merge($ids1, $ids2);
        
        		if (!empty($ids))
        		{
        		foreach ($ids as $id)
        		{
        		$query = $db->getQuery(true);
        		$query->delete('#__menu')
        		->where($db->qn('id') . ' = ' . $db->q($id));
        		$db->setQuery($query);
        
        		try
        		{
        		$db->execute();
        		}
        		catch (Exception $exc)
        		{
        		// Nothing
        		}
        		}
        		}
        		/**/
    }