28 $this->buildTransformationList();
33 return self::PULL_TAG . $fileId;
36 private function buildTransformationList()
38 if (!empty(static::$transformationList))
48 $event =
new Event(
'main',
'onTransformationBuildList');
52 foreach ($event->getResults() as $result)
54 if ($result->getType() != EventResult::SUCCESS)
58 $result = $result->getParameters();
59 if (!is_array($result))
64 foreach ($result as $class)
66 if (!is_string($class) || !class_exists($class))
71 if (!is_subclass_of($class, Transformation::class,
true))
73 throw new SystemException(
"Wrong event result. {$class} is not a subclass of " . Transformation::class);
76 $additionalList[] = $class;
80 static::$transformationList = array_merge($default, $additionalList);
93 $result->addError(
new Error(
'Could not include module transformer'));
98 $fileData = \CFile::getByID($fileId)->fetch();
101 $result->addError(
new Error(
'Could not find file'));
107 if (!$transformation)
109 $result->addError(
new Error(
'There is no transformation for file'));
115 $transformation->getInputMaxSize() > 0 &&
116 $fileData[
'FILE_SIZE'] > $transformation->getInputMaxSize()
119 $result->addError(
new Error(
'Too big file for transformation'));
124 $transformer = $transformation->buildTransformer();
127 $result->addError(
new Error(
'Could not build transformer'));
132 $shouldSendPullTag =
true;
134 if ($this->shouldSendToTransformation($information, $fileData))
136 $result = $transformer->transform(
138 [$transformation->getOutputExtension()],
140 CallbackHandler::class,
141 [
'id' => $fileId,
'fileId' => $fileId,
'queue' => self::QUEUE_NAME]
144 if (!$result->isSuccess())
146 $shouldSendPullTag =
false;
150 if (isset($information[
'status']) && $information[
'status'] == Command::STATUS_ERROR)
152 $shouldSendPullTag =
false;
153 $result->addError(
new Error(
'Could not transform file', Command::STATUS_ERROR));
156 if ($shouldSendPullTag)
160 'pullTag' => $pullTag,
167 protected function shouldSendToTransformation($information, array $fileData)
174 if (!isset($information[
'status']))
179 if ($information[
'status'] !== Command::STATUS_SUCCESS)
182 $date = $information[
'time'];
183 if ($date && (time() - $date->getTimestamp()) > 24 * 3600)
189 if ($information[
'status'] === Command::STATUS_SUCCESS && !CallbackHandler::existSavedFile($fileData[
'ID']))
199 return FileTransformer::getTransformationInfoByFile((
int)$fileId);
210 \CPullWatch::add(CurrentUser::get()->getId(), $pullTag);
223 if (empty($fileData[
'CONTENT_TYPE']))
228 $transformation = $this->buildTransformationByContentType($fileData[
'CONTENT_TYPE']);
231 return $transformation;
234 if (empty($fileData[
'ORIGINAL_NAME']))
241 return $this->buildTransformationByContentType($mimeType);
250 private function buildTransformationByContentType($contentType)
252 foreach (static::$transformationList as $transformationClass)
255 if (in_array($contentType, $transformationClass::getInputContentTypes(),
true))
257 $reflectionClass = new \ReflectionClass($transformationClass);
259 return $reflectionClass->newInstance();
static includeModule($moduleName)
static isModuleInstalled($moduleName)
static getByFilename($filename)