API15:JInstallerPlugin/uninstall
From Joomla! Documentation
Description
Custom uninstall method
Template:Description:JInstallerPlugin/uninstall
Syntax
uninstall($id, $clientId)
| Parameter Name | Default Value | Description |
|---|---|---|
| $id | $cid The id of the plugin to uninstall | |
| $clientId | $clientId The id of the client (unused) |
Returns
boolean True on success
Defined in
libraries/joomla/installer/adapters/plugin.php
Importing
jimport( 'joomla.installer.adapters.plugin' );
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('plugin');
if ( !$row->load((int) $id) ) {
JError::raiseWarning(100, JText::_('ERRORUNKOWNEXTENSION'));
return false;
}
// Is the plugin we are trying to uninstall a core one?
// Because that is not a good idea...
if ($row->iscore) {
JError::raiseWarning(100, JText::_('Plugin').' '.JText::_('Uninstall').': '.JText::sprintf('WARNCOREPLUGIN', $row->name)."<br />".JText::_('WARNCOREPLUGIN2'));
return false;
}
// Get the plugin folder so we can properly build the plugin path
if (trim($row->folder) == '') {
JError::raiseWarning(100, JText::_('Plugin').' '.JText::_('Uninstall').': '.JText::_('Folder field empty, cannot remove files'));
return false;
}
// Set the plugin root path
$this->parent->setPath('extension_root', JPATH_ROOT.DS.'plugins'.DS.$row->folder);
// Because plugins don't have their own folders we cannot use the standard method of finding an installation manifest
$manifestFile = JPATH_ROOT.DS.'plugins'.DS.$row->folder.DS.$row->element.'.xml';
if (file_exists($manifestFile))
{
$xml =& JFactory::getXMLParser('Simple');
// If we cannot load the xml file return null
if (!$xml->loadFile($manifestFile)) {
JError::raiseWarning(100, JText::_('Plugin').' '.JText::_('Uninstall').': '.JText::_('Could not load manifest file'));
return false;
}
/*
* Check for a valid XML root tag.
* @todo: Remove backwards compatability in a future version
* Should be 'install', but for backward compatability we will accept 'mosinstall'.
*/
$root =& $xml->document;
if ($root->name() != 'install' && $root->name() != 'mosinstall') {
JError::raiseWarning(100, JText::_('Plugin').' '.JText::_('Uninstall').': '.JText::_('Invalid manifest file'));
return false;
}
// Remove the plugin files
$this->parent->removeFiles($root->getElementByPath('images'), -1);
$this->parent->removeFiles($root->getElementByPath('files'), -1);
JFile::delete($manifestFile);
// Remove all media and languages as well
$this->parent->removeFiles($root->getElementByPath('media'));
$this->parent->removeFiles($root->getElementByPath('languages'), 1);
} else {
JError::raiseWarning(100, 'Plugin Uninstall: Manifest File invalid or not found');
return false;
}
// Now we will no longer need the plugin object, so lets delete it
$row->delete($row->id);
unset ($row);
// If the folder is empty, let's delete it
$files = JFolder::files($this->parent->getPath('extension_root'));
if (!count($files)) {
JFolder::delete($this->parent->getPath('extension_root'));
}
return $retval;
}
[Edit See Also] Template:SeeAlso:JInstallerPlugin/uninstall
Examples
<CodeExamplesForm />