/**
* Method to finalise the uninstallation processing
*
* @return boolean
*
* @since 4.0.0
* @throws \RuntimeException
*/
protected function finaliseUninstall() : bool
{
$extensionId = $this->extension->extension_id;
$db = $this->parent->getDbo();
$retval = true;
// Remove the schema version
$query = $db->getQuery(true)->delete('#__schemas')->where('extension_id = :extension_id')->bind(':extension_id', $extensionId, ParameterType::INTEGER);
$db->setQuery($query);
$db->execute();
$element = $this->extension->element;
$clientId = $this->extension->client_id;
// Let's delete all the module copies for the type we are uninstalling
$query->clear()->select($db->quoteName('id'))->from($db->quoteName('#__modules'))->where($db->quoteName('module') . ' = :element')->where($db->quoteName('client_id') . ' = :client_id')->bind(':element', $element)->bind(':client_id', $clientId, ParameterType::INTEGER);
$db->setQuery($query);
try {
$modules = $db->loadColumn();
} catch (\RuntimeException $e) {
$modules = [];
}
// Do we have any module copies?
if (\count($modules)) {
// Ensure the list is sane
$modules = ArrayHelper::toInteger($modules);
$modID = implode(',', $modules);
// Wipe out any items assigned to menus
$query = $db->getQuery(true)->delete($db->quoteName('#__modules_menu'))->where($db->quoteName('moduleid') . ' IN (' . $modID . ')');
$db->setQuery($query);
try {
$db->execute();
} catch (\RuntimeException $e) {
Log::add(Text::sprintf('JLIB_INSTALLER_ERROR_MOD_UNINSTALL_EXCEPTION', $e->getMessage()), Log::WARNING, 'jerror');
$retval = false;
}
// Wipe out any instances in the modules table
/** @var \Joomla\CMS\Table\Module $module */
$module = Table::getInstance('Module');
foreach ($modules as $modInstanceId) {
$module->load($modInstanceId);
if (!$module->delete()) {
Log::add(Text::sprintf('JLIB_INSTALLER_ERROR_MOD_UNINSTALL_EXCEPTION', $module->getError()), Log::WARNING, 'jerror');
$retval = false;
}
}
}
// Now we will no longer need the module object, so let's delete it and free up memory
$this->extension->delete($this->extension->extension_id);
$query = $db->getQuery(true)->delete($db->quoteName('#__modules'))->where($db->quoteName('module') . ' = :element')->where($db->quoteName('client_id') . ' = :client_id')->bind(':element', $element)->bind(':client_id', $clientId, ParameterType::INTEGER);
$db->setQuery($query);
try {
// Clean up any other ones that might exist as well
$db->execute();
} catch (\RuntimeException $e) {
// Ignore the error...
}
// Remove the installation folder
if (!Folder::delete($this->parent->getPath('extension_root'))) {
// Folder should raise an error
$retval = false;
}
return $retval;
}