API16:JInstallerFile/uninstall
From Joomla! Documentation
Description
Custom uninstall method
<! removed transcluded page call, red link never existed >
Syntax
uninstall($id)
Parameter Name | Default Value | Description |
---|---|---|
$id | $id The id of the file to uninstall |
Returns
boolean True on success
Defined in
libraries/joomla/installer/adapters/file.php
Importing
jimport( 'joomla.installer.adapters.file' );
Source Body
function uninstall($id)
{
// Initialise variables.
$row = JTable::getInstance('extension');
if(!$row->load($id)) {
JError::raiseWarning(100, JText::_('File').' '.JText::_('Uninstall').': '.JText::_('Could not load extension entry'));
return false;
}
$retval = true;
$manifestFile = JPATH_MANIFESTS.DS.'files' . DS . $row->element .'.xml';
// Because files may not have their own folders we cannot use the standard method of finding an installation manifest
if (file_exists($manifestFile))
{
// Set the plugin root path
$this->parent->setPath('extension_root', JPATH_ROOT); //.DS.'files'.DS.$manifest->filename);
$xml =JFactory::getXML($manifestFile);
// If we cannot load the xml file return null
if( ! $xml) {
JError::raiseWarning(100, JText::_('File').' '.JText::_('Uninstall').': '.JText::_('Could not load manifest file'));
return false;
}
/*
* Check for a valid XML root tag.
*/
if ($xml->getName() != 'extension') {
JError::raiseWarning(100, JText::_('File').' '.JText::_('Uninstall').': '.JText::_('Invalid manifest file'));
return false;
}
$this->manifest = $xml;
// Set root folder names
$packagePath = $this->parent->getPath('source');
$jRootPath = JPath::clean(JPATH_ROOT);
// loop through all elements and get list of files and folders
foreach ($xml->fileset->files as $eFiles)
{
$folder = (string)$eFiles->attributes()->folder;
$target = (string)$eFiles->attributes()->target;
//Create folder path
if(empty($target))
{
$targetFolder = JPATH_ROOT;
}
else
{
$targetFolder = JPATH_ROOT.DS.$target;
}
$folderList = array();
// Check if all children exists
if (count($eFiles->children()) > 0)
{
// loop through all filenames elements
foreach ($eFiles->children() as $eFileName)
{
if ($eFileName->getName() == 'folder') {
$folderList[] = $targetFolder.DS.$eFileName;
} else {
$fileName = $targetFolder.DS.$eFileName;
JFile::delete($fileName);
}
}
}
// Delete any folders that don't have any content in them
foreach($folderList as $folder)
{
$files = JFolder::files($folder);
if(!count($files)) {
JFolder::delete($folder);
}
}
}
JFile::delete($manifestFile);
} else {
JError::raiseWarning(100, 'File Uninstall: Manifest File invalid or not found');
// delete the row because its broken
$row->delete();
return false;
}
$this->parent->removeFiles($xml->languages);
$row->delete();
return $retval;
}
<! removed transcluded page call, red link never existed >
Examples
Code Examples