- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/lib/controller/attachment/download.php
- Класс: Bitrix\Crm\Controller\Attachment\Download
- Вызов: Download::downloadArchiveAction
public function downloadArchiveAction(int $ownerTypeId, int $ownerId, array $fileIds)
{
$ownerTypeName = \CCrmOwnerType::ResolveName($ownerTypeId);
$ownerId = (int)$ownerId;
if ($ownerId <= 0 || !\CCrmOwnerType::IsDefined($ownerTypeId))
{
$this->addError(new Main\Error('Invalid data ownerTypeID = ' . $ownerTypeId . ', ownerID = ' . $ownerId));
return null;
}
if ($ownerTypeId !== \CCrmOwnerType::Activity)
{
$this->addError(new Main\Error("The owner type '{$ownerTypeName}' is not supported in current context"));
return null;
}
foreach ($fileIds as $fileId)
{
$isFileExists = false;
switch ($ownerTypeId)
{
case \CCrmOwnerType::Activity:
$isFileExists = \CCrmActivity::CheckStorageElementExists($ownerId, StorageType::Disk, $fileId);
break;
}
if (!$isFileExists)
{
$this->addError(new Main\Error('File not found'));
return null;
}
}
if (!\CCrmPerms::IsAdmin())
{
$isPermitted = false;
$userPermissions = \CCrmPerms::GetCurrentUserPermissions();
switch ($ownerTypeId)
{
case \CCrmOwnerType::Activity:
$bindings = \CCrmActivity::GetBindings($ownerId);
break;
default:
$bindings = [];
}
foreach ($bindings as $binding)
{
if (EntityAuthorization::checkReadPermission($binding['OWNER_TYPE_ID'], $binding['OWNER_ID'], $userPermissions))
{
$isPermitted = true;
break;
}
}
if (!$isPermitted)
{
$this->addError(new Main\Error('Access denied'));
return null;
}
}
return DiskManager::buildArchive('archive' . date('y-m-d') . '.zip', $fileIds);
}