Jump to content

Module: Page Edit Soft Lock


Soma
 Share

Recommended Posts

PageEditSoftLock ProcessWire2+ Module

There was a request for a page lock feature in PW2.1 for pages being edited by an other user already, it would lock or throw a message of along the line of: "This page is currently being edited by "username'."

Thanks to Ryan for helping getting this done quickly!

Download:

https://github.com/s...ageEditSoftLock

How it works

Only the module "PageEditSoftLock" needs to be installed/uninstalled, the "ProcessPageEditSoftLock" Module will install/uninstall itself. The module creates a table and a hidden admin page under /page/edit/ for pinging in the background while editing a page. You can configure the ping interval and expiration timeout to what you think is good.

Defaults

- 20 seconds for pinging,

- 60 seconds for expiration time (all entries in the table older than this will get deleted).

----

27-02-2012 update

https://github.com/s...1f204bc1b6c740a

Fix for new repeater field throwing the lock message because of the way repeater work and this module. Thanks to Ryan for finding a quick fix.

  • Like 4
Link to comment
Share on other sites

I have installed it on some projects and now I noticed a problem with the file upload. It doesn't update upload status and doesn't finish it, but after refresh the image is uploaded. I'm sure it has to do with this module, but not sure what's causing it. Any suggestions appreciated! Thanks

Link to comment
Share on other sites

Nice job Soma, just tested out and it seems to work beautifully! I'm amazed how quickly you got this out.

This may not matter much, but if you want, I think you can replace the try/catch in ProcessPageEditSoftLock with just this below. That would get rid of the try/catch and condense it down to one more efficient query. Though in this case, I don't expect it would really matter since the query happens once every 20 seconds rather than hundreds of times a second. :)

$this->db->query("INSERT INTO users_editing_page (page_id, user_id, ts) VALUES($page_id, $user_id, $time) ON DUPLICATE KEY UPDATE ts=VALUES(ts), user_id=VALUES(user_id)");

I love that the times are configurable. The only question I had was about why times are in two different formats on the config screen (seconds and milliseconds)? I'm thinking that many non-programmers might not recognize exactly what milliseconds are at first.

Link to comment
Share on other sites

I have installed it on some projects and now I noticed a problem with the file upload. It doesn't update upload status and doesn't finish it, but after refresh the image is uploaded. I'm sure it has to do with this module, but not sure what's causing it. Any suggestions appreciated! Thanks

I think I see what the problem is. In your checkpagestatus() function, at the top, have it abort if it's an ajax request. i.e.

if($this->config->ajax) return; 
Link to comment
Share on other sites

Thanks a lot Ryan, this would have taken me ages to find out! Lovely :D

It works now again.

Only problem I noticed now in Firefox it doesn't seem to work at all, my module. Even with the fix. ??? I got tested now with all except FF, I got latest. Anyone experience the same? Stupid me, I logged in with same user... But still I think the pining window.setInterval doesn't work in my FF. Will test now some more.

EDIT: There's something strange going on in FF, no errors and it doesn't seem to work at all... Confused...

Link to comment
Share on other sites

Well I'm already used to it, but now it works without doing something... tested again in FF and it works now. Oh well.

Thanks Ryan for the suggestions, I implemented your suggestions.

And have adjusted the config times to be both in seconds.

I commited the new version to github. Thanks!

Link to comment
Share on other sites

  • 3 months later...
  • 3 months later...
  • 8 months later...

Hi Soma,

This is a great setup, but I am thinking about the issue of more than one person using the same login details. I have a project where each team of people will have a single login and I'd like to be able to have the warning popup even if the page is being edited by the same username. An IP address won't be appropriate since many will likely appear from the same address. I am thinking a cookie approach might be best.

The other thing I want to be able to do is use this to warn users editing pages via a front-end form.

I plan on implementing these shortly, but thought I'd ask if perhaps you already had any plans along these lines, or any suggestions. 

Link to comment
Share on other sites

No I haven't . Give them all a separate login, problem solved. You don't want to have various people with same login in a CMS generally and working simultaneously from same place.

Anyway I don't see a simple way to implement this. I'm also not sure if it would work for frontend as you would have to take care of it anyway, but maybe my module helps you getting started.

Link to comment
Share on other sites

I agree that separate logins would help, but all the editing I am talking about is front-end, and will be by groups of people that may change on a daily basis, so it starts to get complicated.

I am sure I will make use of your module as a starter, but you are right, I may have to do this differently to handle front-end protection.

Link to comment
Share on other sites

  • 1 month later...

Hi Peter

I don't know really how hard a hard lock in a soft lock module is. :D

The reason to only have a soft lock is clear, and hard locks can get a burden if someone lock a page by having the page open.

I think it's possible, but have to think about some time. It would be as you suggest and option you need to enable. But then also the Module name doesn't fit anymore.

Link to comment
Share on other sites

Hello Peter,

If the traffic lights are turned red, you could drive through. But you know you're wrong.

If there's an emergency, you could take the risk to driving through red. ( soft lock. )

But if there's a hard lock, the lock must be openend somehow if someone didn't logout for example.

So an other thing is needed to re-open locked pages. ( Making the hard-lock a little soft again.  )

Think Soma did a great job with the soft-lock.

Link to comment
Share on other sites

Hai Peter,

you said: "I guess it depends on the business requirements of a particular website."

(If I understand what you're saying) If you don't "trust" your editors, you're better off with with a front-end edit solution with the PW API.

Dear Martijn,

Perhaps so. I haven't run into the situation yet, so we'll have to see.

But I'm grateful that Soma wrote the module. It will indeed come in handy.

Peter

Link to comment
Share on other sites

Lol love that analogy.

Either way you can end up with a problem. SInce finally you decide which one you think makes most sense. I understand if one wants or needs this feature and I added a option to enable hard lock.

Pushed an update 1.0.1 to github now.

- added option to enable hard lock

- made alert message translatable

https://github.com/somatonic/PageEditSoftLock

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...