Actions

API15

JInstallerModule/uninstall

From Joomla! Documentation

< API15:JInstallerModule
Revision as of 13:32, 12 May 2013 by JoomlaWikiBot (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.

Contents

Description

Custom uninstall method

[<! removed edit link to red link >]

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

Syntax

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)

Returns

boolean True on success

Defined in

libraries/joomla/installer/adapters/module.php

Importing

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
        jimport('joomla.application.helper');
        $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
                JFolder::delete($this->parent->getPath('extension_root'));
                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('media'));
        $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;
        $db->setQuery($query);
        $modules = $db->loadResultArray();
 
        // Do we have any module copies?
        if (count($modules)) {
                JArrayHelper::toInteger($modules);
                $modID = implode(',', $modules);
                $query = 'DELETE' .
                                ' FROM #__modules_menu' .
                                ' WHERE moduleid IN ('.$modID.')';
                $db->setQuery($query);
                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
        $row->delete($row->id);
        $query = 'DELETE FROM `#__modules` WHERE module = '.$db->Quote($row->module) . ' AND client_id = ' . $row->client_id;
        $db->setQuery($query);
        $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 >

Examples

<CodeExamplesForm />