Hi everyone,
I've recently been building a CMS to make developing life a bit easier, but I've come across a problem I can't seem to figure out.
The system caters for multiple users and user groups, so it's fair to assume that eventually two or more people will try to edit the same (for example) article or page. At the moment, I've tried using a checkout-checkin method using two fields in the database (`date_checked_out` and `checked_out_by`) and three PHP functions (checkin, checkout, check_edit_status).
It was going well until I realized if I refreshed the page that was checked out (by me) I got kicked out with an error saying "You are currently working on this file elsewhere...". So I started to play with $_SESSION vars to allow refreshing the page - then I realized it allowed me to edit the page from a different window even when it was checked out! I also came across a few other problems such as, if a user left the page using the back button, the page stayed checked-out.
Does anyone know a better way to checking-in/out or know of a guide which might help?
Thanks in advance,
Ben
CMS Version Controlling
Moderator: General Moderators
-
ben.artiss
- Forum Contributor
- Posts: 116
- Joined: Fri Jan 23, 2009 3:04 pm
Re: CMS Version Controlling
The multiple window thing is tricky. If the OS treats different windows as just different windows & not separate processes, there's not much you can do with sessions. The only thing that comes to mind is if every time you check out a file, you attach a random string to the URL, like: edit.php?url=/page/being/edited.html&key=38fkf884kbnfj. That random string can be separate for each page access - which allows it to be separate for each window. You then store $_GET['key'] as the identifier for what has the page checked out. In each window, check if $_GET['key'] is what currently has the file checked out. If it is, let the page be edited. If not, then another window has the file checked out.
As for automatically checking the file in, have some hidden AJAX call that keeps the file checked out every 10 seconds or so. If the file hasn't been newly checked out in the last 10 seconds, check it back in.
As for automatically checking the file in, have some hidden AJAX call that keeps the file checked out every 10 seconds or so. If the file hasn't been newly checked out in the last 10 seconds, check it back in.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
-
ben.artiss
- Forum Contributor
- Posts: 116
- Joined: Fri Jan 23, 2009 3:04 pm
Re: CMS Version Controlling
Excellent advice I don't know why I didn't think of the unique key!
I will give that a bash later on.
At the moment, the checkout() function checks to see how long the file has been checked out for, and if it's been longer than the set time (e.g. 20mins), it checks-in and checks it back out for the current user (otherwise redirects with an error); would you say this is a bad idea since a user could potentially still be editing some data? This is just a fail safe in case something goes wrong when checking-in so the data becomes editable again.
Thanks for the reply, it's given me a good idea where to take it!
Regards, Ben
At the moment, the checkout() function checks to see how long the file has been checked out for, and if it's been longer than the set time (e.g. 20mins), it checks-in and checks it back out for the current user (otherwise redirects with an error); would you say this is a bad idea since a user could potentially still be editing some data? This is just a fail safe in case something goes wrong when checking-in so the data becomes editable again.
Thanks for the reply, it's given me a good idea where to take it!
Regards, Ben
Re: CMS Version Controlling
My sessions are an hour. If a user has a window open for longer than an hour and they try to re-save the page, they get a page that basically says they need to re-login. That page stores all the $_POST information, so when they login and are forwarded, none of their data is lost.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
- allspiritseve
- DevNet Resident
- Posts: 1174
- Joined: Thu Mar 06, 2008 8:23 am
- Location: Ann Arbor, MI (USA)
Re: CMS Version Controlling
This might be of interest: http://jim-mcbeath.blogspot.com/2009/02 ... cking.html
Re: CMS Version Controlling
The different windows may not be enough, because they will share cookies (and thus the PHPSESSID). Try different browsers, example if on windows open FF and then try to access/edit the same page in IE.
Re: CMS Version Controlling
You could pass session IDs in the url, rather than saving a cookie. That way you could have as many different sessions open as you wanted.