API16

JInstaller/removeFiles

From Joomla! Documentation

< API16:JInstaller

The "API16" 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


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

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]

public function removeFiles($element, $cid=0)
{
        // Initialise variables.
        $removefiles = array ();
        $retval = true;

        // Get the client info if we're using a specific client
        jimport('joomla.application.helper');
        if ($cid > -1) {
                $client = &JApplicationHelper::getClientInfo($cid);
        }
        else {
                $client = null;
        }

        if (!($element instanceof JXMLElement) || !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;
        }

        $folder = '';

        /*
         * 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->getName())
        {
                case 'media':
                        if ((string)$element->attributes()->destination) {
                                $folder = (string)$element->attributes()->destination;
                        }
                        else {
                                $folder = '';
                        }
                        $source = $client->path.DS.'media'.DS.$folder;
                        break;

                case 'languages':
                        if ($client) {
                                $source = $client->path.DS.'language';
                        }
                        else {
                                $source = '';
                        }
                        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->getName() == 'language' && (string)$file->attributes()->tag != '')
                {
                        if ($source) {
                                $path = $source.DS.$file->attributes()->tag.DS.basename((string)$file);
                        }
                        else
                        {
                                $target_client = JApplicationHelper::getClientInfo((string)$file->attributes()->client, true);
                                $path = $target_client->path.DS.'language'.DS.$file->attributes()->tag.DS.basename((string)$file);
                        }

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

                /*
                 * Actually delete the files/folders
                 */
                if (is_dir($path)) {
                        $val = JFolder::delete($path);
                }
                else {
                        $val = JFile::delete($path);
                }

                if ($val === false)
                {
                        JError::raiseWarning(43, 'Failed to delete '. $path);
                        $retval = false;
                }
        }

        if (!empty($folder)) {
                $val = JFolder::delete($source);
        }

        return $retval;
}


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

Examples[edit]

Code Examples[edit]