I need to compare if a certain property of my object has changed when someone is saving it. I wrote a plugin to be able to add some functionality before and after updating an object in the backend happens.
So, I don’t know if this is not working as expected or if I’m getting this wrong.
I thought I would get the state before it is saved to the database in:
function preUpdateObject(Object_MyObject $object) {}
And the new state of the object in
function postUpdateObject(Object_MyObject $object) {}
But this doesn’t work:
public function preUpdateObject(Object_MyObject $object) {
$this->tempOldDate = $object->getUpdate();
}
public function postUpdateObject(Object_MyObject $object){
if($this->tempOldDate->compareDate($object->getUpdate()) == -1) {
// do something because a newer date has been entered
}
}
Any clue how I can get the old object state BEFORE it is updated??
Seems like this function is not working as expected. I filed a bug report:
http://www.pimcore.org/issues/browse/PIMCORE-1232
I created a workaround that can be used.
The database is NOT updated. So it’s correct that preUpdateObject is the function to use to get the object state, but:
Check that database is not updated…. I want a date from my object that sits in table ‘object_1’
Using the generated Object class doesn’t work, but if you clear the cache it does