Jump to content


Photo

Module: Page Edit Soft Lock

Module

  • Please log in to reply
25 replies to this topic

#1 Soma

Soma

    Hero Member

  • Moderators
  • 3,187 posts
  • 1744

  • LocationSH, Switzerland

Posted 27 October 2011 - 02:47 PM

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.

@somartist | modules created | support me, flattr my work flattr.com


#2 apeisa

apeisa

    Hero Member

  • Moderators
  • 2,521 posts
  • 848

  • LocationVihti, Finland

Posted 27 October 2011 - 03:25 PM

Great stuff! Can't wait to see this finished.

#3 Soma

Soma

    Hero Member

  • Moderators
  • 3,187 posts
  • 1744

  • LocationSH, Switzerland

Posted 28 October 2011 - 03:33 AM

Thanks apeisa. Just released first version. See first post for link and infos.

@somartist | modules created | support me, flattr my work flattr.com


#4 apeisa

apeisa

    Hero Member

  • Moderators
  • 2,521 posts
  • 848

  • LocationVihti, Finland

Posted 28 October 2011 - 05:47 AM

Amazing stuff Soma! Will test this sooner than later. Seems like a great implementation.

#5 Soma

Soma

    Hero Member

  • Moderators
  • 3,187 posts
  • 1744

  • LocationSH, Switzerland

Posted 28 October 2011 - 08:22 AM

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

@somartist | modules created | support me, flattr my work flattr.com


#6 ryan

ryan

    Hero Member

  • Administrators
  • 5,771 posts
  • 3114

  • LocationAtlanta, GA

Posted 28 October 2011 - 08:24 AM

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.


#7 ryan

ryan

    Hero Member

  • Administrators
  • 5,771 posts
  • 3114

  • LocationAtlanta, GA

Posted 28 October 2011 - 08:33 AM

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;


#8 Soma

Soma

    Hero Member

  • Moderators
  • 3,187 posts
  • 1744

  • LocationSH, Switzerland

Posted 28 October 2011 - 08:43 AM

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...

@somartist | modules created | support me, flattr my work flattr.com


#9 Soma

Soma

    Hero Member

  • Moderators
  • 3,187 posts
  • 1744

  • LocationSH, Switzerland

Posted 28 October 2011 - 09:04 AM

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!

@somartist | modules created | support me, flattr my work flattr.com


#10 Soma

Soma

    Hero Member

  • Moderators
  • 3,187 posts
  • 1744

  • LocationSH, Switzerland

Posted 27 February 2012 - 02:37 PM

Just commited an update to this module fixing an issue with brand new repeater field, where the lock message would appear after saving page.

@somartist | modules created | support me, flattr my work flattr.com


#11 evanmcd

evanmcd

    Full Member

  • Members
  • PipPipPip
  • 79 posts
  • 28

Posted 14 June 2012 - 01:07 AM

Awesome module, Soma. JUST what I needed. Thanks so much for it.

#12 adrian

adrian

    Sr. Member

  • Members
  • PipPipPipPip
  • 247 posts
  • 70

Posted 19 February 2013 - 01:58 PM

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. 



#13 Soma

Soma

    Hero Member

  • Moderators
  • 3,187 posts
  • 1744

  • LocationSH, Switzerland

Posted 19 February 2013 - 02:06 PM

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.


@somartist | modules created | support me, flattr my work flattr.com


#14 adrian

adrian

    Sr. Member

  • Members
  • PipPipPipPip
  • 247 posts
  • 70

Posted 19 February 2013 - 02:14 PM

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.



#15 Peter Falkenberg Brown

Peter Falkenberg Brown

    Full Member

  • Members
  • PipPipPip
  • 60 posts
  • 14

  • LocationMaine, USA

Posted 02 April 2013 - 09:15 PM

Hi Soma,

 

Thanks for doing this module.

 

How hard would it be to add an option to make it a hard lock, rather than a soft one?

 

Thanks,

 

Peter



#16 Soma

Soma

    Hero Member

  • Moderators
  • 3,187 posts
  • 1744

  • LocationSH, Switzerland

Posted 03 April 2013 - 04:28 AM

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.


@somartist | modules created | support me, flattr my work flattr.com


#17 Peter Falkenberg Brown

Peter Falkenberg Brown

    Full Member

  • Members
  • PipPipPip
  • 60 posts
  • 14

  • LocationMaine, USA

Posted 03 April 2013 - 09:48 AM

Dear Soma,

 

Your points are well taken.

 

Still, it might be good to have a hard lock module as an option.

I guess it's a toss up between the incovenience of open records, verus two conflicts where both

people ignore the soft lock.

 

Thanks,

 

Peter



#18 Martijn Geerts

Martijn Geerts

    Sr. Member

  • Members
  • PipPipPipPip
  • 373 posts
  • 168

Posted 03 April 2013 - 01:17 PM

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.



#19 Peter Falkenberg Brown

Peter Falkenberg Brown

    Full Member

  • Members
  • PipPipPip
  • 60 posts
  • 14

  • LocationMaine, USA

Posted 03 April 2013 - 01:32 PM

Dear Martijn,

 

Yes, he did a great job; thanks Soma!

 

I guess it depends on the business requirements of a particular website.

 

I do understand your logic. :-).

 

Yours,

 

Peter

 

 



#20 Martijn Geerts

Martijn Geerts

    Sr. Member

  • Members
  • PipPipPipPip
  • 373 posts
  • 168

Posted 03 April 2013 - 01:42 PM

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.







Also tagged with one or more of these keywords: Module

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users