Actions

API15

JInstaller/removeFiles

From Joomla! Documentation

< API15:JInstaller
Revision as of 13:32, 12 May 2013 by JoomlaWikiBot (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

Method to parse through a files element of the installation manifest and remove the files that were installed

[<! removed edit link to red link >]

<! removed transcluded page call, red link never existed >

Syntax

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

boolean True on success

Defined in

libraries/joomla/installer/installer.php

Importing

jimport( 'joomla.installer.installer' );

Source Body

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;
}

[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >

Examples

<CodeExamplesForm />