Difference between revisions of "JInstallerPlugin/uninstall"
From Joomla! Documentation
< API15:JInstallerPlugin
(New page: ===Description===
Custom uninstall method
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>Edit Descripton<nowiki>]</nowi...) |
m (preparing for archive only) |
||
(One intermediate revision by the same user not shown) | |||
Line 3: | Line 3: | ||
<span class="editsection" style="font-size:76%;"> | <span class="editsection" style="font-size:76%;"> | ||
− | <nowiki>[< | + | <nowiki>[<! removed edit link to red link >]</nowiki> |
</span> | </span> | ||
− | + | <! removed transcluded page call, red link never existed > | |
===Syntax=== | ===Syntax=== | ||
Line 118: | Line 118: | ||
<span class="editsection" style="font-size:76%;"> | <span class="editsection" style="font-size:76%;"> | ||
− | <nowiki>[< | + | <nowiki>[<! removed edit link to red link >]</nowiki> |
</span> | </span> | ||
− | + | <! removed transcluded page call, red link never existed > | |
===Examples=== | ===Examples=== | ||
− | + | === Code Examples === | |
<dpl> | <dpl> | ||
noresultsheader=\n | noresultsheader=\n | ||
category=uninstall | category=uninstall | ||
category=JInstallerPlugin | category=JInstallerPlugin | ||
− | + | namespace=CodeExample | |
category=MethodExample | category=MethodExample | ||
include=* | include=* | ||
format= ,,, | format= ,,, | ||
</dpl> | </dpl> | ||
+ | [[Category:Archived pages API15]] |
Latest revision as of 19:54, 24 March 2017
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.
Description[edit]
Custom uninstall method
[<! removed edit link to red link >]
<! removed transcluded page call, red link never existed >
Syntax[edit]
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[edit]
boolean True on success
Defined in[edit]
libraries/joomla/installer/adapters/plugin.php
Importing[edit]
jimport( 'joomla.installer.adapters.plugin' );
Source Body[edit]
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;
}
[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >
Examples[edit]
Code Examples[edit]