recipe_lock_protection.rst 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. Lock Protection
  2. ===============
  3. Lock protection will prevent data corruption when multiple users edit an object at the same time.
  4. Example
  5. -------
  6. 1) Alice starts to edit the object
  7. 2) Bob starts to edit the object
  8. 3) Alice submits the form
  9. 4) Bob submits the form
  10. In this case, a message will tell Bob that someone else has edited the object,
  11. and that he must reload the page and apply the changes again.
  12. Enable Lock Protection
  13. ----------------------
  14. By default, lock protection is disabled.
  15. You can enable it in your ``sonata_admin`` configuration :
  16. .. configuration-block::
  17. .. code-block:: yaml
  18. # app/config/config.yml
  19. sonata_admin:
  20. options:
  21. lock_protection: true
  22. You must also configure each entity that you want to support by adding a field called ``$version`` on which the Doctrine ``Version`` feature is activated.
  23. .. code-block:: php
  24. <?php
  25. // src/AppBundle/Entity/Car.php
  26. namespace AppBundle\Entity\Car;
  27. use Doctrine\ORM\Mapping as ORM;
  28. class Car
  29. {
  30. // ...
  31. /**
  32. * @ORM\Column(type="integer")
  33. * @ORM\Version
  34. */
  35. protected $version;
  36. // ...
  37. }
  38. For more information about this visit the `Doctrine docs <http://doctrine-orm.readthedocs.org/en/latest/reference/transactions-and-concurrency.html?highlight=optimistic#optimistic-locking>`_
  39. .. note::
  40. If the object model manager does not support object locking,
  41. the lock protection will not be triggered for the object.
  42. Currently, only the ``SonataDoctrineORMAdminBundle`` supports it.