Back to ComponentAdapter class

Method _updateMenus

protected bool
_updateMenus
(mixed $componentId, mixed $clientId = null)
Method to update menu database entries for a component in case if the component has been uninstalled before.
Parameters
  • int|null $componentId The component ID.
  • int $clientId The client id
Returns
  • bool True if successful
Since
  • 3.7.0

Method _updateMenus - Source code

/**
 * Method to update menu database entries for a component in case if the component has been uninstalled before.
 *
 * @param   int|null  $componentId  The component ID.
 * @param   int       $clientId     The client id
 *
 * @return  boolean  True if successful
 *
 * @since   3.7.0
 */
protected function _updateMenus($componentId, $clientId = null)
{
    $db = $this->parent->getDbo();
    $option = $this->element;
    $link = 'index.php?option=' . $option;
    $linkMatch = 'index.php?option=' . $option . '&%';
    // Update all menu items which contain 'index.php?option=com_extension' or 'index.php?option=com_extension&...'
    // to use the new component id.
    $query = $db->getQuery(true)->update($db->quoteName('#__menu'))->set($db->quoteName('component_id') . ' = :componentId')->where($db->quoteName('type') . ' = ' . $db->quote('component'))->extendWhere('AND', [$db->quoteName('link') . ' LIKE :link', $db->quoteName('link') . ' LIKE :linkMatch'], 'OR')->bind(':componentId', $componentId, ParameterType::INTEGER)->bind(':link', $link)->bind(':linkMatch', $linkMatch);
    if (isset($clientId)) {
        $query->where($db->quoteName('client_id') . ' = :clientId')->bind(':clientId', $clientId, ParameterType::INTEGER);
    }
    try {
        $db->setQuery($query);
        $db->execute();
    } catch (\RuntimeException $e) {
        return false;
    }
    return true;
}