- Модуль: disk
- Путь к файлу: ~/bitrix/modules/disk/lib/controller/onlyoffice.php
- Класс: BitrixDiskControllerOnlyOffice
- Вызов: OnlyOffice::saveDocument
protected function saveDocument(ModelsDocumentSession $documentSession, array $payloadData): bool
{
if (!in_array($payloadData['status'], [
self::STATUS_IS_READY_FOR_SAVE,
self::STATUS_FORCE_SAVE,
self::STATUS_ERROR_WHILE_SAVING,
self::STATUS_ERROR_WHILE_FORCE_SAVING,
], true))
{
return false;
}
if (in_array($payloadData['status'], [
self::STATUS_IS_READY_FOR_SAVE,
self::STATUS_ERROR_WHILE_SAVING,
], true))
{
AddEventToStatFile(
'disk',
'disk_oo_doc_closed',
$documentSession->getExternalHash(),
ServiceLocator::getInstance()->get('disk.onlyofficeConfiguration')->getServer(),
'with_changes',
0
);
}
if (empty($payloadData['url']))
{
$this->addError(new Error("Could not find 'url' in payload. Status: {$payloadData['status']}"));
return false;
}
if (!$documentSession->getObject())
{
$this->addError(new Error('Could not find file.'));
return false;
}
$fileDownloader = new DocumentOnlyOfficeFileDownloader($payloadData['url']);
$downloadResult = $fileDownloader->download();
if ($downloadResult->isSuccess())
{
$tmpFile = $downloadResult->getData()['file'];
$tmpFileArray = CFile::makeFileArray($tmpFile);
if ($tmpFileArray['type'] === 'application/encrypted')
{
$tmpFileArray['type'] = MimeType::getByFilename($documentSession->getObject()->getName());
}
$payloadData['users'] = $payloadData['users'] ?? [$documentSession->getUserId()];
if (!is_array($payloadData['users']))
{
$payloadData['users'] = [$payloadData['users']];
}
$options = ['commentAttachedObjects' => false];
if ($documentSession->getObject()->uploadVersion($tmpFileArray, $payloadData['users'][0], $options))
{
$this->sendEventToParticipants($documentSession->getExternalHash(), 'saved');
return true;
}
}
return false;
}