13 final class CallbackHandler
implements Transformer\InterfaceCallback
32 public static function call($status, $command, $params, $result = array())
34 if (isset($params[
'fileId']) && $params[
'fileId'] > 0)
36 Transformer\FileTransformer::clearInfoCache($params[
'fileId']);
38 if ($status == Transformer\Command::STATUS_ERROR && isset($params[
'id']))
43 if (!isset($params[
'id']) || !isset($params[
'fileId']) || !isset($result[
'files']))
45 return 'wrong parameters';
48 if ($status != Transformer\Command::STATUS_UPLOAD)
50 return 'wrong command status';
53 $previewLogId = $previewId = $previewImageId = 0;
54 $previewLog = FilePreviewTable::getList([
56 'filter' => [
'FILE_ID' => $params[
'fileId']],
60 if (isset($previewLog[
'ID']))
62 $previewLogId = $previewLog[
'ID'];
65 foreach ($result[
'files'] as $ext => $filePath)
69 $previewImageId = self::saveFile($filePath,
'image/jpeg');
74 FilePreviewTable::update($previewLogId, [
75 'PREVIEW_IMAGE_ID' => $previewImageId,
80 $resultAdd = FilePreviewTable::add([
81 'FILE_ID' => $params[
'fileId'],
82 'PREVIEW_IMAGE_ID' => $previewImageId,
85 if ($resultAdd->getId())
87 $previewLogId = $resultAdd->getId();
94 $previewId = self::saveFile($filePath, MimeType::getByFileExtension($ext));
97 FilePreviewTable::update($previewLogId, [
98 'PREVIEW_ID' => $previewId,
103 FilePreviewTable::add([
104 'FILE_ID' => $params[
'fileId'],
105 'PREVIEW_ID' => $previewId,
109 self::sendNotifyAboutTransformation($params[
'fileId']);
113 (
new Event(
'main',
'onFileTransformationComplete', [
114 'fileId' => $params[
'fileId'],
120 protected static function sendNotifyAboutTransformation($fileId)
122 if (Loader::includeModule(
'pull'))
124 \CPullWatch::addToStack(
125 TransformerManager::getPullTag($fileId),
127 'module_id' =>
'main',
128 'command' =>
'transformationComplete',
137 protected static function saveFile($file, $type)
139 $fileArray = \CFile::makeFileArray($file, $type);
140 $fileArray[
'MODULE_ID'] =
'main';
141 $fileId = \CFile::saveFile($fileArray,
'main_preview');
150 public static function existSavedFile($fileId)
152 $previewRow = FilePreviewTable::getList([
153 'select' => [
'ID',
'PID' =>
'PREVIEW.ID'],
155 '=FILE_ID' => $fileId,
160 return !empty($previewRow[
'PID']);
static includeModule($moduleName)