Beispiel #1
0
 public function onBeforeFileAction(MOXMAN_Core_FileActionEventArgs $args)
 {
     switch ($args->getAction()) {
         case MOXMAN_Core_FileActionEventArgs::ADD:
             $args->setFile($this->renameFile($args->getFile()));
             break;
         case MOXMAN_Core_FileActionEventArgs::MOVE:
             $args->setTargetFile($this->renameFile($args->getTargetFile()));
             break;
     }
 }
Beispiel #2
0
 /** @ignore */
 private function copyFile($fromFile, $toFile)
 {
     $config = $toFile->getConfig();
     if ($config->get('general.demo')) {
         throw new MOXMAN_Exception("This action is restricted in demo mode.", MOXMAN_Exception::DEMO_MODE);
     }
     if (!$fromFile->exists()) {
         throw new MOXMAN_Exception("From file doesn't exist: " . $fromFile->getPublicPath(), MOXMAN_Exception::FILE_DOESNT_EXIST);
     }
     if (!$toFile->canWrite()) {
         throw new MOXMAN_Exception("No write access to file: " . $toFile->getPublicPath(), MOXMAN_Exception::NO_WRITE_ACCESS);
     }
     $filter = MOXMAN_Vfs_BasicFileFilter::createFromConfig($config);
     if ($filter->accept($fromFile, $fromFile->isFile()) !== MOXMAN_Vfs_BasicFileFilter::ACCEPTED) {
         throw new MOXMAN_Exception("Invalid file name for: " . $fromFile->getPublicPath(), MOXMAN_Exception::INVALID_FILE_NAME);
     }
     // Fire before file action event
     $args = new MOXMAN_Core_FileActionEventArgs(MOXMAN_Core_FileActionEventArgs::COPY, $fromFile);
     $args->setTargetFile($toFile);
     $args->getData()->fileSize = $fromFile->getSize();
     MOXMAN::getPluginManager()->get("core")->fire("BeforeFileAction", $args);
     $fromFile = $args->getFile();
     $toFile = $args->getTargetFile();
     // To file exists generate unique name
     $fileName = $toFile->getName();
     $ext = MOXMAN_Util_PathUtils::getExtension($fileName);
     for ($i = 2; $toFile->exists(); $i++) {
         if ($toFile->isFile() && $ext) {
             $toFile = MOXMAN::getFile($toFile->getParent(), basename($fileName, '.' . $ext) . '_' . $i . '.' . $ext);
         } else {
             $toFile = MOXMAN::getFile($toFile->getParent(), $fileName . '_' . $i);
         }
     }
     $fromFile->copyTo($toFile);
     $this->fireTargetFileAction(MOXMAN_Core_FileActionEventArgs::COPY, $fromFile, $toFile);
     return $toFile;
 }
Beispiel #3
0
 /**
  * Fires a before file action event with the specified from/to file objects.
  *
  * @param string $action Action name for the file event for example COPY.
  * @param MOXMAN_Vfs_IFile $fromFile From file to use.
  * @param MOXMAN_Vfs_IFile $toFile To file to use.
  * @return MOXMAN_Core_FileActionEventArgs Returns event argument instance.
  */
 protected function fireBeforeTargetFileAction($action, $fromFile, $toFile)
 {
     $args = new MOXMAN_Core_FileActionEventArgs($action, $fromFile);
     $args->setTargetFile($toFile);
     return MOXMAN::getPluginManager()->get("core")->fire("BeforeFileAction", $args);
 }