english/libraries/joomla/installer/adapters/module.php
/**
	 * Custom uninstall method
	 *
	 * @param   integer  $id  The id of the module to uninstall
	 *
	 * @return  boolean  True on success
	 * @since   11.1
	 */
Custom uninstall method
@param   integer  $id  The id of the module to uninstall

@return  boolean  True on success
@since   11.1
Custom uninstall method @param integer $id The id of the module to uninstall @return boolean True on success @since 11 . 1
public function uninstall($id)
	{
		$row	= null;
		$retval = true;
		$db		= $this->parent->getDbo();
		$row = JTable::getInstance('extension');
		if (!$row->load((int) $id) || !strlen($row->element)) {
			JError::raiseWarning(100, JText::_('JLIB_INSTALLER_ERROR_MOD_UNINSTALL_ERRORUNKOWNEXTENSION'));
			return false;
		}
		if ($row->protected) {
			JError::raiseWarning(100, JText::sprintf('JLIB_INSTALLER_ERROR_MOD_UNINSTALL_WARNCOREMODULE', $row->name));
			return false;
		}
		jimport('joomla.application.helper');
		$element = $row->element;
		$client = JApplicationHelper::getClientInfo($row->client_id);
		if ($client === false) {
			$this->parent->abort(JText::sprintf('JLIB_INSTALLER_ERROR_MOD_UNINSTALL_UNKNOWN_CLIENT', $row->client_id));
			return false;
		}
		$this->parent->setPath('extension_root', $client->path . '/modules/' . $element);
		$this->parent->setPath('source', $this->parent->getPath('extension_root'));
		$this->parent->findManifest();
		$this->manifest = $this->parent->getManifest();
		$this->loadLanguage(($row->client_id ? JPATH_ADMINISTRATOR : JPATH_SITE) . '/modules/'.$element);
		$this->scriptElement = $this->manifest->scriptfile;
		$manifestScript = (string)$this->manifest->scriptfile;
		if ($manifestScript) {
			$manifestScriptFile = $this->parent->getPath('extension_root') . '/' . $manifestScript;
			if (is_file($manifestScriptFile)) {
				include_once $manifestScriptFile;
			}
			$classname = $element.'InstallerScript';
			if (class_exists($classname)) {
				$this->parent->manifestClass = new $classname($this);
				$this->set('manifest_script', $manifestScript);
			}
		}
		ob_start();
		ob_implicit_flush(false);
		if ($this->parent->manifestClass && method_exists($this->parent->manifestClass,'uninstall')) {
			$this->parent->manifestClass->uninstall($this);
		}
		$msg = ob_get_contents();
		ob_end_clean();
		if (!($this->manifest instanceof JXMLElement)) {
			JFolder::delete($this->parent->getPath('extension_root'));
			JError::raiseWarning(100, JText::_('JLIB_INSTALLER_ERROR_MOD_UNINSTALL_INVALID_NOTFOUND_MANIFEST'));
			return false;
		}
		$utfresult = $this->parent->parseSQLFiles($this->manifest->uninstall->sql);
		if ($utfresult === false) {
			JError::raiseWarning(100, JText::sprintf('JLIB_INSTALLER_ERROR_MOD_UNINSTALL_SQL_ERROR', $db->stderr(true)));
			$retval = false;
		}
		$query = $db->getQuery(true);
		$query->delete()->from('#__schemas')->where('extension_id = '. $row->extension_id);
		$db->setQuery($query);
		$db->Query();
		$this->parent->removeFiles($this->manifest->media);
		$this->parent->removeFiles($this->manifest->languages, $row->client_id);
		$query = 'SELECT `id`' .
				' FROM `#__modules`' .
				' WHERE module = '.$db->Quote($row->element) .
				' AND client_id = '.(int)$row->client_id;
		$db->setQuery($query);
		try
		{
			$modules = $db->loadColumn();
		}
		catch(JException $e)
		{
			$modules = array();
		}
				if (count($modules))
		{
			JArrayHelper::toInteger($modules);
			$modID = implode(',', $modules);
			$query = 'DELETE' .
					' FROM #__modules_menu' .
					' WHERE moduleid IN ('.$modID.')';
			$db->setQuery($query);
			try
			{
				$db->query();
			}
			catch(JException $e)
			{
				JError::raiseWarning(100, JText::sprintf('JLIB_INSTALLER_ERROR_MOD_UNINSTALL_EXCEPTION', $db->stderr(true)));
				$retval = false;
			}
			$query = 'DELETE' .
					' FROM #__modules' .
					' WHERE id IN ('.$modID.')';
			$db->setQuery($query);
			try
			{
				$db->query();
			}
			catch (JException $e)
			{
				JError::raiseWarning(100, JText::sprintf('JLIB_INSTALLER_ERROR_MOD_UNINSTALL_EXCEPTION', $db->stderr(true)));
				$retval = false;
			}
		}
		$row->delete($row->extension_id);
		$query = 'DELETE FROM `#__modules` WHERE module = '.$db->Quote($row->element) . ' AND client_id = ' . $row->client_id;
		$db->setQuery($query);
		try
		{
			$db->Query();
		}
		catch(JException $e)
		{
		}
		unset ($row);
		if (!JFolder::delete($this->parent->getPath('extension_root'))) {
			$retval = false;
		}
		return $retval;
	}
