Actions

API16

JInstallerPackage/uninstall

From Joomla! Documentation

< API16:JInstallerPackage
Revision as of 17:53, 22 March 2010 by Doxiki (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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.

Contents

Description

Custom uninstall method

[Edit Descripton]

Description:JInstallerPackage/uninstall

Syntax

uninstall($id)
Parameter Name Default Value Description
$id $id The id of the package to uninstall

Returns

boolean True on success

Defined in

libraries/joomla/installer/adapters/package.php

Importing

jimport( 'joomla.installer.adapters.package' );

Source Body

function uninstall($id)
{
        // Initialise variables.
        $row    = null;
        $retval = true;
 
        $row = & JTable::getInstance('extension');
        $row->load($id);
 
        $manifestFile = JPATH_MANIFESTS.DS.'packages' . DS . $row->get('element') .'.xml';
        $manifest = new JPackageManifest($manifestFile);
 
        // Set the plugin root path
        $this->parent->setPath('extension_root', JPATH_MANIFESTS.DS.'packages'.DS.$manifest->packagename);
 
        // Because libraries may not have their own folders we cannot use the standard method of finding an installation manifest
        if (file_exists($manifestFile))
        {
                $xml =JFactory::getXML($manifestFile);
 
                // If we cannot load the xml file return false
                if (!$xml)
                {
                        JError::raiseWarning(100, JText::_('Package').' '.JText::_('Uninstall').': '.JText::_('Could not load manifest file'));
                        return false;
                }
 
                /*
                 * Check for a valid XML root tag.
                 * @todo: Remove backwards compatability in a future version
                 * Should be 'extension', but for backward compatability we will accept 'install'.
                 */
                if ($xml->getName() != 'install' && $xml->getName() != 'extension')
                {
                        JError::raiseWarning(100, JText::_('Package').' '.JText::_('Uninstall').': '.JText::_('Invalid manifest file'));
                        return false;
                }
 
                $error = false;
                foreach ($manifest->filelist as $extension)
                {
                        $tmpInstaller = new JInstaller();
                        $id = $this->_getExtensionID($extension->type, $extension->id, $extension->client, $extension->group);
                        $client = JApplicationHelper::getClientInfo($extension->client,true);
                        if (!$tmpInstaller->uninstall($extension->type, $id, $client->id))
                        {
                                $error = true;
                                JError::raiseWarning(100, JText::_('Package').' '.JText::_('Uninstall').': '.
//                                                      JText::_('There was an error removing an extension!') . ' ' .
                                                JText::_('This extension may have already been uninstalled or might not have been uninstall properly') .': ' .
                                                basename($extension->filename));
                                //$this->parent->abort(JText::_('Package').' '.JText::_('Uninstall').': '.JText::_('There was an error removing an extension, try reinstalling:') . basename($extension->filename));
                                //return false;
                        }
                }
                $this->parent->removeFiles($xml->languages);
                // clean up manifest file after we're done if there were no errors
                if (!$error) {
                        JFile::delete($manifestFile);
                }
                else {
                        JError::raiseWarning(100, JText::_('Package'). ' ' . JText::_('Uninstall'). ': '.
                                JText::_('Errors were detected, manifest file not removed!'));
                }
        }
        else
        {
                JError::raiseWarning(100, JText::_('Package').' '.JText::_('Uninstall').': '.
                        JText::_('Manifest File invalid or not found') . $id);
                return false;
        }
 
        return $retval;
}

[Edit See Also] SeeAlso:JInstallerPackage/uninstall

Examples

<CodeExamplesForm />