Using sfFilter to update DB with Doctrine

强颜欢笑 提交于 2019-12-11 00:30:44

问题


I've created a sfFilter to update the current module where the user is at:


class SessionFilter extends sfFilter {
    public function execute($filterChain){
        if ($this->isFirstCall()){
            $user = $this->getContext()->getUser()->getId();
            $module = $this->getContext()->getModuleName();
            Doctrine::getTable('ActiveSession')->set($user, $module);
            Doctrine::getTable('ActiveSession')->refresh();
        }

        $filterChain->execute();
    }
}

When I look up into the db I found out that the record has set the field 'module' at 'default' but when I see the log it says:


UPDATE active_session SET module = 'secretary' WHERE (sys_user_id = '2')

Does anyone know how to fix this behaviour?

EDIT: I forgot to put the set and refresh method's

class ActiveSessionTable extends Doctrine_Table
{
    public function set($userId, $module){
        $q = $this->createQuery()->update()
            ->set('module','?', $module)
            ->where("sys_user_id = ?", array($userId))->execute();
    }

    public function refresh(){
        $time = time() - sfConfig::get('app_session_keep') * 60;
        $this->createQuery()->delete()->where('time < ?', $time)->execute();
    }
    ...
}

The refresh method should be used in other method but for testing I'm keeping it there.


回答1:


Well... to close this.

The only way I could accomplish what I wanted was to check if module was 'default':

class ActiveSessionTable extends Doctrine_Table
{
    public function set($userId, $module){
        if($module != 'default'){
            $q = $this->createQuery()->update()
               ->set('module','?', $module)
               ->where("sys_user_id = ?", array($userId))->execute();
        }
    }
   ...
}

really not a happy answer but couldn't find the right one.



来源:https://stackoverflow.com/questions/5054753/using-sffilter-to-update-db-with-doctrine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!