SingleEdit: Prevent concurrent edits on records.

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 858
Joined: 2019-05-21 22:42
Location: Germany
Contact:

SingleEdit: Prevent concurrent edits on records.

Post by onoehring » 2021-01-15 17:32

Hi,

I created a new extension which should be easy to implement: SingleEdit
Purpose: Prevent concurrent edits on records.

As AppGini (AG) in the current version 5.92 does not support locking records for user B if user A currently edits them, I decided to make a start.
From the docs:

Introduction
A common problem working with online-databases is, that it’s almost impossible to handle concurrent edits on the same record.
If user UA has record RA open in the browser, nothing prevents user UB from opening that same record RA in his browser. So far there is no problem, as user UA and user UB are only viewing the record. A problem arises, once both users start editing the record.
This might seem not so common, but people might keep their browser window open, do something else and try to save an edited record 30 minutes after they opened it. We, as developers, just do not know if the user is viewing, editing, has his browser closed etc.

Let’s make an example and assume the records shows customer’s C1 data: Customer’s C1 lastname, firstname and street address. The data in the database reads as follows:

Code: Select all

Lastname: Noehring
Firstname: Olaf
Streetaddress: Somestreet 3
UA not starts editing the record and changes the lastname because the customer C1 has married, so the data in the browser of UA is now:

Code: Select all

Lastname: Merkel		<--- the value has been changed by UA
Firstname: Olaf
Streetaddress: Somestreet 3
At the same time UB changes the street address because the customer C1 has moved, so the data in the browser of UB is now:

Code: Select all

Lastname: Noehring
Firstname: Olaf
Streetaddress: Countryside 99		<--- the value has been changed by UB
We need do keep in mind every user sees the values on screen as they have been pulled from the database when the page was generated. This UA does not notice (yet), that UB changes the streetaddress and UB does notice the changes of the column lastname by UA.

UA now presses the save changes button in the browser window. The values that will be written to the database, overwriting existing values, are:

Code: Select all

Lastname: Merkel		<--- the value that has been changed by UA
Firstname: Olaf
Streetaddress: Somestreet 3
Once UB presses the save changes button in the browser window. These values will be written to the database, overwriting existing values:

Code: Select all

Lastname: Noehring
Firstname: Olaf
Streetaddress: Countryside 99		<--- the value that has been changed by UB
We can now see the problem: The data has been messed up and is wrong. The user has his old lastname but the new streetaddress. The new lastname which UA had changes was overwritten by the old lastname when UB saved the values from his browser window.
User UB should not have been able to save his edits, but should have been notified, that the records has been changed in the meantime.

This script solves this problem.

It can look like this:
singleedit_err1.png
singleedit_err1.png (18.43 KiB) Viewed 248 times
Download v0.9
(.ZIP, size 237kb, including files and documentation)
https://dl.olaf-noehring.de/?t=167959be ... 3be10084cb

Comments? Ideas? Suggestions?
Olaf

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 858
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: SingleEdit: Prevent concurrent edits on records.

Post by onoehring » 2021-01-16 06:30

Hi,
be patient. I removed v0.9 and making it easier and better to implement. New version coming up in one or two hours.
Olaf

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 858
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: SingleEdit: Prevent concurrent edits on records.

Post by onoehring » 2021-01-16 07:36

Hi,

it was a long day yesterday and I obviously way a bit too eager to release. So, release early and often, I present the 0.91 version (the previous version has been removed).
  • To use SingleEdit 0.91 you need to add only 7 lines of code now (including 2 lines of comments). This should make implementation even easier and your code cleaner.
  • You can adjust the custom error message more easy (moved variable).
  • Updates should be way easier, as the code is not simply included (to be exact: required) from two files.
Download v0.91
https://dl.olaf-noehring.de/?t=81bb7a67 ... db71170e80

Olaf

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 858
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: SingleEdit: Prevent concurrent edits on records.

Post by onoehring » 2021-01-18 11:03

Hi,

I forgot to remove some debugging calls. They are gone now in this version (the previous version has been removed):

Download v0.92
https://dl.olaf-noehring.de/?t=562ee17e ... 08c5f358c9

Olaf

Post Reply