API16

JInstallerFile/populateFilesAndFolderList

From Joomla! Documentation

< API16:JInstallerFile
Revision as of 17:39, 22 March 2010 by Doxiki (talk | contribs) (New page: ===Description=== function used to populate files and folder list <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>[[Description:JInstallerFile/populateFilesAndFold...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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]

function used to populate files and folder list

[Edit Descripton]

Template:Description:JInstallerFile/populateFilesAndFolderList

Syntax[edit]

populateFilesAndFolderList()


Returns[edit]

boolean none

Defined in[edit]

libraries/joomla/installer/adapters/file.php

Importing[edit]

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

Source Body[edit]

private function populateFilesAndFolderList()
{

        // Initialise variable
        $this->folderList = array();
        $this->fileList = array();

        // Get fileset
        $eFileset = $this->manifest->fileset->files;

        // 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 ($this->manifest->fileset->files as $eFiles)
        {
                // Check if the element is files element
                $folder = (string)$eFiles->attributes()->folder;
                $target = (string)$eFiles->attributes()->target;

                //Split folder names into array to get folder names. This will
                // help in creating folders
                $arrList = split("/|\\/", $target);

                $folderName = $jRootPath;
                foreach ($arrList as $dir)
                {
                        if(empty($dir)) continue ;

                        $folderName .= DS.$dir;
                        // Check if folder exists, if not then add to the array for folder creation
                        if (!JFolder::exists($folderName)) {
                                array_push($this->folderList, $folderName);
                        }
                }


                //Create folder path
                $sourceFolder = empty($folder)?$packagePath:$packagePath.DS.$folder;
                $targetFolder = empty($target)?$jRootPath:$jRootPath.DS.$target;

                //Check if source folder exists
                if (! JFolder::exists($sourceFolder)) {
                        JError::raiseWarning(1, JText::_('Files').' '.JText::_('Install').': '.JText::_('Failed to find source directory').': "'.$sourceFolder.'"');
                        // if installation fails, rollback
                        $this->parent->abort();
                        return false;
                }

                // Check if all children exists
                if (count($eFiles->children()))
                {
                        // loop through all filenames elements
                        foreach ($eFiles->children() as $eFileName)
                        {
                                $path['src'] = $sourceFolder.DS.$eFileName;
                                $path['dest'] = $targetFolder.DS.$eFileName;
                                $path['type'] = 'file';
                                if ($eFileName->getName() == 'folder') {
                                        $folderName = $targetFolder.DS.$eFileName;
                                        array_push($this->folderList, $folderName);
                                        $path['type'] = 'folder';
                                }

                                array_push($this->fileList, $path);
                        }
                } else {
                        $files = JFolder::files($sourceFolder);
                        foreach ($files as $file) {
                                $path['src'] = $sourceFolder.DS.$file;
                                $path['dest'] = $targetFolder.DS.$file;

                                array_push($this->fileList, $path);
                        }

                }
        }
}

[Edit See Also] Template:SeeAlso:JInstallerFile/populateFilesAndFolderList

Examples[edit]

<CodeExamplesForm />