What you want is a transactional database system, MySql can do that, see the MySql manual. Search innoDB and transactional. Alternative is to set a "Lock" field in the database, then you check if the row is locked before anyone can edit it. Though letting the database handle it may be better.
As far as I am concerned, transactional database system will have read/write lock when modifying the table itself, MyISAM for table lock, InnoDB for row lock. While these are very low level operations, the lock would last for couple few milliseconds only. Therefore you will probably need to have a way to manually lock your post for a longer period of time.
I am not a Wordpress expert, but the way Wordpress is probably doing a setInterval autosave on the first user to keep renewing a "lock". Wordpress saves a version of post every minute (when there are changes) and therefore trigger the renewal of the lock as long as the first user stays in editing that post.
As long as the lock is renewed, any new comers would be warned when trying to edit the post. Once you have this done, you can then implemented the idea of letting user with higher privileges to edit page or so. I think you could use the same way as what Wordpress have done.
FYI: If you prefer not to deal with any row locking or transactions, you could take a look at one of the NoSQL database system, couchDb, they implemented Multi-Version Concurrency Control (MVCC), but you would still need to handle conflicts whenever the conflict occurs.
EDIT: Looks like MySQL with InnoDB have MVCC too
http://dev.mysql.com/doc/refman/5.0/en/innodb-multi-versioning.html
Add Checkout_by (Integer) and Checkout_at (timestamp) to your table fields. When ever a user is editing a post then update these two fields with his/her user_id and Current timestamp. When another user wants to edit compare new user's access level with previous editing user and determine if the new user should take control or not.
Thank you guys. I will test the solution miladr.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community