[ic] How to "lock" a record?

Paul Jordan paul at gishnetwork.com
Wed Jun 23 12:28:22 EDT 2004

DB [DB at M-and-D.com] wrote:
>>> I'm developing a 5.2/foundation based catalog to allow several
>>> people to collaborate on order processing. The order data is stored
>>> in a mysql table. I'm nearly finished except for one issue. I need
>>> to be sure that only one person at a time is working on a given
>>> order.
>>> My first thought is to add a new column to the table that holds the
>>> order records, and have users "sign out" the records they're
>>> working on by entering their initials into that field.
>>> Does anyone have a better way or any other suggestions? Maybe there
>>> is an existing mechanism that addresses this problem? All
>>> suggestions are welcome.
>> I would probably set a new lock-column and a edited_by column, and
>> add a timestamp + the username when a user starts editing it (check
>> the code that is found in the UI for activating and deactivating a
>> customer). When the user is ready with his/her editing, then It
>> would clear the timestamp from the lock-column. You should then also
>> remeber to have a cron-job that auto-clears the lock-field if the
>> timestamp is older that x-minutes. The username would help the same
>> user to return to his/her unfinished record before the cron resets
>> the field (if eg. browser crashese etc.)
>> Rene
> Thanks... that sounds like what I had in mind and I have added the two
> columns. Here is how I currently link to the page where the order
> data is edited:
>     <FORM METHOD=POST ACTION="[process]">
>      <INPUT TYPE=HIDDEN name="mv_doit" value="return">
>      <INPUT TYPE=HIDDEN name="mv_nextpage" value="update_order">
>                Update Order<br> <select name=update_code>
>                    [loop option=order_number search="
>                          st=db
>                          ra=yes
>                          fi=MDorders
>                          rf=order_number
>                          ml=1000
>                          tf=order_number
>                          to=n
>                    "]
>                    <option value="[loop-data MDorders order_number]">
> [loop-data MDorders order_number]</option>
>                    [/loop]
>                </select><br>
>      <INPUT TYPE=SUBMIT name="mv_submit"  Value="Go"> </FORM>
> I want to to add a timestamp to the "locked" field when the "go"
> button on the above form is clicked. Can that be done somehow or
> would I have to use two steps: 1) add the timestamp, then 2) open the
> page where the edits are made.
> DB

I would point that form to a special_pages page that has some logic. The logic
would do a query to first check if it is locked already. If it is locked,
bounce the user to a suitable notice page, and if not locked, immediately
insert the users "username" into your lock_column field.

Also, on your "this record is locked page" I would show who last took control,
and at what time. This way, the user could decide if they want to terminate the
lock, and place their own lock. For example, a browser may crash, and you may
have your cron set to 30 minutes (sometimes people work slow :). So, Sally can
say, hmm Bill just left for lunch, so I know he is not working on this, I will
terminate it. Or maybe Sally's browser crashed. she get get back on real quick,
and terminate/initiate herself a new lock.

You should also compare the usernames just before you write to the record. If
they don't match, you need a backup plan. Maybe write the info into scratch, or
a new record or whatever.

This should work *most of the time. It should work really well in small
offices. Also, if the crew is using a mandatory IM, then they can message each
other... "are you working on this record? it had been a while...", that is, if
it is really important.

My system allows for very very loooong edits, and also allows for extreme
incompetence, so that is necessary.


More information about the interchange-users mailing list