/**
* Method to remove admin menu references to a component
*
* @param int $id The ID of the extension whose admin menus will be removed
*
* @return boolean True if successful.
*
* @throws \Exception
*
* @since 3.1
*/
protected function _removeAdminMenus($id)
{
$db = $this->parent->getDbo();
/** @var \Joomla\CMS\Table\Menu $table */
$table = Table::getInstance('menu');
// Get the ids of the menu items
$query = $db->getQuery(true)->select($db->quoteName('id'))->from($db->quoteName('#__menu'))->where([$db->quoteName('client_id') . ' = 1', $db->quoteName('menutype') . ' = ' . $db->quote('main'), $db->quoteName('component_id') . ' = :id'])->bind(':id', $id, ParameterType::INTEGER);
$db->setQuery($query);
$ids = $db->loadColumn();
$result = true;
// Check for error
if (!empty($ids)) {
// Iterate the items to delete each one.
foreach ($ids as $menuid) {
if (!$table->delete((int) $menuid, false)) {
Factory::getApplication()->enqueueMessage($table->getError(), 'error');
$result = false;
}
}
// Rebuild the whole tree
$table->rebuild();
}
return $result;
}