public function populateFromFacebook($doSave = true) { $fb = $this->getFacebook(); if (!($sfGuardUser = $this->getGuardUser())) { if ($email = $fb->getEmail()) { //-- Emails must be uniqe so start there $sfGuardUser = Doctrine::getTable('sfGuardUser')->findOneByEmailAddress($email); } if (!$sfGuardUser && ($fb_uid = $fb->getId())) { $sfGuardUser = Doctrine::getTable('sfGuardUser')->findOneByFacebookUid($fb_uid); } if (!$sfGuardUser) { $sfGuardUser = new sfGuardUser(); } } //-- If it is in the session but not the guard User, add it to the guard user if (!$sfGuardUser->getFacebookAuthCode() && $this->getAttribute('facebook_auth_code')) { if (sfConfig::get('sf_logging_enabled')) { sfContext::getInstance()->getLogger()->info('--- DEBUG --- FB AUTH CODE in session but not the guard User'); } $sfGuardUser->setFacebookAuthCode($this->getAttribute('facebook_auth_code')); } $sfGuardUser->populateWithFacebook($fb); if ($doSave) { $sfGuardUser->save(); $this->signin($sfGuardUser); } //-- NOTE: The $sfGuardUser MAY NOT be saved yet! $dispatcher = sfContext::getInstance()->getEventDispatcher(); $dispatcher->notify(new sfEvent($sfGuardUser, 'm14tFacebook.connect', array())); return $sfGuardUser; }