public function transferTo($filename)
 {
     if (!$this->isEmpty() && is_uploaded_file($this->tempName)) {
         if (@FileSystemUtils::safeCopy($this->tempName, $filename)) {
             return true;
         }
         if (@move_uploaded_file($this->tempName, $filename)) {
             return true;
         }
     }
     return FALSE;
 }
 /**
  * This function copies the file from the local path (specified in the {@link $file}) to the generated storage
  * path; creating any directories as needed.  The public URL will be set on the {@link $file} upon successful
  * persistence to the filesystem.
  *
  * @param Site                $site  Site used to determine storage location
  * @param StorageFacilityFile &$file File to store
  *
  * @return StorageFacilityFile Fully-resolved and stored file, has URL and id
  *                              set appropriately to reference the stored file later
  * @throws StorageFacilityException upon failure
  */
 public function putFile(StorageFacilityParams $params, StorageFacilityFile &$file)
 {
     $storagePath = $this->generateStoragePath($params, $file->getId());
     //        $this->createDirectory($storagePath);
     if (is_file($file->getLocalPath())) {
         try {
             FileSystemUtils::safeCopy($file->getLocalPath(), $storagePath);
         } catch (Exception $e) {
             throw new StorageFacilityException($e->getMessage());
         }
     } else {
         throw new StorageFacilityException("Local file not found '" . $file->getLocalPath() . "'");
     }
     $file->setLocalPath($storagePath);
     $file->setUrl($this->generateUrl($params, $file->getId()));
     return $file;
 }
 /**
  * Moves the file from the themes to the public app directory
  *
  * NOTE: the following code will overwrite files
  *
  * @param string $relpath  The relative path where the file lives
  * @param string $filename The file to move
  *
  * @return string the full path and filename of the moved file
  */
 public function putFile($relpath, $filename, $ts)
 {
     $basedir = $this->getBaseDeployDirectory() . $this->subject . '/';
     //move files from themes to public app directory
     $newfile = $basedir . $relpath;
     //        @FileSystemUtils::safeCopy($filename, $newfile);
     //        $ts = filemtime($filename);
     if (!file_exists($newfile) || $ts != filemtime($newfile)) {
         @FileSystemUtils::safeCopy($filename, $newfile);
         //@touch($newfile,$ts); //preserve original modified time
     }
     return new StorageFacilityFile('/' . ltrim($relpath, '/'), $newfile);
 }
 public function save()
 {
     if ($this->lockSystemChanges) {
         return;
     }
     if (!$this->changed) {
         return;
     }
     $xml = new SimpleXMLExtended('<system/>');
     $test = $xml->addChild('plugins');
     foreach ($this->plugins as $plugin) {
         $test->addXMLElement($this->SystemXMLConverter->pluginToXML($plugin));
     }
     $test = $xml->addChild('elements');
     foreach ($this->elements as $element) {
         $test->addXMLElement($this->SystemXMLConverter->elementToXML($element));
     }
     $test = $xml->addChild('aspects');
     foreach ($this->aspects as $aspect) {
         $test->addXMLElement($this->SystemXMLConverter->aspectToXML($aspect));
     }
     $test = $xml->addChild('cmsnavitems');
     foreach ($this->cmsNavItems as $navItem) {
         $test->addXMLElement($this->SystemXMLConverter->cmsNavItemToXML($navItem));
     }
     $newContents = $xml->asPrettyXML();
     $backup = $this->backupPath . '/system.' . $this->DateFactory->newStorageDate()->format('Y_m_d_His') . '.' . microtime(true) . '.xml';
     FileSystemUtils::safeCopy($this->systemXMLFile, $backup);
     FileSystemUtils::safeFilePutContents($this->systemXMLFile, $newContents);
     $this->ApplicationContext->clearContextFiles();
     $this->changed = false;
     $this->resetParsed();
 }
 /**
  * Writes the contents to the config file, after first
  * backing up the current config
  *
  * @param string $contents The contents to write to the config file
  *
  * @return void
  */
 public function saveContents($contents)
 {
     $path = pathinfo($this->configFileLocation);
     //BACKUP CURRENT config.php
     $backup = $this->backupPath . '/pluginconfig.' . date('Y_m_d_His') . '.php';
     FileSystemUtils::safeCopy($this->configFileLocation, $backup);
     //OVERWRITE config.php WITH POSTED CONTENTS
     FileSystemUtils::safeFilePutContents($this->configFileLocation, $contents);
     $this->VersionService->incrementDeploymentRevision('Saved config.php');
 }