- Модуль: voximplant
- Путь к файлу: ~/bitrix/modules/voximplant/classes/general/vi_history.php
- Класс: CVoxImplantHistory
- Вызов: CVoxImplantHistory::DownloadAgent
static function DownloadAgent(int $historyID, string $recordUrl, $attachToCrm = true, $retryOnFailure = true): bool
{
$recordUrl = BitrixMainWebUri::urnDecode($recordUrl);
self::WriteToLog('Downloading record ' . $recordUrl);
$attachToCrm = ($attachToCrm === true);
if ($recordUrl == '' || $historyID <= 0)
{
return false;
}
$urlPath = parse_url($recordUrl, PHP_URL_PATH);
if ($urlPath)
{
$tempPath = CFile::GetTempName('', bx_basename($urlPath));
}
else
{
$tempPath = CFile::GetTempName('', bx_basename($recordUrl));
}
$http = VIHttpClientFactory::create(array(
"disableSslVerification" => true
));
try
{
$isDownloadSuccess = $http->download($recordUrl, $tempPath);
if (!$isDownloadSuccess)
{
self::DownloadAgentRequestErrorHandler($historyID, $recordUrl, $attachToCrm, $retryOnFailure, $http, "Call record download unsuccessful. Url: ");
return false;
}
if ($http->getStatus() !== 200)
{
self::DownloadAgentRequestErrorHandler($historyID, $recordUrl, $attachToCrm, $retryOnFailure, $http, "Call record download error. Url: ");
return false;
}
static::WriteToLog("Call record downloaded successfully. Url: " . $recordUrl);
$fileType = $http->getHeaders()->getContentType() ?: CFile::GetContentType($tempPath);
$recordFile = CFile::MakeFileArray($tempPath, $fileType);
if (is_array($recordFile) && $recordFile['size'] && $recordFile['size'] > 0)
{
if(mb_strpos($recordFile['name'], '.') === false)
{
$recordFile['name'] .= '.mp3';
}
$isCorrectFileResult = VISecurityRecordFile::isCorrectFromArray($recordFile);
if (!$isCorrectFileResult->isSuccess())
{
return false;
}
$history = VIStatisticTable::getById($historyID);
$arHistory = $history->fetch();
static::AttachRecord($arHistory['CALL_ID'], $recordFile);
}
}
catch (Exception $ex)
{
self::WriteToLog('Error caught during downloading record: ' . PHP_EOL . print_r($ex, true));
}
return false;
}