Back to ComponentAdapter class

Method finaliseUninstall

protected bool
finaliseUninstall
()
Method to finalise the uninstallation processing
Returns
  • bool
Since
  • 4.0.0
-
  • \RuntimeException

Method finaliseUninstall - Source code

/**
 * 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();
    // 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();
    // Remove the component container in the assets table.
    $asset = Table::getInstance('Asset');
    if ($asset->loadByName($this->getElement())) {
        $asset->delete();
    }
    $extensionName = $this->element;
    $extensionNameWithWildcard = $extensionName . '.%';
    // Remove categories for this component
    $query = $db->getQuery(true)->delete($db->quoteName('#__categories'))->where([$db->quoteName('extension') . ' = :extension', $db->quoteName('extension') . ' LIKE :wildcard'], 'OR')->bind(':extension', $extensionName)->bind(':wildcard', $extensionNameWithWildcard);
    $db->setQuery($query);
    $db->execute();
    // Rebuild the categories for correct lft/rgt
    Table::getInstance('category')->rebuild();
    // Clobber any possible pending updates
    $update = Table::getInstance('update');
    $uid = $update->find(array('element' => $this->extension->element, 'type' => 'component', 'client_id' => 1, 'folder' => ''));
    if ($uid) {
        $update->delete($uid);
    }
    // Now we need to delete the installation directories. This is the final step in uninstalling the component.
    if (trim($this->extension->element)) {
        $retval = true;
        // Delete the component site directory
        if (is_dir($this->parent->getPath('extension_site'))) {
            if (!Folder::delete($this->parent->getPath('extension_site'))) {
                Log::add(Text::_('JLIB_INSTALLER_ERROR_COMP_UNINSTALL_FAILED_REMOVE_DIRECTORY_SITE'), Log::WARNING, 'jerror');
                $retval = false;
            }
        }
        // Delete the component admin directory
        if (is_dir($this->parent->getPath('extension_administrator'))) {
            if (!Folder::delete($this->parent->getPath('extension_administrator'))) {
                Log::add(Text::_('JLIB_INSTALLER_ERROR_COMP_UNINSTALL_FAILED_REMOVE_DIRECTORY_ADMIN'), Log::WARNING, 'jerror');
                $retval = false;
            }
        }
        // Delete the component API directory
        if (is_dir($this->parent->getPath('extension_api'))) {
            if (!Folder::delete($this->parent->getPath('extension_api'))) {
                Log::add(Text::_('JLIB_INSTALLER_ERROR_COMP_UNINSTALL_FAILED_REMOVE_DIRECTORY_API'), Log::WARNING, 'jerror');
                $retval = false;
            }
        }
        // Now we will no longer need the extension object, so let's delete it
        $this->extension->delete($this->extension->extension_id);
        return $retval;
    }
    // No component option defined... cannot delete what we don't know about
    Log::add(Text::_('JLIB_INSTALLER_ERROR_COMP_UNINSTALL_NO_OPTION'), Log::WARNING, 'jerror');
    return false;
}