Accessing previous version of page before/after page save
Posted 16 March 2012 - 06:12 AM
I tried before page save to get the page using something like $previousVersion = wire('pages')->get($page->id); but that didn't work (and certainly wouldn't work after page save ).
It's probably something simple like $_POST vars I bet, but just wanted to check.
Posted 16 March 2012 - 09:41 AM
$pageCopy = clone $page;
From that point forward, any changes to $page won't be seen in $pageCopy. This clone will cease to exist once it is out of memory scope.
For obvious reasons, file-based assets aren't cloned here. So if your clone depends on file/image assets, then you have to create a new page not just in memory, but on database/disk too. Here's how you do that:
$pageCopy = $pages->clone($page);
That does a recursive clone, cloning not just that page, but any children too. See the parameters to the $pages->clone() function for additional options to control this. You can also specify that you want it to clone to a different parent. Be careful with the cloning as it's something you probably don't want to do on every page save. It can be an expensive operation if there are lots of files or subpages associated with the cloned page.
Posted 16 March 2012 - 10:02 AM
Literally all I want to do is compare the value of a field before the person hit Save and what the value is after they click Save by using a beforePageSave hook if that makes sense.
Posted 16 March 2012 - 10:06 AM
wire('pages')->uncacheAll(); $oldPage = wire('pages')->get($page->id);
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users