Example #1
0
 public function uploadVersion(Entry $entry)
 {
     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;
     }
     /** @var File $file */
     $file = $entry->getObject();
     if (!$file) {
         $this->errorCollection->addOne(new Error('Could not get file from cloud import record'));
         return null;
     }
     $tmpFile = $entry->getTmpFile();
     $fileArray = \CFile::makeFileArray($tmpFile->getAbsolutePath());
     $version = $file->uploadVersion($fileArray, $this->documentHandler->getUserId());
     if (!$version) {
         $tmpFile->delete();
         $this->errorCollection->add($file->getErrors());
         return null;
     }
     $entry->linkVersion($version);
     return $version;
 }
Example #2
0
 protected function processActionUpdateAttachedObject()
 {
     $this->checkRequiredPostParams(array('cloudImportId', 'attachedId'));
     if ($this->errorCollection->hasErrors()) {
         $this->sendJsonErrorResponse();
     }
     $cloudImport = CloudImport\Entry::load(array('ID' => $this->request->getPost('cloudImportId'), 'USER_ID' => $this->getUser()->getId()), array('TMP_FILE'));
     if (!$cloudImport) {
         $this->errorCollection->addOne(new Error('Could not find cloud import', self::ERROR_COULD_NOT_FIND_CLOUD_IMPORT));
         $this->sendJsonErrorResponse();
     }
     $documentHandlersManager = Driver::getInstance()->getDocumentHandlersManager();
     $documentHandler = $documentHandlersManager->getHandlerByCode($cloudImport->getService());
     if (!$documentHandler) {
         $this->errorCollection->add($documentHandlersManager->getErrors());
         $this->sendJsonErrorResponse();
     }
     if (!$documentHandler->checkAccessibleTokenService()) {
         $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_UF_CONTROLLER_ERROR_COULD_NOT_WORK_WITH_TOKEN_SERVICE', array('#NAME#' => $documentHandler->getName())), self::ERROR_COULD_NOT_WORK_WITH_TOKEN_SERVICE)));
         $this->errorCollection->add($documentHandler->getErrors());
         $this->sendJsonErrorResponse();
     }
     if (!$documentHandler->queryAccessToken()->hasAccessToken() || $documentHandler->isRequiredAuthorization()) {
         $this->sendNeedAuth($documentHandler->getUrlForAuthorizeInTokenService('opener'));
     }
     /** @var AttachedObject $attachedModel */
     $attachedModel = AttachedObject::loadById((int) $this->request->getPost('attachedId'), array('OBJECT'));
     if (!$attachedModel) {
         $this->errorCollection->add(array(new Error('Could not find attached object')));
         $this->sendJsonErrorResponse();
     }
     if (!$attachedModel->canUpdate($this->getUser()->getId())) {
         $this->errorCollection->add(array(new Error("Bad permission. Could not update this file")));
         $this->sendJsonErrorResponse();
     }
     $importManager = new CloudImport\ImportManager($documentHandler);
     $version = $importManager->uploadVersion($cloudImport);
     if (!$version) {
         $this->errorCollection->add($importManager->getErrors());
         $this->sendJsonErrorResponse();
     }
     $this->sendJsonSuccessResponse();
 }
Example #3
0
 /**
  * Returns last cloud import entry of object.
  * @see Document\CloudImport\ImportManager, @see Document\CloudImport\Entry.
  * @return Document\CloudImport\Entry|
  */
 public function getLastCloudImportEntry()
 {
     if ($this->lastCloudImport === null) {
         $lastCloudImport = Document\CloudImport\Entry::getModelList(array('filter' => array('OBJECT_ID' => $this->getRealObjectId()), 'order' => array('ID' => 'DESC'), 'limit' => 1));
         if (!$lastCloudImport) {
             return null;
         }
         $this->lastCloudImport = array_pop($lastCloudImport);
     }
     return $this->lastCloudImport;
 }