Пример #1
0
 protected function processActionPublish()
 {
     $onlineSession = $this->getOnlineEditSessionForFile();
     if ($onlineSession) {
         $forkSession = $onlineSession;
         if ($onlineSession->getOwnerId() != $this->getUser()->getId()) {
             $forkSession = $this->forkEditSessionForCurrentUser($onlineSession);
         }
         $this->sendJsonSuccessResponse(array('editSessionId' => $forkSession->getId(), 'id' => $onlineSession->getServiceFileId(), 'link' => $onlineSession->getServiceFileLink()));
     }
     $src = $this->getFileSrcToPublish();
     if (!$src) {
         $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_DOC_CONTROLLER_ERROR_COULD_NOT_GET_FILE'), self::ERROR_COULD_NOT_GET_FILE)));
         $this->sendJsonErrorResponse();
     }
     $fileData = new FileData();
     $fileData->setName($this->file->getName());
     $fileData->setMimeType(TypeFile::getMimeTypeByFilename($this->file->getName()));
     $fileData->setSrc($src);
     if (!$fileData->getSize()) {
         $fileData->setSize(filesize($fileData->getSrc()));
     }
     if ($fileData->getSize() === 0) {
         $fileData = $this->documentHandler->createBlankFile($fileData);
     } else {
         $fileData = $this->documentHandler->createFile($fileData);
     }
     if (!$fileData) {
         if ($this->documentHandler->isRequiredAuthorization()) {
             $this->sendNeedAuth();
         }
         $this->errorCollection->add($this->documentHandler->getErrors());
         $this->sendJsonErrorResponse();
     }
     //if somebody publish to google similar document
     $onlineSession = $this->getOnlineEditSessionForFile();
     if ($onlineSession) {
         $this->documentHandler->deleteFile($fileData);
         $forkSession = $onlineSession;
         if ($onlineSession->getOwnerId() != $this->getUser()->getId()) {
             $forkSession = $this->forkEditSessionForCurrentUser($onlineSession);
         }
         $this->sendJsonSuccessResponse(array('editSessionId' => $forkSession->getId(), 'id' => $onlineSession->getServiceFileId(), 'link' => $onlineSession->getServiceFileLink()));
     }
     $session = $this->addFileEditSessionByCurrentUser($fileData);
     $this->sendJsonSuccessResponse(array('editSessionId' => $session->getId(), 'id' => $fileData->getId(), 'link' => $fileData->getLinkInService()));
 }
Пример #2
0
 protected function processActionPublishBlank()
 {
     $this->checkRequiredGetParams(array('type'));
     if ($this->errorCollection->hasErrors()) {
         $this->sendJsonErrorResponse();
     }
     $fileData = new BlankFileData($this->request->getQuery('type'));
     $fileData = $this->documentHandler->createBlankFile($fileData);
     if (!$fileData) {
         if ($this->documentHandler->isRequiredAuthorization()) {
             $this->sendNeedAuth();
         }
         $this->errorCollection->add($this->documentHandler->getErrors());
         $this->sendJsonErrorResponse();
     }
     $session = $this->addCreateEditSessionByCurrentUser($fileData);
     if (!$session) {
         $this->sendJsonErrorResponse();
     }
     $this->sendJsonSuccessResponse(array('editSessionId' => $session->getId(), 'id' => $fileData->getId(), 'link' => $fileData->getLinkInService()));
 }