/**
* Method to finalise the uninstallation processing
*
* @return boolean
*
* @since 4.0.0
* @throws \RuntimeException
*/
protected function finaliseUninstall() : bool
{
$db = $this->parent->getDbo();
$query = $db->getQuery(true);
$element = $this->extension->element;
$clientId = $this->extension->client_id;
$extensionId = $this->extension->extension_id;
// Set menu that assigned to the template back to default template
$subQuery = $db->getQuery(true)->select($db->quoteName('s.id'))->from($db->quoteName('#__template_styles', 's'))->where([$db->quoteName('s.template') . ' = :element', $db->quoteName('s.client_id') . ' = :clientId']);
$query->bind(':element', $element)->bind(':clientId', $clientId, ParameterType::INTEGER);
$query->update($db->quoteName('#__menu'))->set($db->quoteName('template_style_id') . ' = 0')->where($db->quoteName('template_style_id') . ' IN (' . (string) $subQuery . ')');
$db->setQuery($query);
$db->execute();
// Remove the template's styles
$query = $db->getQuery(true)->delete($db->quoteName('#__template_styles'))->where([$db->quoteName('template') . ' = :template', $db->quoteName('client_id') . ' = :client_id'])->bind(':template', $element)->bind(':client_id', $clientId, ParameterType::INTEGER);
$db->setQuery($query);
$db->execute();
// Remove the schema version
$query = $db->getQuery(true)->delete($db->quoteName('#__schemas'))->where($db->quoteName('extension_id') . ' = :extension_id')->bind(':extension_id', $extensionId, ParameterType::INTEGER);
$db->setQuery($query);
$db->execute();
// Clobber any possible pending updates
$update = Table::getInstance('update');
$uid = $update->find(['element' => $this->extension->element, 'type' => $this->type, 'client_id' => $this->extension->client_id]);
if ($uid) {
$update->delete($uid);
}
$this->extension->delete();
return true;
}