• Модуль: disk
  • Путь к файлу: ~/bitrix/modules/disk/lib/document/documentcontroller.php
  • Класс: BitrixDiskDocumentDocumentController
  • Вызов: DocumentController::processActionPublish
protected function processActionPublish()
{
	if (Configuration::isEnabledObjectLock() && $this->file->getLock())
	{
		if (!$this->file->getLock()->canUnlock($this->getUser()->getId()))
		{
			$this->errorCollection->addOne($this->file->generateUnlockErrorByAnotherUser($this->file->getLock()));

			$this->sendJsonErrorResponse();
		}
	}

	$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(),
		));
	}
	elseif($this->documentHandler instanceof Office365Handler || $this->documentHandler instanceof GoogleHandler)
	{
		//todo refactor. Make the same for other handlers not only for onedrive, office365
		$showSession = $this->findShowSessionByCurrentUser();
		if($showSession)
		{
			$session = $this->createEditSessionFromShowSession($showSession);
			if($session)
			{
				$this->sendJsonSuccessResponse(array(
					'editSessionId' => $session->getId(),
					'id' => $session->getServiceFileId(),
					'link' => $session->getServiceFileLink(),
				));
			}
		}
	}
	$this->documentHandler->getErrorContainer()->clear();

	$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();
	}

	$this->trackDocument();

	//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(),
	));
}