Skip to content

[cookbook][doctrine] The update of the entity is not secure. #5448

Closed
@yceruto

Description

@yceruto

Doctrine launches the PreUpdate event when there is a change in the mapped fields of the entity. Otherwise does nothing. We agree?

Then in this case, the file field it's not a mapped field, Using the id as the Filename:

/**
 * Sets file.
 *
 * @param UploadedFile $file
 */
public function setFile(UploadedFile $file = null)
{
    $this->file = $file;
    // check if we have an old image path
    if (is_file($this->getAbsolutePath())) {
        // store the old name to delete after the update
        $this->temp = $this->getAbsolutePath();
    } else {
        $this->path = 'initial';
    }
}

when the file exists previously the condition,

if (is_file($this->getAbsolutePath())) is true

but the path field is not changed and therefore Doctrine does not detect any change in the entity and not triggers the events. (Suppose that the form has only a file field)

I think which is the goal too of the sentence,

$this->path = 'initial';

the first time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    hasPRA Pull Request has already been submitted for this issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions