JInstaller/removeFiles
From Joomla! Documentation
< API15:JInstaller
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
The "API15" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.
Description[edit]
Method to parse through a files element of the installation manifest and remove the files that were installed
Template:Description:JInstaller/removeFiles
Syntax[edit]
removeFiles($element, $cid=0)
Parameter Name | Default Value | Description |
---|---|---|
$element | $element The xml node to process | |
$cid | 0 | $cid Application ID of application to remove from |
Returns[edit]
boolean True on success
Defined in[edit]
libraries/joomla/installer/installer.php
Importing[edit]
jimport( 'joomla.installer.installer' );
Source Body[edit]
function removeFiles($element, $cid=0)
{
// Initialize variables
$removefiles = array ();
$retval = true;
// Get the client info
jimport('joomla.application.helper');
$client =& JApplicationHelper::getClientInfo($cid);
if (!is_a($element, 'JSimpleXMLElement') || !count($element->children())) {
// Either the tag does not exist or has no children therefore we return zero files processed.
return true;
}
// Get the array of file nodes to process
$files = $element->children();
if (count($files) == 0) {
// No files to process
return true;
}
/*
* Here we set the folder we are going to remove the files from. There are a few
* special cases that need to be considered for certain reserved tags.
*/
switch ($element->name())
{
case 'media':
if ($element->attributes('destination')) {
$folder = $element->attributes('destination');
} else {
$folder = '';
}
$source = $client->path.DS.'media'.DS.$folder;
break;
case 'languages':
$source = $client->path.DS.'language';
break;
default:
if ($client) {
$pathname = 'extension_'.$client->name;
$source = $this->getPath($pathname);
} else {
$pathname = 'extension_root';
$source = $this->getPath($pathname);
}
break;
}
// Process each file in the $files array (children of $tagName).
foreach ($files as $file)
{
/*
* If the file is a language, we must handle it differently. Language files
* go in a subdirectory based on the language code, ie.
*
* <language tag="en_US">en_US.mycomponent.ini</language>
*
* would go in the en_US subdirectory of the languages directory.
*/
if ($file->name() == 'language' && $file->attributes('tag') != '') {
$path = $source.DS.$file->attributes('tag').DS.basename($file->data());
// If the language folder is not present, then the core pack hasn't been installed... ignore
if (!JFolder::exists(dirname($path))) {
continue;
}
} else {
$path = $source.DS.$file->data();
}
/*
* Actually delete the files/folders
*/
if (is_dir($path)) {
$val = JFolder::delete($path);
} else {
$val = JFile::delete($path);
}
if ($val === false) {
$retval = false;
}
}
return $retval;
}
[Edit See Also] Template:SeeAlso:JInstaller/removeFiles
Examples[edit]
<CodeExamplesForm />