I'm working on a module to "check out" and "check in" nodes, to get around the problem of multiple users updating the same node. A feature of this is that users can choose to "check out" the node so that it remains locked to other users even if they have finished editing it (that way they can come back to it later without fear of it being messed up).
The basic plan is this:
1) Create a new table "checkout" with uid/nid and timestamp. NID is a unique key (logically: more than one user cannot update a node at the same time)
2) Use nodeapi "validate": INSERT an entry into "checkout" with the nid and uid. If there is an error because the row already exists, then check to see if the associated uid is the same as current uid. If it is, then allow editing, if it is not then give an error message.
This all works ok, except that when the row exists I get an SQL error message across the top of the page. Since this is an accepted condition, I really want to trap that error message and use it in the code rather than have it display. It is possible to do this?
Why not do a SELECT first, you might ask?
Two reasons:
- I'm a bit uncertain about using START TRANSACTION and/or LOCK TABLES - afraid this would not fit in the Drupal DB abstraction layer.
- since most of the time people will only want to make sure nobody changes the node while they are actively editing it, then just