From Joomla! Documentation

< API16:JInstallerTemplate
Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.



Custom uninstall method

[<! removed edit link to red link >]

<! removed transcluded page call, red link never existed >


Parameter Name Default Value Description
$id $path The template name


boolean True on success

Defined in



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);
        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
                // Make sure we delete the folders
                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'));
                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 = #__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);
        $query = 'DELETE FROM #__template_styles'.
                        ' WHERE template = '.$db->Quote($name).
                        ' AND client_id = '.$db->Quote($clientId);
        return $retval;

[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >


<CodeExamplesForm />