API16:JInstaller/parseFiles
From Joomla! Documentation
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 take appropriate action.
[<! removed edit link to red link >]
<! removed transcluded page call, red link never existed >
Syntax
parseFiles($element, $cid=0, $oldFiles=null, $oldMD5=null)
| Parameter Name | Default Value | Description |
|---|---|---|
| $element | $element The xml node to process | |
| $cid | 0 | $cid Application ID of application to install to |
| $oldFiles | null | List of old files (JXMLElement's) |
| $oldMD5 | null | List of old MD5 sums (indexed by filename with value as MD5) |
Returns
boolean True on success
Defined in
libraries/joomla/installer/installer.php
Importing
jimport( 'joomla.installer.installer' );
Source Body
public function parseFiles($element, $cid=0, $oldFiles=null, $oldMD5=null) { // Get the array of file nodes to process; we checked this had children above if ( ! is_a($element, 'JXMLElement') || ! count($element->children())) { // Either the tag does not exist or has no children (hence no files to process) therefore we return zero files processed. return 0; } // Initialise variables. $copyfiles = array (); // Get the client info jimport('joomla.application.helper'); $client = &JApplicationHelper::getClientInfo($cid); /* * Here we set the folder we are going to remove the files from. */ if ($client) { $pathname = 'extension_'.$client->name; $destination = $this->getPath($pathname); } else { $pathname = 'extension_root'; $destination = $this->getPath($pathname); } /* * Here we set the folder we are going to copy the files from. * * Does the element have a folder attribute? * * If so this indicates that the files are in a subdirectory of the source * folder and we should append the folder attribute to the source path when * copying files. */ $folder = (string)$element->attributes()->folder; if ($folder && file_exists($this->getPath('source').DS.$folder)) { $source = $this->getPath('source').DS.$folder; } else { $source = $this->getPath('source'); } // Work out what files have been deleted if ($oldFiles && is_a($oldFiles, 'JXMLElement')) { $oldEntries = $oldFiles->children(); if (count($oldEntries)) { $deletions = $this->findDeletedFiles($oldEntries, $element); foreach ($deletions['folders'] as $deleted_folder) { JFolder::delete($destination.DS.$deleted_folder); } foreach ($deletions['files'] as $deleted_file) { JFile::delete($destination.DS.$deleted_file); } } } // Copy the MD5SUMS file if it exists if (file_exists($source.DS.'MD5SUMS')) { $path['src'] = $source.DS.'MD5SUMS'; $path['dest'] = $destination.DS.'MD5SUMS'; $path['type'] = 'file'; $copyfiles[] = $path; } // Process each file in the $files array (children of $tagName). foreach ($element->children() as $file) { $path['src'] = $source.DS.$file; $path['dest'] = $destination.DS.$file; // Is this path a file or folder? $path['type'] = ($file->getName() == 'folder') ? 'folder' : 'file'; /* * Before we can add a file to the copyfiles array we need to ensure * that the folder we are copying our file to exits and if it doesn't, * we need to create it. */ if (basename($path['dest']) != $path['dest']) { $newdir = dirname($path['dest']); if (!JFolder::create($newdir)) { JError::raiseWarning(1, 'JInstaller::install: '.JText::_('FAILED_TO_CREATE_DIRECTORY').' "'.$newdir.'"'); return false; } } // Add the file to the copyfiles array $copyfiles[] = $path; } return $this->copyFiles($copyfiles); }
[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >
Examples
<CodeExamplesForm />
