Development

Changeset 3693

You must first sign up to be able to contribute.

Changeset 3693

Show
Ignore:
Timestamp:
04/02/07 13:26:06 (2 years ago)
Author:
fabien
Message:

plugins: fixed deleting sfGuardUser when no profile is defined (closes #1626)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfGuardPlugin/lib/model/sfGuardUser.php

    r3406 r3693  
    7777  public function getProfile() 
    7878  { 
    79     if (null === $this->profile) 
    80     { 
    81       $profileClass = sfConfig::get('app_sf_guard_plugin_profile_class', 'sfGuardUserProfile'); 
    82       if (!class_exists($profileClass)) 
    83       { 
    84         throw new sfException(sprintf('The user profile class "%s" does not exist.', $profileClass)); 
    85       } 
    86  
    87       $fieldName = sfConfig::get('app_sf_guard_plugin_profile_field_name', 'user_id'); 
    88       $profilePeerClass =  $profileClass.'Peer'; 
    89  
    90       // to avoid php segmentation fault 
    91       class_exists($profilePeerClass); 
    92  
    93       $foreignKeyColumn = call_user_func_array(array($profilePeerClass, 'translateFieldName'), array($fieldName, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_COLNAME)); 
    94  
    95       if (!$foreignKeyColumn) 
    96       { 
    97         throw new sfException(sprintf('The user profile class "%s" does not contain a "%s" column.', $profileClass, $fieldName)); 
    98       } 
    99  
    100       $c = new Criteria(); 
    101       $c->add($foreignKeyColumn, $this->getId()); 
    102  
    103       $this->profile = call_user_func_array(array($profileClass.'Peer', 'doSelectOne'), array($c)); 
    104  
    105       if (!$this->profile) 
    106       { 
    107         $this->profile = new $profileClass(); 
    108         $method = 'set'.call_user_func_array(array($profilePeerClass, 'translateFieldName'), array($fieldName, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_PHPNAME)); 
    109         $this->profile->$method($this->getId()); 
    110       } 
     79    if (!is_null($this->profile)) 
     80    { 
     81      return $this->profile; 
     82    } 
     83 
     84    $profileClass = sfConfig::get('app_sf_guard_plugin_profile_class', 'sfGuardUserProfile'); 
     85    if (!class_exists($profileClass)) 
     86    { 
     87      throw new sfException(sprintf('The user profile class "%s" does not exist.', $profileClass)); 
     88    } 
     89 
     90    $fieldName = sfConfig::get('app_sf_guard_plugin_profile_field_name', 'user_id'); 
     91    $profilePeerClass =  $profileClass.'Peer'; 
     92 
     93    // to avoid php segmentation fault 
     94    class_exists($profilePeerClass); 
     95 
     96    $foreignKeyColumn = call_user_func_array(array($profilePeerClass, 'translateFieldName'), array($fieldName, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_COLNAME)); 
     97 
     98    if (!$foreignKeyColumn) 
     99    { 
     100      throw new sfException(sprintf('The user profile class "%s" does not contain a "%s" column.', $profileClass, $fieldName)); 
     101    } 
     102 
     103    $c = new Criteria(); 
     104    $c->add($foreignKeyColumn, $this->getId()); 
     105 
     106    $this->profile = call_user_func_array(array($profileClass.'Peer', 'doSelectOne'), array($c)); 
     107 
     108    if (!$this->profile) 
     109    { 
     110      $this->profile = new $profileClass(); 
     111      $method = 'set'.call_user_func_array(array($profilePeerClass, 'translateFieldName'), array($fieldName, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_PHPNAME)); 
     112      $this->profile->$method($this->getId()); 
    111113    } 
    112114 
     
    251253  public function delete($con = null) 
    252254  { 
    253     if ($profile = $this->getProfile()) 
    254     { 
    255       $profile->delete(); 
     255    // delete profile if available 
     256    try 
     257    { 
     258      if ($profile = $this->getProfile()) 
     259      { 
     260        $profile->delete(); 
     261      } 
     262    } 
     263    catch (sfException $e) 
     264    { 
    256265    } 
    257266 
  • plugins/sfGuardPlugin/package.xml

    r3422 r3693  
    2323  <active>yes</active> 
    2424 </lead> 
    25  <date>2007-02-07</date> 
     25 <date>2007-04-02</date> 
    2626 <version> 
    27    <release>1.1.6</release> 
     27   <release>1.1.7</release> 
    2828   <api>1.1.0</api> 
    2929 </version>