Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CookBook] File upload with Doctrine - error when using PostRemove #2229

Closed
winzou opened this issue Feb 11, 2013 · 2 comments
Closed

[CookBook] File upload with Doctrine - error when using PostRemove #2229

winzou opened this issue Feb 11, 2013 · 2 comments

Comments

@winzou
Copy link

winzou commented Feb 11, 2013

Hi,

I have an entity named A, which owns a OneToOne relation with the Document entity of the cookbook (the one that is being uploaded), and with cascade={remove}.

If I delete A, then Doctrine deletes Document, and only after deletion it tries to execute its PostRemove callback. So in this callback you can't access any property of Document. If you do, you face an Entity was not found exception.

This is the same case as in #712 where you can't access the id property.

The same workaround should be used: save the filename in PreRemove, and use it from PostRemove. This code actually works:

/**
 * @ORM\PreRemove()
 */
public function preRemoveUpload()
{
  // we temporarly save the filename
  $this->filename = $this->getUploadRootDir().'/'.$this->getMyFileName();
}

/**
 * @ORM\PostRemove()
 */
public function removeUpload()
{
  // we use the saved filename
  if (file_exists($this->filename)) {
    unlink($this->filename);
  }
}
@mahmouds
Copy link
Contributor

see #2120

@winzou
Copy link
Author

winzou commented Feb 11, 2013

Rigth, I didn't see it. Closing this one.

@winzou winzou closed this as completed Feb 11, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants