- Модуль: im
- Путь к файлу: ~/bitrix/modules/im/classes/general/im_rest.php
- Класс: CIMRestService
- Вызов: CIMRestService::diskFileCommit
static function diskFileCommit($arParams, $n, CRestServer $server)
{
$arParams = array_change_key_case($arParams, CASE_UPPER);
if (isset($arParams['DIALOG_ID']))
{
if (BitrixImCommon::isDialogId($arParams['DIALOG_ID']))
{
$arParams['CHAT_ID'] = BitrixImDialog::getChatId($arParams['DIALOG_ID']);
}
else
{
throw new BitrixRestRestException("Dialog ID can't be empty", "DIALOG_ID_EMPTY", CRestServer::STATUS_WRONG_REQUEST);
}
}
$chatId = intval($arParams['CHAT_ID']);
if ($chatId <= 0)
{
throw new BitrixRestRestException("Chat ID can't be empty", "CHAT_ID_EMPTY", CRestServer::STATUS_WRONG_REQUEST);
}
$arParams['MESSAGE'] = trim($arParams['MESSAGE']);
if ($arParams['MESSAGE'] == '')
{
unset($arParams['MESSAGE']);
}
$arParams['SILENT_MODE'] = $arParams['SILENT_MODE'] == 'Y';
$chatRelation = CIMChat::GetRelationById($chatId, false, true, false);
if (!$chatRelation[CIMDisk::GetUserId()])
{
throw new BitrixRestRestException("You don't have access to this chat", "ACCESS_ERROR", CRestServer::STATUS_WRONG_REQUEST);
}
if (
CIMChat::GetGeneralChatId() == $chatId
&& !CIMChat::CanSendMessageToGeneralChat()
)
{
throw new BitrixRestRestException("Action unavailable", "ACCESS_ERROR", CRestServer::STATUS_FORBIDDEN);
}
$files = Array();
if (isset($arParams['FILE_ID']))
{
if (!is_array($arParams['FILE_ID']))
{
$arParams['FILE_ID'] = Array($arParams['FILE_ID']);
}
foreach ($arParams['FILE_ID'] as $fileId)
{
$files[$fileId] = 'disk'.$fileId;
}
}
else if (isset($arParams['DISK_ID']))
{
if (!is_array($arParams['DISK_ID']))
{
$arParams['DISK_ID'] = Array($arParams['DISK_ID']);
}
foreach ($arParams['DISK_ID'] as $fileId)
{
$files[$fileId] = 'disk'.$fileId;
}
if (isset($arParams['SYMLINK']))
{
$arParams['SYMLINK'] = $arParams['SYMLINK'] == 'Y';
}
}
else if (isset($arParams['UPLOAD_ID']))
{
if (!is_array($arParams['UPLOAD_ID']))
{
$arParams['UPLOAD_ID'] = Array($arParams['UPLOAD_ID']);
}
foreach ($arParams['UPLOAD_ID'] as $fileId)
{
$files[$fileId] = 'upload'.$fileId;
}
}
if (empty($files))
{
throw new BitrixRestRestException("List of files in not specified", "FILES_ERROR", CRestServer::STATUS_WRONG_REQUEST);
}
if (isset($arParams['TEMPLATE_ID']) && !empty($arParams['TEMPLATE_ID']))
{
$arParams['TEMPLATE_ID'] = mb_substr((string)$arParams['TEMPLATE_ID'], 0, 255);
}
if (isset($arParams['FILE_TEMPLATE_ID']) && !empty($arParams['FILE_TEMPLATE_ID']))
{
$arParams['FILE_TEMPLATE_ID'] = mb_substr((string)$arParams['FILE_TEMPLATE_ID'], 0, 255);
}
$result = CIMDisk::UploadFileFromDisk($chatId, array_values($files), $arParams['MESSAGE'], [
'LINES_SILENT_MODE' => $arParams['SILENT_MODE'],
'TEMPLATE_ID' => $arParams['TEMPLATE_ID']?:'',
'FILE_TEMPLATE_ID' => $arParams['FILE_TEMPLATE_ID']?:'',
'SYMLINK' => $arParams['SYMLINK']?:false,
'AS_FILE' => $arParams['AS_FILE'] ?? 'N',
]);
if (!$result)
{
throw new BitrixRestRestException("Error during saving file to chat", "SAVE_ERROR", CRestServer::STATUS_WRONG_REQUEST);
}
return $result;
}