Using sfFilter to update DB with Doctrine
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::g开发者_运维知识库et('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.
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.
精彩评论