I have the same request like Pete and the autor of Hooks, compare page before and after save , I need the unchanged page in the state like it was before the page was saved.
Before reading this post, I tried to implement a hook before Pages::save, but I always get the changed page there.
I tried to add your code to get the old page, but 1. it still gives me the already changed page, and 2. adding this code reverts the changes after saving.
I mean, I change something in the page, save this page, (my hook is triggered), when the saved page in backend is reloaded, my changes are gone.
That is my code:
$this->addHookBefore('Pages::save', function (HookEvent $event) {
$page = $event->arguments(0);
if ($page->hasField('my_questions')) {
wire('pages')->uncacheAll();
$oldPage = wire('pages')->get($page->id);
$this->log("Questions before: " . $page->my_questions);
$this->log("Questions after : " . $oldPage->my_questions);
}
});
Any ideas how I can get the "oldPage" that realy works?
p.s. I am working in ProcessWire 3.0.184