public function uninstall ( $ id ) { $ row = null ; $ retval = true ; $ db = $ this -> parent -> getDbo ( ) ; $ row = JTable :: getInstance ( 'extension' ) ; if ( ! $ row -> load ( ( int ) $ id ) || ! strlen ( $ row -> element ) ) { JError :: raiseWarning ( 100 , JText :: _ ( 'JLIB_INSTALLER_ERROR_MOD_UNINSTALL_ERRORUNKOWNEXTENSION' ) ) ; return false ; } if ( $ row -> protected ) { JError :: raiseWarning ( 100 , JText :: sprintf ( 'JLIB_INSTALLER_ERROR_MOD_UNINSTALL_WARNCOREMODULE' , $ row -> name ) ) ; return false ; } jimport ( 'joomla.application.helper' ) ; $ element = $ row -> element ; $ client = JApplicationHelper :: getClientInfo ( $ row -> client_id ) ; if ( $ client === false ) { $ this -> parent -> abort ( JText :: sprintf ( 'JLIB_INSTALLER_ERROR_MOD_UNINSTALL_UNKNOWN_CLIENT' , $ row -> client_id ) ) ; return false ; } $ this -> parent -> setPath ( 'extension_root' , $ client -> path . '/modules/' . $ element ) ; $ this -> parent -> setPath ( 'source' , $ this -> parent -> getPath ( 'extension_root' ) ) ; $ this -> parent -> findManifest ( ) ; $ this -> manifest = $ this -> parent -> getManifest ( ) ; $ this -> loadLanguage ( ( $ row -> client_id ? JPATH_ADMINISTRATOR : JPATH_SITE ) . '/modules/' . $ element ) ; $ this -> scriptElement = $ this -> manifest -> scriptfile ; $ manifestScript = ( string ) $ this -> manifest -> scriptfile ; if ( $ manifestScript ) { $ manifestScriptFile = $ this -> parent -> getPath ( 'extension_root' ) . '/' . $ manifestScript ; if ( is_file ( $ manifestScriptFile ) ) { include_once $ manifestScriptFile ; } $ classname = $ element . 'InstallerScript' ; if ( class_exists ( $ classname ) ) { $ this -> parent -> manifestClass = new $ classname ( $ this ) ; $ this -> set ( 'manifest_script' , $ manifestScript ) ; } } ob_start ( ) ; ob_implicit_flush ( false ) ; if ( $ this -> parent -> manifestClass && method_exists ( $ this -> parent -> manifestClass , 'uninstall' ) ) { $ this -> parent -> manifestClass -> uninstall ( $ this ) ; } $ msg = ob_get_contents ( ) ; ob_end_clean ( ) ; if ( ! ( $ this -> manifest instanceof JXMLElement ) ) { JFolder :: delete ( $ this -> parent -> getPath ( 'extension_root' ) ) ; JError :: raiseWarning ( 100 , JText :: _ ( 'JLIB_INSTALLER_ERROR_MOD_UNINSTALL_INVALID_NOTFOUND_MANIFEST' ) ) ; return false ; } $ utfresult = $ this -> parent -> parseSQLFiles ( $ this -> manifest -> uninstall -> sql ) ; if ( $ utfresult === false ) { JError :: raiseWarning ( 100 , JText :: sprintf ( 'JLIB_INSTALLER_ERROR_MOD_UNINSTALL_SQL_ERROR' , $ db -> stderr ( true ) ) ) ; $ retval = false ; } $ query = $ db -> getQuery ( true ) ; $ query -> delete ( ) -> from ( '#__schemas' ) -> where ( 'extension_id = ' . $ row -> extension_id ) ; $ db -> setQuery ( $ query ) ; $ db -> Query ( ) ; $ this -> parent -> removeFiles ( $ this -> manifest -> media ) ; $ this -> parent -> removeFiles ( $ this -> manifest -> languages , $ row -> client_id ) ; $ query = 'SELECT `id`' . ' FROM `#__modules`' . ' WHERE module = ' . $ db -> Quote ( $ row -> element ) . ' AND client_id = ' . ( int ) $ row -> client_id ; $ db -> setQuery ( $ query ) ; try { $ modules = $ db -> loadColumn ( ) ; } catch ( JException $ e ) { $ modules = array ( ) ; } if ( count ( $ modules ) ) { JArrayHelper :: toInteger ( $ modules ) ; $ modID = implode ( ',' , $ modules ) ; $ query = 'DELETE' . ' FROM #__modules_menu' . ' WHERE moduleid IN (' . $ modID . ')' ; $ db -> setQuery ( $ query ) ; try { $ db -> query ( ) ; } catch ( JException $ e ) { JError :: raiseWarning ( 100 , JText :: sprintf ( 'JLIB_INSTALLER_ERROR_MOD_UNINSTALL_EXCEPTION' , $ db -> stderr ( true ) ) ) ; $ retval = false ; } $ query = 'DELETE' . ' FROM #__modules' . ' WHERE id IN (' . $ modID . ')' ; $ db -> setQuery ( $ query ) ; try { $ db -> query ( ) ; } catch ( JException $ e ) { JError :: raiseWarning ( 100 , JText :: sprintf ( 'JLIB_INSTALLER_ERROR_MOD_UNINSTALL_EXCEPTION' , $ db -> stderr ( true ) ) ) ; $ retval = false ; } } $ row -> delete ( $ row -> extension_id ) ; $ query = 'DELETE FROM `#__modules` WHERE module = ' . $ db -> Quote ( $ row -> element ) . ' AND client_id = ' . $ row -> client_id ; $ db -> setQuery ( $ query ) ; try { $ db -> Query ( ) ; } catch ( JException $ e ) { } unset ( $ row ) ; if ( ! JFolder :: delete ( $ this -> parent -> getPath ( 'extension_root' ) ) ) { $ retval = false ; } return $ retval ; }
Custom uninstall method
 @param   integer  $id  The id of the module to uninstall
