Jump to content

(WIP) Field Change Notifier


netcarver
 Share

Recommended Posts

Warning: Still a work-in-progress. Still has quite a lot to be done.

At Tom Reno's request I started work on a module that allows you to setup various watches on fields in your PW installation. You get to choose a field and can then specify when a change to the watched field should trigger a notification email to various interested parties. Pictures might help, so here we go...

post-465-0-33958800-1462359499_thumb.png

post-465-0-55689000-1462359500_thumb.png

I intend adding a further restriction so fields in certain templates can be watched.

  • Like 9
Link to comment
Share on other sites

This continues to look really great! One possible suggestion would be to use the PageAutocomplete Inputfield for the individual users, just because some people might actually have thousands of users. This may be too much for an asmSelect.

  • Like 1
Link to comment
Share on other sites

This continues to look really great! One possible suggestion would be to use the PageAutocomplete Inputfield for the individual users, just because some people might actually have thousands of users. This may be too much for an asmSelect.

I'm trying this out now as it's a new Inputfield type to me. Can you point me in the direction of a module that uses this Inputfield type so I can get a look at how it's used? I tried the following but I'm missing something...

$field = $m->get("InputfieldPageAutocomplete")
 ->set('label', 'Select individuals you wish to notify')
 ->attr('id+name', 'users')
 ->set('parent_id', $this->config->usersPageID )
 ->set('labelFieldName', 'name')
 ->set('columnWidth', 50)
 ->attr('value', explode("|", $user_ids) );
;
$form->add($field);

Thank you in advance!

Link to comment
Share on other sites

Sorry Steve, I've sent you down the wrong path. The 'name' field can't be used with partial match selectors, so there isn't really any point in using the autocomplete unless you want to have to type out the whole username to find it. Sometimes I have to try things out before I realize them. :) If you wanted to do that, below is an example how:

$field = $m->get("InputfieldPageAutocomplete")
->set('label', 'Select individuals you wish to notify')
->attr('id+name', 'users')
->set('parent_id', $this->config->usersPageID )
->set('labelFieldName', 'name')
->set('searchFields', 'name')
->set('operator', '=')
->set('columnWidth', 50)
->attr('value', explode("|", $user_ids) );
Link to comment
Share on other sites

  • 1 month later...

Steve, I took another look at this module, since I might have upcoming requirement to have admin emailed every time any page is saved. This module is pretty close hit, but does much more and in more granular way (fields instead of pages and specific changes). This will be great reference for me if I end up building something similar but for pages.

But while I was looking through code I noticed that there is sql-query as a first thing in init() method. Is there really need to have that sql in each page load, or could it be done later?

Link to comment
Share on other sites

  • 1 year later...

This module seems to be not working well with the latest DEV 2.3.13 of PW:

- Throws an error about a button problem (I think to remember: InputfieldButton, line 253?) when deleting an entry.

- Uses not PDO but Mysqlli (a "depreated" warning)

Link to comment
Share on other sites

There shouldn't be any deprecated warnings about mysqli at least. We don't plan on dropping that database driver anytime soon, just will encourage people to standardize on PDO in the future after 2.4+ is well established. But I don't really see a reason why we'd ever need to remove the mysqli driver, as some sites may need it for legacy use, even after all modules are using PDO. 

InputfieldButton only has about 50 lines in it, so not sure about line 253. @ceberlin can you post in a screenshot or copy/paste the exact errors you saw both for the deprecated warning and the InputfieldButton?

Link to comment
Share on other sites

  • 2 months later...

@netcarver - thank you for this module, I'm finding it really useful for several sites!

One question is how can i modify the sent message to also include info about the page where the field was changed, as well as maybe a link directly to the admin edit for that page.

TIA

Link to comment
Share on other sites

@Macrura,

Glad to hear it is useful to you. My original plan was to watch fields regardless of the page context so there's no direct way to do this at the moment. I'll look at adding the page context for the parser.

  • Like 1
Link to comment
Share on other sites

@Macrura,
 
Off the top of my head: could you try making a small change to the ProcessFieldChangeNotifier.module file? After making the change shown there, you should be able to access the page context using 'page.subfield' from your templates but I haven't verified this yet. YMMV

  • Like 3
Link to comment
Share on other sites

Hi steve, is there any chance that something changed on this new version that would truncate the field in the email if it has line breaks? I have this new version installed on a site but it is only showing the 1st line of the field, whereas the other site is using the old version and shows the complete field; they are on different hosts, so there could be something with that;

Link to comment
Share on other sites

@Macrura

No changes that I'm aware of; it's the tagParser module that takes care of constructing the email subject and body lines and that hasn't changed for a few days. 

However, if the field with the embedded breaks is in the email subject template then those fields will be truncated to prevent email header injection attacks. You should be able to use fields with breaks in the email body template without issue. Is your issue occurring in the subject or body of the email?

BTW, I just added a new transformation to the TagParser to help deal with this if it is indeed the situation. Take a look at "nl2spaces" which will strip newlines and replace them with spaces. Might not be exactly what is needed but it is, perhaps, better than nothing.

Link to comment
Share on other sites

@all

Just pushed v0.6.0 adding...

  • Config of watches using empty strings (detect changes from empty->non-empty or vice-versa.)
  • Hookable triggerMatch() method - so you can define your own actions when a watch triggers.
  • Like 2
Link to comment
Share on other sites

  • 2 weeks later...

@pwFoo,

Not sure exactly what you need - are you after admin or front-end notifications for users? If the latter, then I described a solution a while back that might take of what you need without a module: https://processwire.com/talk/topic/5534-new-articles-to-users-with-cookie/?p=53935

Obviously not exactly how you want it set up, but might be easily adaptable.

Anyway, not sure if it is what you are after, but thought I'd see :)

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