Back to FileAdapter class

Method populateFilesAndFolderList

protected bool
populateFilesAndFolderList
()
Function used to populate files and folder list
Returns
  • bool none
Since
  • 3.1
Class: FileAdapter
Project: Joomla

Method populateFilesAndFolderList - Source code

/**
 * Function used to populate files and folder list
 *
 * @return  boolean  none
 *
 * @since   3.1
 */
protected function populateFilesAndFolderList()
{
    // Initialise variable
    $this->folderList = array();
    $this->fileList = array();
    // Set root folder names
    $packagePath = $this->parent->getPath('source');
    $jRootPath = Path::clean(JPATH_ROOT);
    // Loop through all elements and get list of files and folders
    foreach ($this->getManifest()->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 = preg_split("#/|\\/#", $target);
        $folderName = $jRootPath;
        foreach ($arrList as $dir) {
            if (empty($dir)) {
                continue;
            }
            $folderName .= '/' . $dir;
            // Check if folder exists, if not then add to the array for folder creation
            if (!Folder::exists($folderName)) {
                $this->folderList[] = $folderName;
            }
        }
        // Create folder path
        $sourceFolder = empty($folder) ? $packagePath : $packagePath . '/' . $folder;
        $targetFolder = empty($target) ? $jRootPath : $jRootPath . '/' . $target;
        // Check if source folder exists
        if (!Folder::exists($sourceFolder)) {
            Log::add(Text::sprintf('JLIB_INSTALLER_ABORT_FILE_INSTALL_FAIL_SOURCE_DIRECTORY', $sourceFolder), Log::WARNING, 'jerror');
            // 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 . '/' . $eFileName;
                $path['dest'] = $targetFolder . '/' . $eFileName;
                $path['type'] = 'file';
                if ($eFileName->getName() === 'folder') {
                    $folderName = $targetFolder . '/' . $eFileName;
                    $this->folderList[] = $folderName;
                    $path['type'] = 'folder';
                }
                $this->fileList[] = $path;
            }
        } else {
            $files = Folder::files($sourceFolder);
            foreach ($files as $file) {
                $path['src'] = $sourceFolder . '/' . $file;
                $path['dest'] = $targetFolder . '/' . $file;
                $this->fileList[] = $path;
            }
        }
    }
}