Ejemplo n.º 1
0
 /**
  * @param                $name
  * @param                $targetDirectoryId
  * @param CWebDavTmpFile $tmpFile
  * @return array|boolean
  */
 public function addFile($name, $targetDirectoryId, CWebDavTmpFile $tmpFile)
 {
     if (!$targetDirectoryId) {
         $folder = $this->storage->getRootObject();
     } else {
         $folder = Folder::loadById($targetDirectoryId);
     }
     if (!$folder) {
         $this->errorCollection->add(array(new Error("Could not " . __METHOD__ . " by id {$targetDirectoryId}", 11152)));
         throw new WebDavStorageBreakDownException('bd addFile could not find folder');
     }
     if (!$folder->canAdd($this->storage->getCurrentUserSecurityContext())) {
         throw new CWebDavAccessDeniedException();
     }
     $fileArray = CFile::MakeFileArray($tmpFile->getAbsolutePath());
     $fileArray['name'] = $name;
     $fileModel = $folder->uploadFile($fileArray, array('NAME' => $name, 'CREATED_BY' => $this->getUser()->getId()));
     if ($fileModel) {
         $this->loadFormattedFolderTreeAndBreadcrumbs();
         return $this->formatFileToResponse($fileModel);
     }
     $this->errorCollection->add(array(new Error("Could not " . __METHOD__ . ", uploadFile to {$targetDirectoryId}", 11153)));
     $this->errorCollection->add($folder->getErrors());
     throw new WebDavStorageBreakDownException('bd addFile');
 }
Ejemplo n.º 2
0
 /**
  * @param         $name
  * @param         $targetDirectoryId
  * @param TmpFile $tmpFile
  * @param array   $data
  * @return array
  * @throws AccessDeniedException
  */
 public function addFile($name, $targetDirectoryId, TmpFile $tmpFile, array $data = array())
 {
     if (!$targetDirectoryId) {
         $folder = $this->storage->getRootObject();
     } else {
         $folder = Folder::loadById($targetDirectoryId);
     }
     /** @var Folder $folder */
     if (!$folder) {
         $this->errorCollection->add(array(new Error("Could not " . __METHOD__ . " by id {$targetDirectoryId}", 11152)));
         $tmpFile->delete();
         return array();
     }
     if (!$folder->canAdd($this->storage->getCurrentUserSecurityContext())) {
         $tmpFile->delete();
         throw new AccessDeniedException();
     }
     /** @var array $fileArray */
     if ($tmpFile->isCloud() && $tmpFile->getContentType()) {
         /** @noinspection PhpDynamicAsStaticMethodCallInspection */
         $fileId = \CFile::saveFile(array('name' => $tmpFile->getFilename(), 'tmp_name' => $tmpFile->getAbsolutePath(), 'type' => $tmpFile->getContentType()), Driver::INTERNAL_MODULE_ID, true, true);
         if (!$fileId) {
             $this->errorCollection->add(array(new Error("Could not " . __METHOD__ . ", save cloud file", 111588)));
             return array();
         }
         /** @noinspection PhpDynamicAsStaticMethodCallInspection */
         $fileArray = \CFile::getFileArray($fileId);
         if (!$fileArray) {
             $this->errorCollection->add(array(new Error("Could not " . __METHOD__ . ", getFileArray", 191588)));
             return array();
         }
         $fileData = array('NAME' => Ui\Text::correctFilename($name), 'FILE_ID' => $fileId, 'SIZE' => !isset($data['SIZE']) ? $fileArray['FILE_SIZE'] : $data['SIZE'], 'CREATED_BY' => $this->getUser()->getId());
         if (!empty($data['originalTimestamp'])) {
             $fileData['UPDATE_TIME'] = DateTime::createFromTimestamp($this->convertFromExternalVersion($data['originalTimestamp']));
         }
         $fileModel = $folder->addFile($fileData);
         if (!$fileModel) {
             \CFile::delete($fileId);
         }
     } else {
         $fileArray = \CFile::makeFileArray($tmpFile->getAbsolutePath());
         $fileArray['name'] = $name;
         $fileData = array('NAME' => $name, 'CREATED_BY' => $this->getUser()->getId());
         if (!empty($data['originalTimestamp'])) {
             $fileData['UPDATE_TIME'] = DateTime::createFromTimestamp($this->convertFromExternalVersion($data['originalTimestamp']));
         }
         $fileModel = $folder->uploadFile($fileArray, $fileData);
     }
     if ($fileModel) {
         $tmpFile->delete();
         $this->loadFormattedFolderTreeAndBreadcrumbs();
         return $this->formatFileToResponse($fileModel);
     }
     $this->errorCollection->add(array(new Error("Could not " . __METHOD__ . ", uploadFile to {$targetDirectoryId}", 11153)));
     $this->errorCollection->add($folder->getErrors());
     $tmpFile->delete();
     return array();
 }
Ejemplo n.º 3
0
 public static function connectGroupToSelfUserStorage($userId, Storage $storage, ErrorCollection $errorCollection)
 {
     return self::connectToUserStorage($userId, array('SELF_CONNECT' => true, 'CREATED_BY' => $userId, 'LINK_NAME' => Ui\Text::correctFolderName($storage->getProxyType()->getEntityTitle()), 'REAL_OBJECT' => $storage->getRootObject()), $errorCollection);
 }