示例#1
0
文件: DC_Folder.php 项目: eknoes/core
 /**
  * Recursively duplicate files and folders
  *
  * @param string $source
  * @param string $destination
  */
 public function copy($source = null, $destination = null)
 {
     if ($GLOBALS['TL_DCA'][$this->strTable]['config']['notCopyable']) {
         $this->log('Table "' . $this->strTable . '" is not copyable', __METHOD__, TL_ERROR);
         $this->redirect('contao/main.php?act=error');
     }
     $strFolder = \Input::get('pid', true);
     $blnDoNotRedirect = $source !== null;
     if ($source === null) {
         $source = $this->intId;
     }
     if ($destination === null) {
         $destination = str_replace(dirname($source), $strFolder, $source);
     }
     $this->isValid($source);
     $this->isValid($destination);
     if (!file_exists(TL_ROOT . '/' . $source) || !$this->isMounted($source)) {
         $this->log('File or folder "' . $source . '" was not mounted or could not be found', __METHOD__, TL_ERROR);
         $this->redirect('contao/main.php?act=error');
     }
     if (!file_exists(TL_ROOT . '/' . $strFolder) || !$this->isMounted($strFolder)) {
         $this->log('Parent folder "' . $strFolder . '" was not mounted or is not a directory', __METHOD__, TL_ERROR);
         $this->redirect('contao/main.php?act=error');
     }
     // Avoid a circular reference
     if (preg_match('/^' . preg_quote($source, '/') . '/i', $strFolder)) {
         $this->log('Attempt to copy the folder "' . $source . '" to "' . $strFolder . '" (circular reference)', __METHOD__, TL_ERROR);
         $this->redirect('contao/main.php?act=error');
     }
     // Empty clipboard
     $arrClipboard = $this->Session->get('CLIPBOARD');
     $arrClipboard[$this->strTable] = array();
     $this->Session->set('CLIPBOARD', $arrClipboard);
     $this->import('Files');
     // Copy folders
     if (is_dir(TL_ROOT . '/' . $source)) {
         $count = 1;
         $new = $destination;
         // Add a suffix if the folder exists
         while (is_dir(TL_ROOT . '/' . $new) && $count < 12) {
             $new = $destination . '_' . $count++;
         }
         $destination = $new;
         $this->Files->rcopy($source, $destination);
     } else {
         $count = 1;
         $new = $destination;
         $ext = strtolower(substr($destination, strrpos($destination, '.') + 1));
         // Add a suffix if the file exists
         while (file_exists(TL_ROOT . '/' . $new) && $count < 12) {
             $new = str_replace('.' . $ext, '_' . $count++ . '.' . $ext, $destination);
         }
         $destination = $new;
         $this->Files->copy($source, $destination);
     }
     // Update the database AFTER the file has been copied
     if ($this->blnIsDbAssisted) {
         $syncSource = \Dbafs::shouldBeSynchronized($source);
         $syncTarget = \Dbafs::shouldBeSynchronized($destination);
         if ($syncSource && $syncTarget) {
             \Dbafs::copyResource($source, $destination);
         } elseif ($syncTarget) {
             \Dbafs::addResource($destination);
         }
     }
     // Call the oncopy_callback
     if (is_array($GLOBALS['TL_DCA'][$this->strTable]['config']['oncopy_callback'])) {
         foreach ($GLOBALS['TL_DCA'][$this->strTable]['config']['oncopy_callback'] as $callback) {
             if (is_array($callback)) {
                 $this->import($callback[0]);
                 $this->{$callback[0]}->{$callback[1]}($source, $destination, $this);
             } elseif (is_callable($callback)) {
                 $callback($source, $destination, $this);
             }
         }
     }
     // Add a log entry
     $this->log('File or folder "' . $source . '" has been duplicated', __METHOD__, TL_FILES);
     // Redirect
     if (!$blnDoNotRedirect) {
         $this->redirect($this->getReferer());
     }
 }
示例#2
0
 /**
  * Copy the folder
  *
  * @param string $strNewName The target path
  *
  * @return boolean True if the operation was successful
  */
 public function copyTo($strNewName)
 {
     $strParent = dirname($strNewName);
     // Create the parent folder if it does not exist
     if (!is_dir(TL_ROOT . '/' . $strParent)) {
         new \Folder($strParent);
     }
     $this->Files->rcopy($this->strFolder, $strNewName);
     // Update the database AFTER the folder has been renamed
     $syncSource = \Dbafs::shouldBeSynchronized($this->strFolder);
     $syncTarget = \Dbafs::shouldBeSynchronized($strNewName);
     if ($syncSource && $syncTarget) {
         \Dbafs::copyResource($this->strFolder, $strNewName);
     } elseif ($syncTarget) {
         \Dbafs::addResource($strNewName);
     }
     return true;
 }
示例#3
0
 /**
  * Copy the folder
  *
  * @param string $strNewName The target path
  *
  * @return boolean True if the operation was successful
  */
 public function copyTo($strNewName)
 {
     $strParent = dirname($strNewName);
     // Create the parent folder if it does not exist
     if (!is_dir(TL_ROOT . '/' . $strParent)) {
         new \Folder($strParent);
     }
     $this->Files->rcopy($this->strFolder, $strNewName);
     // Update the database AFTER the folder has been renamed
     if ($this->blnSyncDb) {
         $this->objModel = \Dbafs::copyResource($this->strFolder, $strNewName);
     }
     return true;
 }
 /**
  * {@inheritDoc}
  */
 public function copy($pathOrUuid, $newpath)
 {
     $path = $this->convertToPath($pathOrUuid);
     $this->guardNoInvalidUuid($pathOrUuid, $path);
     $this->guardInUploadPath($path);
     $this->guardInUploadPath($newpath);
     if ($this->adapter->copy($path, $newpath)) {
         \Dbafs::copyResource($path, $newpath);
         return true;
     }
     return false;
 }