< API15:JInstallerModule

The "API15" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.


Custom uninstall method

[<! removed edit link to red link >]

<! removed transcluded page call, red link never existed >


uninstall($id, $clientId)
Parameter Name Default Value Description
$id $id The id of the module to uninstall
$clientId $clientId The id of the client (unused)


boolean True on success

Defined in



jimport( 'joomla.installer.adapters.module' );

Source Body

function uninstall( $id, $clientId )
        // Initialize variables
        $row    = null;
        $retval = true;
        $db             =& $this->parent->getDBO();

        // First order of business will be to load the module object table from the database.
        // This should give us the necessary information to proceed.
        $row = & JTable::getInstance('module');
        if ( !$row->load((int) $id) ) {
                JError::raiseWarning(100, JText::_('ERRORUNKOWNEXTENSION'));
                return false;

        // Is the module we are trying to uninstall a core one?
        // Because that is not a good idea...
        if ($row->iscore) {
                JError::raiseWarning(100, JText::_('Module').' '.JText::_('Uninstall').': '.JText::sprintf('WARNCOREMODULE', $row->name)."<br />".JText::_('WARNCOREMODULE2'));
                return false;

        // Get the extension root path
        $client =& JApplicationHelper::getClientInfo($row->client_id);
        if ($client === false) {
                $this->parent->abort(JText::_('Module').' '.JText::_('Uninstall').': '.JText::_('Unknown client type').' ['.$row->client_id.']');
                return false;
        $this->parent->setPath('extension_root', $client->path.DS.'modules'.DS.$row->module);

        // Get the package manifest objecct
        $this->parent->setPath('source', $this->parent->getPath('extension_root'));
        $manifest =& $this->parent->getManifest();
        if (!is_a($manifest, 'JSimpleXML')) {
                // Make sure we delete the folders
                JError::raiseWarning(100, 'Module Uninstall: Package manifest file invalid or not found');
                return false;

        // Remove other files
        $root =& $manifest->document;
        $this->parent->removeFiles($root->getElementByPath('languages'), $clientId);
        $this->parent->removeFiles($root->getElementByPath('administration/languages'), 1);

        // Lets delete all the module copies for the type we are uninstalling
        $query = 'SELECT `id`' .
                        ' FROM `#__modules`' .
                        ' WHERE module = '.$db->Quote($row->module) .
                        ' AND client_id = '.(int)$row->client_id;
        $modules = $db->loadResultArray();

        // Do we have any module copies?
        if (count($modules)) {
                $modID = implode(',', $modules);
                $query = 'DELETE' .
                                ' FROM #__modules_menu' .
                                ' WHERE moduleid IN ('.$modID.')';
                if (!$db->query()) {
                        JError::raiseWarning(100, JText::_('Module').' '.JText::_('Uninstall').': '.$db->stderr(true));
                        $retval = false;

        // Now we will no longer need the module object, so lets delete it and free up memory
        $query = 'DELETE FROM `#__modules` WHERE module = '.$db->Quote($row->module) . ' AND client_id = ' . $row->client_id;
        $db->Query(); // clean up any other ones that might exist as well
        unset ($row);

        // Remove the installation folder
        if (!JFolder::delete($this->parent->getPath('extension_root'))) {
                // JFolder should raise an error
                $retval = false;
        return $retval;

[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >


Code Examples