/**
* Checks if the name changed, if this is the case, the uploaded file
* has to be renamed.
* Removes the thumbnail files if the album or the name changed.
* Creates the default and album thumbnails if the name or the album changed.
*
* @ORM\PostUpdate()
*/
public function onUpdate() { // Returns a change set for the model, which contains all changed properties with the old and new value.
$changeSet =
Shopware()->
Models()->
getUnitOfWork()->
getEntityChangeSet($this);
$isNameChanged =
isset($changeSet['name'
]) &&
$changeSet['name'
][0
] !==
$changeSet['name'
][1
];
$isAlbumChanged =
isset($changeSet['albumId'
]) &&
$changeSet['albumId'
][0
] !==
$changeSet['albumId'
][1
];
// Name changed || album changed?
if ($isNameChanged ||
$isAlbumChanged) { // To remove the old thumbnails, use the old name.
$name =
isset($changeSet['name'
]) ?
$changeSet['name'
][0
] :
$this->name;
$name =
$this->
removeSpecialCharacters($name);
$name =
$name . '.' .
$this->extension;