[TYPO3-dev] locking of records

Ernesto Baschny [cron IT] ernst at cron-it.de
Fri Jan 27 19:58:20 CET 2006


ben van 't ende schrieb am 27.01.2006 16:47:

> Some of our clients have at some point asked if records in the backend
> can be locked when they are being edited by a user so another user
> cannot edit them at the same time. Ofcourse there is the warning.
> 
> Kasper told me a lot of people also think locking of records has more
> disadvantages than advantages.
> 
> What do you think about that?

I think more interesting would be consistency checks on SAVING of
records. This is called Optimistic Locking.

So we need to check if we are saving data based on the information that
we actually loaded or it something changed data "under our feed".

Its pretty easy to do that: maintain a serial number with the record.
Once you load the form to edit that record, place that number in a
hidden field. On saving, you just have to lock the record for a very
quick time-frame: lock, load record, compare the submitted serial number
with the loaded serial number. If they differ, means someone else
changed the record while you were working on it. So we present a
warning/error-message, whatever, and we might even show what is
different between the loaded and now current record. If serial number
was equal, means noone else touched the record while you were at it, and
so you just: increase serial number and save, then unlock.

As locks are only set for this little timeframe, its very difficult for
them to remain stalled. And if they do, we can use session-ids or other
means to detect if the lock is still "valid" or not (session-id for a
lock expired means lock can be ignored).

We could even do that consistency checking without using locks, which
should increase data consistency already.


Cheers,
Ernesto




More information about the TYPO3-dev mailing list