english/libraries/joomla/installer/adapters/template.php
/**
	 * Custom uninstall method
	 *
	 * @param   integer  $id		The extension ID
	 *
	 * @return  boolean  True on success
	 * @since   11.1
	 */
Custom uninstall method
@param   integer  $id                The extension ID

@return  boolean  True on success
@since   11.1
Custom uninstall method @param integer $id The extension ID @return boolean True on success @since 11 . 1
public function uninstall($id)
	{
		$retval	= true;
		$row = JTable::getInstance('extension');
		if (!$row->load((int) $id) || !strlen($row->element)) {
			JError::raiseWarning(100, JText::_('JLIB_INSTALLER_ERROR_TPL_UNINSTALL_ERRORUNKOWNEXTENSION'));
			return false;
		}
		if ($row->protected) {
			JError::raiseWarning(100, JText::sprintf('JLIB_INSTALLER_ERROR_TPL_UNINSTALL_WARNCORETEMPLATE', $row->name));
			return false;
		}
		$name = $row->element;
		$clientId = $row->client_id;
		if (!$name) {
			JError::raiseWarning(100, JText::_('JLIB_INSTALLER_ERROR_TPL_UNINSTALL_TEMPLATE_ID_EMPTY'));
			return false;
		}
		$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::_('JLIB_INSTALLER_ERROR_TPL_UNINSTALL_TEMPLATE_DEFAULT'));
			return false;
		}
		$client = JApplicationHelper::getClientInfo($clientId);
		if (!$client) {
			JError::raiseWarning(100, JText::_('JLIB_INSTALLER_ERROR_TPL_UNINSTALL_INVALID_CLIENT'));
			return false;
		}
		$this->parent->setPath('extension_root', $client->path . '/templates/' . strtolower($name));
		$this->parent->setPath('source', $this->parent->getPath('extension_root'));
		$this->parent->findManifest();
		$manifest = $this->parent->getManifest();
		if (!($manifest instanceof JXMLElement)) {
			$row->delete($row->extension_id);
			unset($row);
			JFolder::delete($this->parent->getPath('extension_root'));
			JError::raiseWarning(100, JText::_('JLIB_INSTALLER_ERROR_TPL_UNINSTALL_INVALID_NOTFOUND_MANIFEST'));
			return false;
		}
		$this->parent->removeFiles($manifest->media);
		$this->parent->removeFiles($manifest->languages, $clientId);
		if (JFolder::exists($this->parent->getPath('extension_root'))) {
			$retval = JFolder::delete($this->parent->getPath('extension_root'));
		}
		else {
			JError::raiseWarning(100, JText::_('JLIB_INSTALLER_ERROR_TPL_UNINSTALL_TEMPLATE_DIRECTORY'));
			$retval = false;
		}
		$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(strtolower($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;
	}
public function uninstall ( $ id ) { $ retval = true ; $ row = JTable :: getInstance ( 'extension' ) ; if ( ! $ row -> load ( ( int ) $ id ) || ! strlen ( $ row -> element ) ) { JError :: raiseWarning ( 100 , JText :: _ ( 'JLIB_INSTALLER_ERROR_TPL_UNINSTALL_ERRORUNKOWNEXTENSION' ) ) ; return false ; } if ( $ row -> protected ) { JError :: raiseWarning ( 100 , JText :: sprintf ( 'JLIB_INSTALLER_ERROR_TPL_UNINSTALL_WARNCORETEMPLATE' , $ row -> name ) ) ; return false ; } $ name = $ row -> element ; $ clientId = $ row -> client_id ; if ( ! $ name ) { JError :: raiseWarning ( 100 , JText :: _ ( 'JLIB_INSTALLER_ERROR_TPL_UNINSTALL_TEMPLATE_ID_EMPTY' ) ) ; return false ; } $ 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 :: _ ( 'JLIB_INSTALLER_ERROR_TPL_UNINSTALL_TEMPLATE_DEFAULT' ) ) ; return false ; } $ client = JApplicationHelper :: getClientInfo ( $ clientId ) ; if ( ! $ client ) { JError :: raiseWarning ( 100 , JText :: _ ( 'JLIB_INSTALLER_ERROR_TPL_UNINSTALL_INVALID_CLIENT' ) ) ; return false ; } $ this -> parent -> setPath ( 'extension_root' , $ client -> path . '/templates/' . strtolower ( $ name ) ) ; $ this -> parent -> setPath ( 'source' , $ this -> parent -> getPath ( 'extension_root' ) ) ; $ this -> parent -> findManifest ( ) ; $ manifest = $ this -> parent -> getManifest ( ) ; if ( ! ( $ manifest instanceof JXMLElement ) ) { $ row -> delete ( $ row -> extension_id ) ; unset ( $ row ) ; JFolder :: delete ( $ this -> parent -> getPath ( 'extension_root' ) ) ; JError :: raiseWarning ( 100 , JText :: _ ( 'JLIB_INSTALLER_ERROR_TPL_UNINSTALL_INVALID_NOTFOUND_MANIFEST' ) ) ; return false ; } $ this -> parent -> removeFiles ( $ manifest -> media ) ; $ this -> parent -> removeFiles ( $ manifest -> languages , $ clientId ) ; if ( JFolder :: exists ( $ this -> parent -> getPath ( 'extension_root' ) ) ) { $ retval = JFolder :: delete ( $ this -> parent -> getPath ( 'extension_root' ) ) ; } else { JError :: raiseWarning ( 100 , JText :: _ ( 'JLIB_INSTALLER_ERROR_TPL_UNINSTALL_TEMPLATE_DIRECTORY' ) ) ; $ retval = false ; } $ 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 ( strtolower ( $ 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 ; }
Custom uninstall method
 @param   integer  $id                The extension ID
Custom uninstall method @param integer $id The extension ID
// Initialise variables. // First order of business will be to load the template object table from the database. // This should give us the necessary information to proceed. // Is the template we are trying to uninstall a core one?
 // Because that is not a good idea... // For a template the id will be the template name which represents the subfolder of the templates folder that the template resides in. // Deny remove default template // Get the template root path // We do findManifest to avoid problem when uninstalling a list of extensions: getManifest cache its manifest file // Kill the extension entry // Make sure we delete the folders // Remove files // Delete the template directory // Set menu that assigned to the template back to default template