Ejemplo n.º 1
0
 public function execute(Request $request, ResourceTypeFactory $resourceTypeFactory, Acl $acl, EventDispatcher $dispatcher)
 {
     $copiedFiles = (array) $request->request->get('files');
     $copied = 0;
     $errors = array();
     // Initial validation
     foreach ($copiedFiles as $arr) {
         if (!isset($arr['name'], $arr['type'], $arr['folder'])) {
             throw new InvalidRequestException();
         }
         if (!$acl->isAllowed($arr['type'], $arr['folder'], Permission::FILE_VIEW)) {
             throw new UnauthorizedException();
         }
     }
     foreach ($copiedFiles as $arr) {
         if (empty($arr['name'])) {
             continue;
         }
         $name = $arr['name'];
         $type = $arr['type'];
         $folder = $arr['folder'];
         $resourceType = $resourceTypeFactory->getResourceType($type);
         $copiedFile = new CopiedFile($name, $folder, $resourceType, $this->app);
         $options = isset($arr['options']) ? $arr['options'] : '';
         $copiedFile->setCopyOptions($options);
         if ($copiedFile->isValid()) {
             $copyFileEvent = new CopyFileEvent($this->app, $copiedFile);
             $dispatcher->dispatch(CKFinderEvent::COPY_FILE, $copyFileEvent);
             if (!$copyFileEvent->isPropagationStopped()) {
                 if ($copiedFile->doCopy()) {
                     $copied++;
                 }
             }
         }
         $errors = array_merge($errors, $copiedFile->getErrors());
     }
     $data = array('copied' => $copied);
     if (!empty($errors)) {
         $data['error'] = array('number' => Error::COPY_FAILED, 'errors' => $errors);
     }
     return $data;
 }
Ejemplo n.º 2
0
 /**
  * Moves the current file.
  *
  * @return bool `true` if the file was moved successfully.
  *
  * @throws \Exception
  */
 public function doMove()
 {
     $originalFilePath = $this->getFilePath();
     $originalFileName = $this->getFilename();
     // Save original file name - it may be autorenamed when copied
     if (parent::doCopy()) {
         // Remove source file
         $this->deleteThumbnails();
         $this->resourceType->getResizedImageRepository()->deleteResizedImages($this->resourceType, $this->folder, $originalFileName);
         $this->getCache()->delete(Path::combine($this->resourceType->getName(), $this->folder, $originalFileName));
         return $this->resourceType->getBackend()->delete($originalFilePath);
     }
     return false;
 }