Custom uninstall method @param integer $id The id of the module to uninstall
// Initialise variables. // First order of business will be to load the module object table from the database. // This should give us the necessary information to proceed. // Is the module we are trying to uninstall a core one?
 // Because that is not a good idea... // Get the extension root path // Get the package manifest objecct // We do findManifest to avoid problem when uninstalling a list of extensions: getManifest cache its manifest file // Attempt to load the language file; might have uninstall strings // If there is an manifest class file, let's load it // Load the file // Set the class name // Create a new instance // And set this so we can copy it later // Note: if we don't find the class, don't bother to copy the file // Run uninstall if possible // Make sure we delete the folders /*
		 * Let's run the uninstall queries for the component
		 *	If Joomla 1.5 compatible, with discreet sql files - execute appropriate
		 *	file for utf-8 support or non-utf support
		 */ // Try for Joomla 1.5 type queries // Second argument is the utf compatible version attribute // Install failed, rollback changes // Remove the schema version // Remove other files // Let's delete all the module copies for the type we are uninstalling // Do we have any module copies?
 // Ensure the list is sane // Wipe out any items assigned to menus // Wipe out any instances in the modules table // Now we will no longer need the module object, so lets delete it and free up memory // clean up any other ones that might exist as well //Ignore the error... // Remove the installation folder // JFolder should raise an error