Skip to content

Commit

Permalink
EZP-28279: User cannot set max file size in Image field type (ezsyste…
Browse files Browse the repository at this point in the history
  • Loading branch information
ViniTou authored and Łukasz Serwatka committed Mar 20, 2018
1 parent c72461f commit 68a7e9e
Showing 1 changed file with 1 addition and 54 deletions.
Expand Up @@ -10,14 +10,10 @@

use eZ\Publish\Core\IO\IOServiceInterface;
use eZ\Publish\Core\IO\UrlRedecoratorInterface;
use eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter;
use eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldValue;
use eZ\Publish\SPI\Persistence\Content\FieldValue;
use eZ\Publish\SPI\Persistence\Content\FieldTypeConstraints;
use eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition;
use eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldDefinition;

class ImageConverter implements Converter
class ImageConverter extends BinaryFileConverter
{
/** @var \eZ\Publish\Core\IO\IOServiceInterface */
private $imageIoService;
Expand Down Expand Up @@ -214,53 +210,4 @@ protected function parseLegacyXml($xml)

return $extractedData;
}

/**
* Converts field definition data in $fieldDef into $storageFieldDef.
*
* @param \eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition $fieldDef
* @param \eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldDefinition $storageDef
*/
public function toStorageFieldDefinition(FieldDefinition $fieldDef, StorageFieldDefinition $storageDef)
{
$storageDef->dataInt1 = (isset($fieldDef->fieldTypeConstraints->validators['FileSizeValidator']['maxFileSize'])
? round($fieldDef->fieldTypeConstraints->validators['FileSizeValidator']['maxFileSize'] / 1024 / 1024)
: 0);
}

/**
* Converts field definition data in $storageDef into $fieldDef.
*
* @param \eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldDefinition $storageDef
* @param \eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition $fieldDef
*/
public function toFieldDefinition(StorageFieldDefinition $storageDef, FieldDefinition $fieldDef)
{
$fieldDef->fieldTypeConstraints = new FieldTypeConstraints(
array(
'validators' => array(
'FileSizeValidator' => array(
'maxFileSize' => ($storageDef->dataInt1 != 0
? (int)$storageDef->dataInt1 * 1024 * 1024
: null),
),
),
)
);
}

/**
* Returns the name of the index column in the attribute table.
*
* Returns the name of the index column the datatype uses, which is either
* "sort_key_int" or "sort_key_string". This column is then used for
* filtering and sorting for this type.
*
* @return string
*/
public function getIndexColumn()
{
// @todo: Correct?
return 'sort_key_string';
}
}

0 comments on commit 68a7e9e

Please sign in to comment.