Skip to content

Commit 2e21a0b

Browse files
committed
Rewording Caution paragraph at line 413
1 parent 3b0c75d commit 2e21a0b

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

cookbook/doctrine/file_uploads.rst

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -410,15 +410,22 @@ Next, refactor the ``Document`` class to take advantage of these callbacks::
410410
}
411411
}
412412

413-
.. caution::
413+
When using a Doctrine event listener or subscriber, when you make changes
414+
to your entity, the preUpdate() callback must have an extra line of code to
415+
tell Doctrine about the change::
414416

415-
When using Doctrine EvensubScribers' preUpdate(\Doctrine\Common\Persistence\Event\PreUpdateEventArgs $args)
416-
callback instead of lifecycle callbacks you also need to invoke, ``$args->setNewValue('path', $filename);``
417-
as at this point changeSets are not updated and the ``path`` change just made won't have effect
418-
in the data base record.
419-
For full reference on preUpdate event restrictions, see `preUpdate`_ in the in the Doctrine Events documentation.
417+
public function preUpdate(PreUpdateEventArgs $args)
418+
{
419+
$entity = $args->getEntity();
420+
// do all the file uploading logic
421+
// ...
422+
$entity->setFilename($newFilename);
423+
$args->setNewValue('filename', $newFilename);
424+
}
425+
426+
For full reference on preUpdate event restrictions, see `preUpdate`_ in the
427+
Doctrine Events documentation.
420428

421-
.. _`preUpdate`: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/events.html#preupdate
422429

423430
The class now does everything you need: it generates a unique filename before
424431
persisting, moves the file after persisting, and removes the file if the
@@ -556,3 +563,5 @@ You'll notice in this case that you need to do a little bit more work in
556563
order to remove the file. Before it's removed, you must store the file path
557564
(since it depends on the id). Then, once the object has been fully removed
558565
from the database, you can safely delete the file (in ``PostRemove``).
566+
567+
.. _`preUpdate`: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/events.html#preupdate

0 commit comments

Comments
 (0)