/**
* 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;
}