Commit d26f239b authored by Loparev's avatar Loparev
Browse files

Do not upload context resources that are bigger than 20MB

parent 08c97a41
......@@ -41,6 +41,8 @@ class ContextUploader {
*/
protected $apiWrapper;
const FILE_SIZE_LIMIT = 1024 * 1024 * 20;
public function __construct(
SmartlingApiWrapper $api_wrapper,
TranslationJobToUrl $url_converter,
......@@ -293,7 +295,21 @@ class ContextUploader {
$stream_wrapper_manager = \Drupal::service('stream_wrapper_manager')->getViaUri($file->getFileUri());
$params = new UploadResourceParameters();
$params->setFile($stream_wrapper_manager->realpath());
$is_resource_uploaded = $api->uploadResource($item['resourceId'], $params);
$actual_file_size = $file->getSize();
if ($actual_file_size <= ContextUploader::FILE_SIZE_LIMIT) {
$is_resource_uploaded = $api->uploadResource($item['resourceId'], $params);
} else {
$is_resource_uploaded = FALSE;
$this->logger->warning("Context resource file exceeds its maximum permitted_size = @permitted_size, actual_size = @actual_size, id = @id and url = @url", [
'@permitted_size' => ContextUploader::FILE_SIZE_LIMIT,
'@actual_size' => $actual_file_size,
'@id' => $item['resourceId'],
'@url' => $item['url'],
]);
}
// Resource isn't uploaded for some reason. Log this info and set
// resource id into the cache. We will not try to upload this
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment