4

In a previous CMS we used (Processwire), one of the authors created a very useful plugin that would warn a user on an edit page that the page was currently being edited by another user.

I'm thinking this would be a useful addition, unless Craft's use of automatic versioning would somewhat rule out the risk of overwriting someone else's work?

Has anyone had any similar thoughts on the issue?

Thanks.

Brad Bell
  • 67,440
  • 6
  • 73
  • 143

3 Answers3

4

Inspired in part by Mats' detailed answer, I've written a plugin that does just this: MN Snitch

Enjoy!

Marion Newlevant
  • 12,047
  • 22
  • 55
3

It's definitely a feature Craft is missing, and I've had requests from several clients who are frustrated about it (not super frustrated, fortunately, because everything else in Craft is so much better than whatever else they were using before) :D

Implemented as a plugin, in my opinion there are two primary problems to solve – the first is how to "store" the "being edited" state for an entry being edited (and obviously, clearing that state once the entry is no longer being edited), and the second is how to communicate that state to any other users attempting to edit the same entry.

The first problem could easily be solved by using AJAX in order to save the entry ID to a custom database row, keeping track of entries being edited. The real problem is how to ascertain that an entry is being edited, or even that a user is in fact interacting with an entry editing form (an issue the second feature request Brad links to in his answer deals with).

The second problem could probably be solved by either using basic AJAX polling, where a script checks with the server on pageload, and then every X seconds, if the "being edited" state of the current entry has changed; displaying the appropriate message to the user once it does (Craft uses this approach for login timeouts). Websockets would of course be an even better approach, but is a bit more troublesome to set up.

I've actually done some work on a plugin just like this myself (unfortunately, its nowhere close to being finished yet, and might never be!), which uses Pusher (essentially websockets as a service) for problem #2. For problem #1, I've previously "solved" this in other plugins like Reasons by using jQuery to parse the Control Panel HTML, looking for the appropriate form input fields (for instance, the entry editing form would have a hidden action input with the value entries/saveEntry, as well as an input named entryId), in order to identify the current page as an entry editing form. Basically, hacks that could break at any time, e.g. if P&T redesigns the Control Panel.

Beyond this, there are a plethora of other issues to solve. For instance, entries in Craft can be edited in several different ways, so the plugin probably needs to handle element editor modals and Live Preview as well. Also, making sure that an entry is "unlocked" is not as easy as it sounds – a JavaScript "unload" handler would probably work in most cases, but is fickle, in my experience, so there would probably need to be some sort of timestamping feature built in as well, and probably a task to clean up old/stale "being edited" rows from the database.

Due to the potential complexity of the feature, I really hope P&T builds it into core some day. If not, I'm sure a plugin will pop up sooner or later (mine or someone else's).

Mats Mikkel Rummelhoff
  • 22,361
  • 3
  • 38
  • 69
  • Many thanks for such a detailed write up! Out of interest, here is the corresponding module from PW (by Soma).

    https://github.com/somatonic/PageEditSoftLock

    It's 3 years old and pretty sure it's not covering all the bases you mentioned. Just a warning on a traditional edit page.

    – André Goldstein May 07 '16 at 17:18
  • @AndréGoldstein Thanks, that's interesting. It's basically working exactly as I described above; first by keeping a record of entries being edited in the database, and then a combination of timestamps and AJAX polling to communicate messages about the entries' status to the end user. – Mats Mikkel Rummelhoff May 07 '16 at 17:54
2

I can't think of an easy way for a plugin to currently do this, but you should consider voting for these feature requests that would enable this scenario:

http://feedback.craftcms.com/forums/285221-feature-requests/suggestions/9009169-add-an-alert-or-warning-when-multiple-authors-are

http://feedback.craftcms.com/forums/285221-feature-requests/suggestions/10689150-entry-onopen-hook

Brad Bell
  • 67,440
  • 6
  • 73
  • 143