bernhard Posted July 9, 2020 Share Posted July 9, 2020 This is what I have so far: $wire->addHookAfter('Page(template=contact|sample)::changed', function(HookEvent $event) { $page = $event->object; $title = $page->title; $change = $event->arguments(0); $old = $event->arguments(1); // old value $new = $event->arguments(2); // new value $text = '...'; $mail = new WireMail(); $mail->to(['...']); $mail->from('...'); $mail->subject("Changed page: $title"); $mail->bodyHTML($text); $mail->send(); }); The problem is that this will send me an e-mail for every changed field, eg "Changed page X, field A" and "Changed page X, field B". But I want one single E-Mail that says "Changed page X, field A and B". getChanges() on the other hand (https://processwire.com/api/ref/page/get-changes/) does get me an array of changes, but without their old and new values! It should be possible using https://processwire.com/api/ref/wire/set-track-changes/ but where/how would I set this? Thx Link to comment Share on other sites More sharing options...
BitPoet Posted July 9, 2020 Share Posted July 9, 2020 Since your Page::changed hook is called, trackChanges already appears to be enabled. Have you tried getChanges(true) inside a saveReady hook? Also, the change information should be visible in arguments 1 and 2 in a Pages::saved hook. 1 1 Link to comment Share on other sites More sharing options...
bernhard Posted July 9, 2020 Author Share Posted July 9, 2020 Unfortunately not... I'm changing fields tmp1+2 from X to XX and Y to YY: This is what I tried in site/ready.php $wire->addHookBefore('Pages::saveReady', function($event) { $page = $event->arguments(0); $page->setTrackChanges(Wire::trackChangesValues); }); $wire->addHookAfter('Pages::saveReady', function($event) { $page = $event->arguments(0); bd($page->getChanges(true), 'getChanges'); }); $wire->addHookAfter('Pages::saved', function($event) { bd($event->arguments(1), 'changes'); bd($event->arguments(2), 'values'); }); $wire->addHookAfter('Page::changed', function(HookEvent $event) { bd($event->arguments(0), 'changed(0)'); bd($event->arguments(1), 'changed(1)'); }); Link to comment Share on other sites More sharing options...
MarkE Posted July 9, 2020 Share Posted July 9, 2020 Have you tried wire()->addHookBefore('Pages::save', function ($event) { $p = $event->arguments(0); // Get the previous version of the page $oldPage = wire('pages')->getById($p->id, array( 'cache' => false, // don't let it write to cache 'getFromCache' => false, // don't let it read from cache 'getOne' => true, // return a Page instead of a PageArray )); Then you can compare the old and new. Link to comment Share on other sites More sharing options...
Robin S Posted July 9, 2020 Share Posted July 9, 2020 Another approach to try: // Store page changes in custom property on $wire $wire->addHookAfter('Page(template=contact|sample)::changed', function(HookEvent $event) { $page = $event->object; $what = $event->arguments(0); $old = $event->arguments(1); $new = $event->arguments(2); $page_changes = $event->wire('page_changes') ?: []; $page_changes[$page->id][$what] = [ 'old' => $old, 'new' => $new, ]; $event->wire('page_changes', $page_changes); }); // Send email if there are page changes after the request is finished $wire->addHookAfter('ProcessWire::finished', function(HookEvent $event) { $page_changes = $event->wire('page_changes'); if($page_changes) { // Send the email using the values in $page_changes ... } }); 3 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now