Exemple #1
1
 /**
  * Copies object to target folder.
  * @param Folder $targetFolder Target folder.
  * @param int    $updatedBy Id of user.
  * @param bool   $generateUniqueName Generates unique name for object in directory.
  * @return BaseObject|null
  */
 public function copyTo(Folder $targetFolder, $updatedBy, $generateUniqueName = false)
 {
     $this->errorCollection->clear();
     /** @noinspection PhpDynamicAsStaticMethodCallInspection */
     $forkFileId = \CFile::copyFile($this->getFileId(), true);
     if (!$forkFileId) {
         $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_FILE_MODEL_ERROR_COULD_NOT_COPY_FILE'), self::ERROR_COULD_NOT_COPY_FILE)));
         return null;
     }
     /** @noinspection PhpDynamicAsStaticMethodCallInspection */
     $fileArray = \CFile::getFileArray($forkFileId);
     $fileModel = $targetFolder->addFile(array('NAME' => $this->getName(), 'FILE_ID' => $forkFileId, 'SIZE' => $fileArray['FILE_SIZE'], 'CREATED_BY' => $updatedBy), array(), $generateUniqueName);
     if (!$fileModel) {
         $this->errorCollection->add($targetFolder->getErrors());
         return null;
     }
     return $fileModel;
 }
Exemple #2
0
 /**
  * Getting array of errors.
  * @return Error[]
  */
 public function getErrors()
 {
     return array_merge(parent::getErrors(), $this->getRealObject()->getErrors());
 }
Exemple #3
0
 protected function copyToInternal(Folder $targetFolder, $updatedBy, $generateUniqueName = false)
 {
     $newFolder = $targetFolder->addSubFolder(array('NAME' => $this->getName(), 'CREATED_BY' => $updatedBy), array(), $generateUniqueName);
     if (!$newFolder) {
         $this->errorCollection->add($targetFolder->getErrors());
         return null;
     }
     return $newFolder;
 }
 /**
  * Saves file in destination folder from entry of cloud import.
  * @param Entry  $entry Cloud import entry.
  * @param Folder $folder Destination folder.
  * @return \Bitrix\Disk\File|null New file object.
  */
 public function saveFile(Entry $entry, Folder $folder)
 {
     if (!$entry->getTmpFile()) {
         $this->errorCollection->addOne(new Error('Could not find cloud import', self::ERROR_COULD_NOT_FIND_CLOUD_IMPORT));
         return null;
     }
     if ($entry->getContentSize() != $entry->getDownloadedContentSize()) {
         $this->errorCollection->addOne(new Error('Content size != downloaded content size'));
         return null;
     }
     $fileData = new Document\FileData();
     $fileData->setId($entry->getServiceObjectId());
     $fileMetadata = $this->documentHandler->getFileMetadata($fileData);
     if (!$fileMetadata || empty($fileMetadata['name'])) {
         $this->errorCollection->add($this->documentHandler->getErrors());
         return null;
     }
     $name = $fileMetadata['name'];
     if (!getFileExtension($name)) {
         $name = $this->recoverExtensionInName($name, $fileMetadata['mimeType']);
     }
     $tmpFile = $entry->getTmpFile();
     $fileArray = \CFile::makeFileArray($tmpFile->getAbsolutePath());
     $file = $folder->uploadFile($fileArray, array('NAME' => $name, 'CREATED_BY' => $this->documentHandler->getUserId(), 'CONTENT_PROVIDER' => $this->documentHandler->getCode()), array(), true);
     if (!$file) {
         $tmpFile->delete();
         $this->errorCollection->add($folder->getErrors());
         return null;
     }
     $entry->linkObject($file);
     return $file;
 }