- Модуль: main
- Путь к файлу: ~/bitrix/modules/main/lib/ui/viewer/transformation/transformermanager.php
- Класс: BitrixMainUIViewerTransformationTransformerManager
- Вызов: TransformerManager::transform
public function transform($fileId)
{
$result = new Result();
if (!Loader::includeModule('transformer'))
{
$result->addError(new Error('Could not include module transformer'));
return $result;
}
$fileData = CFile::getByID($fileId)->fetch();
if (!$fileData)
{
$result->addError(new Error('Could not find file'));
return $result;
}
$transformation = $this->buildTransformationByFile($fileData);
if (!$transformation)
{
$result->addError(new Error('There is no transformation for file'));
return $result;
}
if(
$transformation->getInputMaxSize() > 0 &&
$fileData['FILE_SIZE'] > $transformation->getInputMaxSize()
)
{
$result->addError(new Error('Too big file for transformation'));
return $result;
}
$transformer = $transformation->buildTransformer();
if (!$transformer)
{
$result->addError(new Error('Could not build transformer'));
return $result;
}
$shouldSendPullTag = true;
$information = $this->getTransformationInformation($fileId);
if ($this->shouldSendToTransformation($information, $fileData))
{
$result = $transformer->transform(
(int)$fileId,
[$transformation->getOutputExtension()],
'main',
CallbackHandler::class,
['id' => $fileId, 'fileId' => $fileId, 'queue' => self::QUEUE_NAME]
);
if (!$result->isSuccess())
{
$shouldSendPullTag = false;
}
}
if (isset($information['status']) && $information['status'] == Command::STATUS_ERROR)
{
$shouldSendPullTag = false;
$result->addError(new Error('Could not transform file', Command::STATUS_ERROR));
}
if ($shouldSendPullTag)
{
$pullTag = $this->subscribeCurrentUserForTransformation($fileId);
$result->setData([
'pullTag' => $pullTag,
]);
}
return $result;
}