Development

#1566: sfPropelData.class.patch

You must first sign up to be able to contribute.

Ticket #1566: sfPropelData.class.patch

File sfPropelData.class.patch, 4.2 kB (added by Andrew.Tchircoff, 2 years ago)

Patch for sfPropelData class

  • sfPropelData.class.php

    old new  
    8686 
    8787      // iterate through datas for this class 
    8888      // might have been empty just for force a table to be emptied on import 
    89       if (!is_array($datas)) 
    90       { 
    91         return; 
    92       } 
    93  
    94       foreach ($datas as $key => $data) 
    95       { 
    96         // create a new entry in the database 
    97         $obj = new $class(); 
    98  
    99         if (!is_array($data)) 
    100         { 
    101           throw new Exception('You must give a name for each fixture data entry'); 
    102         } 
    103  
    104         foreach ($data as $name => $value) 
    105         { 
    106           // foreign key? 
    107           try 
    108           { 
    109             $column = $tableMap->getColumn($name); 
    110             if ($column->isForeignKey() && !is_null($value)) 
    111             { 
    112               $relatedTable = $this->maps[$class]->getDatabaseMap()->getTable($column->getRelatedTableName()); 
    113               if (!isset($this->object_references[$relatedTable->getPhpName().'_'.$value])) 
    114               { 
    115                 $error = 'The object "%s" from class "%s" is not defined in your data file.'; 
    116                 $error = sprintf($error, $value, $relatedTable->getPhpName()); 
    117                 throw new sfException($error); 
    118               } 
    119               $value = $this->object_references[$relatedTable->getPhpName().'_'.$value]; 
    120             } 
    121           } 
    122           catch (PropelException $e) 
    123           { 
    124           } 
    125  
    126           $pos = array_search($name, $column_names); 
    127           $method = 'set'.sfInflector::camelize($name); 
    128           if ($pos) 
    129           { 
    130             $obj->setByPosition($pos, $value); 
    131           } 
    132           else if (is_callable(array($obj, $method))) 
    133           { 
    134             $obj->$method($value); 
    135           } 
    136           else 
    137           { 
    138             $error = 'Column "%s" does not exist for class "%s"'; 
    139             $error = sprintf($error, $name, $class); 
    140             throw new sfException($error); 
    141           } 
    142         } 
    143         $obj->save(); 
    144  
    145         // save the id for future reference 
    146         if (method_exists($obj, 'getPrimaryKey')) 
    147         { 
    148           $this->object_references[$class.'_'.$key] = $obj->getPrimaryKey(); 
    149         } 
    150       } 
     89            if(is_array($datas)) 
     90            { 
     91          foreach ($datas as $key => $data) 
     92          { 
     93            // create a new entry in the database 
     94            $obj = new $class(); 
     95                     
     96            if (!is_array($data)) 
     97            { 
     98              throw new Exception('You must give a name for each fixture data entry'); 
     99            } 
     100 
     101            foreach ($data as $name => $value) 
     102            { 
     103              // foreign key? 
     104              try 
     105              { 
     106                $column = $tableMap->getColumn($name); 
     107                if ($column->isForeignKey() && !is_null($value)) 
     108                { 
     109                  $relatedTable = $this->maps[$class]->getDatabaseMap()->getTable($column->getRelatedTableName()); 
     110                  if (!isset($this->object_references[$relatedTable->getPhpName().'_'.$value])) 
     111                  { 
     112                    $error = 'The object "%s" from class "%s" is not defined in your data file.'; 
     113                    $error = sprintf($error, $value, $relatedTable->getPhpName()); 
     114                    throw new sfException($error); 
     115                  } 
     116                  $value = $this->object_references[$relatedTable->getPhpName().'_'.$value]; 
     117                } 
     118              } 
     119              catch (PropelException $e) 
     120              { 
     121              } 
     122 
     123              $pos = array_search($name, $column_names); 
     124              $method = 'set'.sfInflector::camelize($name); 
     125              if ($pos) 
     126              { 
     127                $obj->setByPosition($pos, $value); 
     128              } 
     129              else if (is_callable(array($obj, $method))) 
     130              { 
     131                $obj->$method($value); 
     132              } 
     133              else 
     134              { 
     135                $error = 'Column "%s" does not exist for class "%s"'; 
     136                $error = sprintf($error, $name, $class); 
     137                throw new sfException($error); 
     138              } 
     139            } 
     140            $obj->save(); 
     141 
     142            // save the id for future reference 
     143            if (method_exists($obj, 'getPrimaryKey')) 
     144            { 
     145              $this->object_references[$class.'_'.$key] = $obj->getPrimaryKey(); 
     146            } 
     147          } 
     148            } 
    151149    } 
    152150  } 
    153151