on_page_update event and attribute values

Permalink
I am experiencing some problems in accessing attribute values from the Page object that is passed to the on_page_update event. The values received are the ones from the time that the page properties form is first displayed, rather than as they are at the time that the form is saved.

E.g.:
function on_page_update($page) {
$file = $page->getCollectionAttributeValue('pdf_file');
if ($file && !$file->error) {
$filename = $file->getRelativePath();
}
error_log($filename); //old value appears here
}

What I am doing seems intuitively correct. But it seems there is little chance, after poking through the core, that the updated attribute values would be available at the time that the on_page_update event is called.

In concrete/startup/process.php lines 839 and 840 appear thus:
$nvc->update($data);
processMetaData($nvc);

The on_page_update event is called at the end of the update method above.
The processMetaData function seems to be responsible for extracting the submitted attribute values out of $_POST and saving them away into the relevant attributes. As this is after the on_page_update event has been and gone, it is little wonder that I receive the old values.

Can somebody advise me if my intuitive perception of this is correct? If it is and this is a bug, is there an effective work-around? And can this bug be fixed?

Thanks.

 
C5LABS replied on at Permalink Reply
C5LABS
stephencain replied on at Permalink Reply
Thanks for the referal, but it does not seem to discuss the problem that I am experiencing.

The on_page_update fires when I expect it and want it, i.e. immeadiately after the Save button on the page properties dialog is clicked.

The issue is that the ammended attribute values do not are not available in the page object that is passed to the event.

Using the on_page_version_approve event almost solves my problem; but not quite. If a user vists a page and edits values in the page properties dialog, when the page is subsequently approved then the updated values for the page attributes are available to the page object in the on_page_version_approve event that is fired.

BUT: If a user goes into the sitemap and accesses a page's properties from there, then upon saving them the on_page_update is fired immeadiately followed by the on_page_version_approve event. And both are passed a page object with the previous attribute values. Which due to the inconsistency is the worst of all worlds.
jordanlev replied on at Permalink Reply
jordanlev
The problem does seem to be that the page object passed to the event handler contains the OLD values, not the new updated values. Simple solution: grab the collection ID from the passed-in page, then retrieve the page from the database again to get its newly-updated values. For example:
public function my_on_page_update_handler($page) {
   $updated_page = Page::getByID($page->getCollectionID());
   $something = $updated_page->getCollectionName();
   //etc.
}


-Jordan