JInstallerTemplate/uninstall
From Joomla! Documentation
< API16:JInstallerTemplate
The "API16" 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 transcluded page call, red link never existed >
Syntax[edit]
uninstall($id)
Parameter Name | Default Value | Description |
---|---|---|
$id | $path The template name |
Returns[edit]
boolean True on success
Defined in[edit]
libraries/joomla/installer/adapters/template.php
Importing[edit]
jimport( 'joomla.installer.adapters.template' );
Source Body[edit]
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[edit]
Code Examples[edit]