Difference between revisions of "JInstallerModule/uninstall"
From Joomla! Documentation
< API15:JInstallerModule
(New page: ===Description===
Custom uninstall method
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>Edit Descripton<nowiki>]</nowi...) |
m (removing red link to edit, no existant pages) |
||
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 122: | Line 122: | ||
<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=== | ||
Line 137: | Line 137: | ||
format= ,,, | format= ,,, | ||
</dpl> | </dpl> | ||
+ | [[Category:Archived pages API15]] |
Revision as of 13:32, 12 May 2013
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 | $id The id of the module to uninstall | |
$clientId | $clientId The id of the client (unused) |
Returns[edit]
boolean True on success
Defined in[edit]
libraries/joomla/installer/adapters/module.php
Importing[edit]
jimport( 'joomla.installer.adapters.module' );
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('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[edit]
<CodeExamplesForm />