Piwik\Filesystem::copy PHP Method

copy() public static method

Copies a file from $source to $dest.
public static copy ( string $source, string $dest, boolean $excludePhp = false ) : true
$source string A path to a file, eg. './tmp/latest/index.php'. The file must exist.
$dest string A path to a file, eg. './index.php'. The file does not have to exist.
$excludePhp boolean Whether to avoid copying files if the file is related to PHP (includes .php, .tpl, .twig files).
return true
    public static function copy($source, $dest, $excludePhp = false)
    {
        if ($excludePhp) {
            if (self::hasPHPExtension($source)) {
                return true;
            }
        }
        $success = self::tryToCopyFileAndVerifyItWasCopied($source, $dest);
        if (!$success) {
            $success = self::tryToCopyFileAndVerifyItWasCopied($source, $dest);
        }
        if (!$success) {
            throw new Exception("Error while creating/copying file from {$source} to <code>{$dest}</code>. Content of copied file is different.");
        }
        return true;
    }

Usage Example

示例#1
0
 private function oneClick_Copy()
 {
     /*
      * Make sure the execute bit is set for this shell script
      */
     if (!Rules::isBrowserTriggerEnabled()) {
         @chmod($this->pathRootExtractedPiwik . '/misc/cron/archive.sh', 0755);
     }
     $model = new Model();
     /*
      * Copy all files to PIWIK_INCLUDE_PATH.
      * These files are accessed through the dispatcher.
      */
     Filesystem::copyRecursive($this->pathRootExtractedPiwik, PIWIK_INCLUDE_PATH);
     $model->removeGoneFiles($this->pathRootExtractedPiwik, PIWIK_INCLUDE_PATH);
     /*
      * These files are visible in the web root and are generally
      * served directly by the web server.  May be shared.
      */
     if (PIWIK_INCLUDE_PATH !== PIWIK_DOCUMENT_ROOT) {
         /*
          * Copy PHP files that expect to be in the document root
          */
         $specialCases = array('/index.php', '/piwik.php', '/js/index.php');
         foreach ($specialCases as $file) {
             Filesystem::copy($this->pathRootExtractedPiwik . $file, PIWIK_DOCUMENT_ROOT . $file);
         }
         /*
          * Copy the non-PHP files (e.g., images, css, javascript)
          */
         Filesystem::copyRecursive($this->pathRootExtractedPiwik, PIWIK_DOCUMENT_ROOT, true);
         $model->removeGoneFiles($this->pathRootExtractedPiwik, PIWIK_DOCUMENT_ROOT);
     }
     /*
      * Config files may be user (account) specific
      */
     if (PIWIK_INCLUDE_PATH !== PIWIK_USER_PATH) {
         Filesystem::copyRecursive($this->pathRootExtractedPiwik . '/config', PIWIK_USER_PATH . '/config');
     }
     Filesystem::unlinkRecursive($this->pathRootExtractedPiwik, true);
     Filesystem::clearPhpCaches();
 }