34 public static function run($activityId, $recordingId, $siteId = SITE_ID, $attempt = 0)
36 $recordingFields = ZoomMeetingRecordingTable::getRowById($recordingId);
37 if (!is_array($recordingFields))
42 $attachResult = static::attach($activityId, $recordingFields, $siteId);
43 if ($attachResult->isSuccess())
49 if ($attempt > static::MAX_ATTEMPTS)
54 return static::class.
"::run({$activityId}, {$recordingId}, '{$siteId}', {$attempt});";
57 public static function attach($activityId, array $recordingFields, $siteId = SITE_ID)
61 $validSymbolsPattern =
'/^[a-z0-9\-]+$/i';
62 if (!preg_match($validSymbolsPattern, $recordingFields[
'EXTERNAL_ID']))
64 return $result->addError(
new Error(
'Can not create recording file name, external_id contains invalid symbols'));
66 if (!preg_match($validSymbolsPattern, $recordingFields[
'FILE_TYPE']))
68 return $result->addError(
new Error(
'Can not create recording file name, external_id contains invalid symbols'));
70 if (!Loader::includeModule(
'crm'))
72 return $result->addError(
new Error(
'CRM module is not installed'));
74 $fileName = mb_strtolower(
"{$recordingFields['EXTERNAL_ID']}.{$recordingFields['FILE_TYPE']}");
75 $downloadResult = static::download($recordingFields[
'DOWNLOAD_URL'], $recordingFields[
'DOWNLOAD_TOKEN'], $fileName);
76 if(!$downloadResult->isSuccess())
78 return $result->addErrors($downloadResult->getErrors());
81 $activityFields = \CCrmActivity::GetByID($activityId,
false);
84 return $result->addError(
new Error(
'Activity is not found'));
86 $responsible = $activityFields[
'RESPONSIBLE_ID'];
88 $tempPath = $downloadResult->getData()[
'file'];
89 $recordFile = \CFile::MakeFileArray($tempPath, $recordingFields[
'FILE_TYPE']);
90 $recordFile[
'MODULE_ID'] =
'crm';
91 $saveResult = DiskHelper::saveFile($recordFile, $responsible, $siteId);
93 if(!$saveResult->isSuccess())
95 return $result->addErrors($saveResult->getErrors());
98 $fileId = $saveResult->getData()[
'fileId'];
99 ZoomMeetingRecordingTable::update($recordingFields[
'ID'], [
103 $storageElementIds = \unserialize($activityFields[
'STORAGE_ELEMENT_IDS'], [
'allowed_classes' =>
false]) ?: [];
104 $storageElementIds[] = $fileId;
106 $activityFields[
'STORAGE_TYPE_ID'] = \Bitrix\Crm\Integration\StorageType::Disk;
107 $activityFields[
'STORAGE_ELEMENT_IDS'] = $storageElementIds;
109 $updateResult = \CCrmActivity::Update($activityId, $activityFields,
false);
112 return $result->addError(
new Error(\CCrmActivity::GetLastErrorMessage()));