API16:JInstaller/copyFiles
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
Copy files from source directory to the target directory
[<! removed edit link to red link >]
<! removed transcluded page call, red link never existed >
Syntax
copyFiles($files, $overwrite=null)
| Parameter Name | Default Value | Description |
|---|---|---|
| $files | $files array with filenames | |
| $overwrite | null | $overwrite True if existing files can be replaced |
Returns
boolean True on success
Defined in
libraries/joomla/installer/installer.php
Importing
jimport( 'joomla.installer.installer' );
Source Body
public function copyFiles($files, $overwrite=null) { /* * To allow for manual override on the overwriting flag, we check to see if * the $overwrite flag was set and is a boolean value. If not, use the object * allowOverwrite flag. */ if (is_null($overwrite) || !is_bool($overwrite)) { $overwrite = $this->_overwrite; } /* * $files must be an array of filenames. Verify that it is an array with * at least one file to copy. */ if (is_array($files) && count($files) > 0) { foreach ($files as $file) { // Get the source and destination paths $filesource = JPath::clean($file['src']); $filedest = JPath::clean($file['dest']); $filetype = array_key_exists('type', $file) ? $file['type'] : 'file'; if (!file_exists($filesource)) { /* * The source file does not exist. Nothing to copy so set an error * and return false. */ JError::raiseWarning(1, 'JInstaller::install: '.JText::sprintf('File does not exist', $filesource)); return false; } elseif (file_exists($filedest) && !$overwrite) { /* * It's okay if the manifest already exists */ if ($this->getPath('manifest') == $filesource) { continue; } /* * The destination file already exists and the overwrite flag is false. * Set an error and return false. */ JError::raiseWarning(1, 'JInstaller::install: '.JText::sprintf('WARNSAME', $filedest)); return false; } else { // Copy the folder or file to the new location. if ($filetype == 'folder') { if (!(JFolder::copy($filesource, $filedest, null, $overwrite))) { JError::raiseWarning(1, 'JInstaller::install: '.JText::sprintf('Failed to copy folder to', $filesource, $filedest)); return false; } $step = array ('type' => 'folder', 'path' => $filedest); } else { if (!(JFile::copy($filesource, $filedest,null))) { JError::raiseWarning(1, 'JInstaller::install: '.JText::sprintf('Failed to copy file to', $filesource, $filedest)); return false; } $step = array ('type' => 'file', 'path' => $filedest); } /* * Since we copied a file/folder, we want to add it to the installation step stack so that * in case we have to roll back the installation we can remove the files copied. */ $this->_stepStack[] = $step; } } } else { /* * The $files variable was either not an array or an empty array */ return false; } return count($files); }
[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >
Examples
<CodeExamplesForm />
