API15

Difference between revisions of "JInstaller/copyFiles"

From Joomla! Documentation

< API15:JInstaller
(New page: ===Description=== Copy files from source directory to the target directory <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>[[Description:JInstaller/copyFiles|Edit ...)
 
m (preparing for archive only)
 
(One intermediate revision by the same user not shown)
Line 3: Line 3:
  
 
<span class="editsection" style="font-size:76%;">
 
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[Description:JInstaller/copyFiles|Edit Descripton]]<nowiki>]</nowiki>
+
<nowiki>[<! removed edit link to red link >]</nowiki>
 
</span>
 
</span>
  
{{Description:JInstaller/copyFiles}}
+
<! removed transcluded page call, red link never existed >
  
 
===Syntax===
 
===Syntax===
Line 122: Line 122:
  
 
<span class="editsection" style="font-size:76%;">
 
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[SeeAlso:JInstaller/copyFiles|Edit See Also]]<nowiki>]</nowiki>
+
<nowiki>[<! removed edit link to red link >]</nowiki>
 
</span>
 
</span>
{{SeeAlso:JInstaller/copyFiles}}
+
<! removed transcluded page call, red link never existed >
  
 
===Examples===
 
===Examples===
<CodeExamplesForm />
+
=== Code Examples ===
 
<dpl>
 
<dpl>
 
  noresultsheader=\n
 
  noresultsheader=\n
 
  category=copyFiles
 
  category=copyFiles
 
  category=JInstaller
 
  category=JInstaller
  category=CodeExample
+
  namespace=CodeExample
 
  category=MethodExample
 
  category=MethodExample
 
  include=*
 
  include=*
 
  format= ,,,
 
  format= ,,,
 
</dpl>
 
</dpl>
 +
[[Category:Archived pages API15]]

Latest revision as of 19:52, 24 March 2017

The "API15" 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]

Copy files from source directory to the target directory

[<! removed edit link to red link >]

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

Syntax[edit]

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[edit]

boolean True on success

Defined in[edit]

libraries/joomla/installer/installer.php

Importing[edit]

jimport( 'joomla.installer.installer' );

Source Body[edit]

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))) {
                                                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[edit]

Code Examples[edit]