2011-11-16 30 views
1

我需要比较某人某个特定属性的对象是否在某人保存时发生了更改。我编写了一个插件,以便能够在更新后端对象之前和之后添加一些功能。Pimcore - 在preUpdateObject挂钩中获取旧对象状态

所以,我不知道这是不是按预期工作,或者如果我得到这个错误。

我想我会得到状态之前它是在保存到数据库:

function preUpdateObject(Object_MyObject $object) {} 

和对象的

function postUpdateObject(Object_MyObject $object) {} 

新的状态,但是,这并不工作:

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 
    } 
} 

任何线索如何才能得到旧的对象状态之前它是更新?

回答

0

看起来像这个功能没有按预期工作。我提交了一个错误报告: http://www.pimcore.org/issues/browse/PIMCORE-1232

我创建了一个可以使用的解决方法。

数据库未更新。因此,它是正确的,preUpdateObject的功能是用来获取对象的状态,但:

检查数据库没有更新....我想从我的目标是,在表中位于“object_1”

// oldDate has the old value 
$dbAdapter = Pimcore_Resource_Mysql::get("database"); 
$dbentry = $dbAdapter->fetchRow(
       $dbAdapter->select() 
         ->from('object_1') 
         ->where('o_id = ?', $object->getId()));  
$oldDate = new Pimcore_Date($dbentry['update']); 
日期

使用生成的Object类是不行的,但如果你清除缓存它

// get's the new date from the editor 
$oldDate = Object_MyObject::getById($object->getId())->getUpdate(); 
// this also works but don't know if it is safe to delete 
// the object from the registry 
Zend_Registry::set('object_' . $object->getId(), false); 
$oldDate = Object_MyObject::getById($object->getId())->getUpdate();