JInstallerTemplate/uninstall: Difference between revisions
From Joomla! Documentation
New page: ===Description===
Custom uninstall method
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>Edit Descripton<nowiki>]</no... |
m preparing for archive only |
||
| (2 intermediate revisions by the same user not shown) | |||
| Line 2: | Line 2: | ||
Custom uninstall method | Custom uninstall method | ||
<! removed transcluded page call, red link never existed > | |||
===Syntax=== | ===Syntax=== | ||
| Line 132: | Line 130: | ||
</source> | </source> | ||
<! removed transcluded page call, red link never existed > | |||
< | |||
===Examples=== | ===Examples=== | ||
=== Code Examples === | |||
<dpl> | <dpl> | ||
noresultsheader=\n | noresultsheader=\n | ||
category=uninstall | category=uninstall | ||
category=JInstallerTemplate | category=JInstallerTemplate | ||
namespace=CodeExample | |||
category=MethodExample | category=MethodExample | ||
include=* | include=* | ||
format= ,,, | format= ,,, | ||
</dpl> | </dpl> | ||
[[Category:Archived pages API16]] | |||
Latest revision as of 01:51, 25 March 2017
Description
Custom uninstall method
<! removed transcluded page call, red link never existed >
Syntax
uninstall($id)
| Parameter Name | Default Value | Description |
|---|---|---|
| $id | $path The template name |
Returns
boolean True on success
Defined in
libraries/joomla/installer/adapters/template.php
Importing
jimport( 'joomla.installer.adapters.template' );
Source Body
public function uninstall($id)
{
// Initialise variables.
$retval = true;
// 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('extension');
if (!$row->load((int) $id) || !strlen($row->element))
{
JError::raiseWarning(100, JText::_('ERRORUNKOWNEXTENSION'));
return false;
}
// Is the template we are trying to uninstall a core one?
// Because that is not a good idea...
if ($row->protected)
{
JError::raiseWarning(100, JText::_('Template').' '.JText::_('Uninstall').': '.JText::sprintf('WARNCOREMODULE', $row->name)."<br />".JText::_('WARNCOREMODULE2'));
return false;
}
$name = $row->element;
$clientId = $row->client_id;
// For a template the id will be the template name which represents the subfolder of the templates folder that the template resides in.
if (!$name)
{
JError::raiseWarning(100, JText::_('Template').' '.JText::_('Uninstall').': '.JText::_('Template id is empty, cannot uninstall files'));
return false;
}
// Deny remove default template
$db = &$this->parent->getDbo();
$query = 'SELECT COUNT(*) FROM #__template_styles'.
' WHERE home = 1 AND template = '.$db->Quote($name);
$db->setQuery($query);
if ($db->loadResult() != 0)
{
JError::raiseWarning(100, JText::_('Template').' '.JText::_('Uninstall').': '.JText::_('Cannot remove default template'));
return false;
}
// Get the template root path
$client = &JApplicationHelper::getClientInfo($clientId);
if (!$client)
{
JError::raiseWarning(100, JText::_('Template').' '.JText::_('Uninstall').': '.JText::_('Invalid application'));
return false;
}
$this->parent->setPath('extension_root', $client->path.DS.'templates'.DS.$name);
$this->parent->setPath('source', $this->parent->getPath('extension_root'));
$manifest = &$this->parent->getManifest();
if (!$manifest INSTANCEOF JXMLElement)
{
// kill the extension entry
$row->delete($row->extension_id);
unset($row);
// Make sure we delete the folders
JFolder::delete($this->parent->getPath('extension_root'));
JError::raiseWarning(100, JTEXT::_('Template').' '.JTEXT::_('Uninstall').': '.JTEXT::_('Package manifest file invalid or not found'));
return false;
}
// Remove files
$this->parent->removeFiles($manifest->media, $clientId);
$this->parent->removeFiles($manifest->languages, $clientId);
// Delete the template directory
if (JFolder::exists($this->parent->getPath('extension_root'))) {
$retval = JFolder::delete($this->parent->getPath('extension_root'));
}
else
{
JError::raiseWarning(100, JText::_('Template').' '.JText::_('Uninstall').': '.JText::_('Directory does not exist, cannot remove files'));
$retval = false;
}
//Set menu that assigned to the template back to default template
$query = 'UPDATE #__menu INNER JOIN #__template_styles'.
' ON #__template_styles.id = #__menu.template_style_id'.
' SET #__menu.template_style_id = 0'.
' WHERE #__template_styles.template = '.$db->Quote($name).
' AND #__template_styles.client_id = '.$db->Quote($clientId);
$db->setQuery($query);
$db->Query();
$query = 'DELETE FROM #__template_styles'.
' WHERE template = '.$db->Quote($name).
' AND client_id = '.$db->Quote($clientId);
$db->setQuery($query);
$db->Query();
$row->delete($row->extension_id);
unset($row);
return $retval;
}
<! removed transcluded page call, red link never existed >
Examples
Code Examples