Development

Changeset 3386 for branches/1.0/lib

You must first sign up to be able to contribute.

Changeset 3386 for branches/1.0/lib

Show
Ignore:
Timestamp:
02/01/07 10:53:58 (2 years ago)
Author:
fabien
Message:

fixed sfPropelData::dumpData (primary key at the end of column definition + ordering of tables to take foreign keys into account)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.0/lib/addon/propel/sfPropelData.class.php

    r3382 r3386  
    263263    array_walk($tables, array($this, 'loadMapBuilder')); 
    264264 
    265     foreach ($tables as $table) 
    266     { 
    267       $tableMap = $this->maps[$table]->getDatabaseMap()->getTable(constant($table.'Peer::TABLE_NAME')); 
     265    // reordering tables to take foreign keys into account 
     266    $move = true; 
     267    while ($move) 
     268    { 
     269      foreach ($tables as $i => $tableName) 
     270      { 
     271        $tableMap = $this->maps[$tableName]->getDatabaseMap()->getTable(constant($tableName.'Peer::TABLE_NAME')); 
     272 
     273        foreach ($tableMap->getColumns() as $column) 
     274        { 
     275          if ($column->isForeignKey()) 
     276          { 
     277            $relatedTable = $this->maps[$tableName]->getDatabaseMap()->getTable($column->getRelatedTableName()); 
     278            if (array_search($relatedTable->getPhpName(), $tables) > $i) 
     279            { 
     280              unset($tables[$i]); 
     281              $tables[] = $tableName; 
     282              $move = true; 
     283              continue 2; 
     284            } 
     285          } 
     286        } 
     287 
     288        $move = false; 
     289      } 
     290    } 
     291 
     292    foreach ($tables as $tableName) 
     293    { 
     294      $tableMap = $this->maps[$tableName]->getDatabaseMap()->getTable(constant($tableName.'Peer::TABLE_NAME')); 
    268295 
    269296      // get db info 
    270       $rs = $con->executeQuery('SELECT * FROM '.constant($table.'Peer::TABLE_NAME')); 
    271  
    272       $dumpData[$table] = array(); 
    273  
    274       while ($rs->next()) { 
    275         $pk = ''; 
     297      $rs = $con->executeQuery('SELECT * FROM '.constant($tableName.'Peer::TABLE_NAME')); 
     298 
     299      $dumpData[$tableName] = array(); 
     300 
     301      while ($rs->next()) 
     302      { 
     303        $pk = $tableName; 
     304        $values = array(); 
    276305        foreach ($tableMap->getColumns() as $column) 
    277306        { 
    278307          $col = strtolower($column->getColumnName()); 
    279  
    280308          if ($column->isPrimaryKey()) 
    281309          { 
    282             $pk .= '_' .$rs->get($col); 
    283             continue; 
     310            $pk .= '_'.$rs->get($col); 
    284311          } 
    285312          else if ($column->isForeignKey()) 
    286313          { 
    287             $relatedTable = $this->maps[$table]->getDatabaseMap()->getTable($column->getRelatedTableName()); 
    288  
    289             $dumpData[$table][$table.$pk][$col] = $relatedTable->getPhpName().'_'.$rs->get($col); 
     314            $relatedTable = $this->maps[$tableName]->getDatabaseMap()->getTable($column->getRelatedTableName()); 
     315 
     316            $values[$col] = $relatedTable->getPhpName().'_'.$rs->get($col); 
    290317          } 
    291318          else 
    292319          { 
    293             $dumpData[$table][$table.$pk][$col] = $rs->get($col); 
    294           } 
    295         } 
     320            $values[$col] = $rs->get($col); 
     321          } 
     322        } 
     323 
     324        $dumpData[$tableName][$pk] = $values; 
    296325      } 
    297326    }