• Модуль: documentgenerator
  • Путь к файлу: ~/bitrix/modules/documentgenerator/lib/integration/transformermanager.php
  • Класс: BitrixDocumentGeneratorIntegrationTransformerManager
  • Вызов: TransformerManager::call
static function call($status, $command, $params, $result = array())
{
	if(!isset($params['documentId']) || empty($params['documentId']))
	{
		return 'wrong parameters: no documentId';
	}

	if($status != Command::STATUS_UPLOAD && $status != Command::STATUS_ERROR)
	{
		return 'wrong command status';
	}

	$document = Document::loadById($params['documentId']);
	if(!$document)
	{
		static::fireEvent($params['documentId']);
		return 'document '.$params['documentId'].' not found';
	}

	$updateData = [];
	foreach(static::getFormats() as $extension => $format)
	{
		if(isset($result['files'][$extension]))
		{
			$fileArray = CFile::MakeFileArray($result['files'][$extension], $format['TYPE']);
			$fileArray['MODULE_ID'] = Driver::MODULE_ID;
			$fileArray['name'] = $fileArray['fileName'] = $document->getFileName($extension);
			$saveResult = FileTable::saveFile($fileArray);
			if($saveResult->isSuccess())
			{
				$updateData[$format['KEY']] = $saveResult->getId();
				$document->{$format['METHOD']}($saveResult->getId());
			}
		}
	}

	if(!empty($updateData))
	{
		$updateResult = DocumentTable::update($params['documentId'], $updateData);
		if(!$updateResult->isSuccess())
		{
			foreach($updateData as $fileId)
			{
				FileTable::delete($fileId);
			}
		}
	}

	$isTransformationError = $status === Command::STATUS_ERROR;
	$data = $document->getFile(false)->getData();
	$data['isTransformationError'] = $isTransformationError;
	if($isTransformationError)
	{
		if(isset($result['command']))
		{
			$command = $result['command'];
			if($command instanceof Command)
			{
				$error = $command->getError();
				if($error)
				{
					$data['transformationErrorMessage'] = $error->getMessage();
					$data['transformationErrorCode'] = $error->getCode();
				}
			}
		}
	}
	static::addToStack($data);
	$pdfId = null;
	if(isset($updateData['PDF_ID']) && $updateData['PDF_ID'] > 0)
	{
		$pdfId = $updateData['PDF_ID'];
	}
	$data['pdfId'] = $pdfId;
	static::fireEvent($params['documentId'], $data);

	return true;
}