Development

Changeset 11230

You must first sign up to be able to contribute.

Changeset 11230

Show
Ignore:
Timestamp:
08/28/08 18:24:16 (3 months ago)
Author:
Kris.Wallsmith
Message:

sfPropelPlugin [migration]: Added sfPropelTable::asCreateTableSql(), migration model ->unwrap() methods now clone the internal object.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfPropelPlugin/branches/migration/lib/propel/migration/model/sfPropelColumn.class.php

    r11229 r11230  
    170170   *  
    171171   * @see sfPropelModel 
     172   *  
     173   * @throws InvalidArgumentException If the parameter is null 
    172174   */ 
    173175  public function unwrap($value = null) 
    174176  { 
    175     if ($value instanceof sfPropelTable) 
    176     { 
     177    if (is_null($value)) 
     178    { 
     179      throw new InvalidArgumentException(sprintf('%s expects a sfPropelTable object as its first parameter.', __METHOD__)); 
     180    } 
     181    elseif ($value instanceof sfPropelTable) 
     182    { 
     183      $column = clone $this->column; 
     184 
    177185      if ($this->indexType) 
    178186      { 
    179         $value->addIndex(sfPropelIndex::type($this->indexType)->column($this->column)); 
     187        $value->addIndex(sfPropelIndex::type($this->indexType)->column($column)); 
    180188      } 
    181189 
     
    185193        $fk->setTable($value->unwrap()); 
    186194        $fk->setForeignTableName($this->fkTable); 
    187         $fk->addReference($this->column->getName(), $this->fkColumn); 
     195        $fk->addReference($column->getName(), $this->fkColumn); 
    188196        $fk->setOnDelete($this->fkOnDelete); 
    189197        $fk->setOnUpdate($this->fkOnUpdate); 
     
    192200      } 
    193201 
    194       return $this->column; 
     202      return $column; 
    195203    } 
    196204 
  • plugins/sfPropelPlugin/branches/migration/lib/propel/migration/model/sfPropelIndex.class.php

    r11229 r11230  
    8181   *  
    8282   * @see sfPropelModel 
     83   *  
     84   * @throws InvalidArgumentException If the parameter is null 
    8385   */ 
    8486  public function unwrap($value = null) 
    8587  { 
    86     if ($value instanceof sfPropelTable
     88    if (is_null($value)
    8789    { 
     90      throw new InvalidArgumentException(sprintf('%s expects a sfPropelTable object as its first parameter.', __METHOD__)); 
     91    } 
     92    elseif ($value instanceof sfPropelTable) 
     93    { 
     94      $index = clone $this->index; 
     95 
    8896      $columns = $value->unwrap()->getColumns(); 
    8997      $columns = array_combine(array_map(create_function('$c', 'return $c->getName();'), $columns), $columns); 
    90  
    91       $index = clone $this->index; 
    9298 
    9399      foreach ($this->columns as $name) 
  • plugins/sfPropelPlugin/branches/migration/lib/propel/migration/model/sfPropelModel.class.php

    r11229 r11230  
    5252    if (is_null($value)) 
    5353    { 
    54       return $this->model; 
     54      $model = clone $this->model; 
     55 
     56      return $model; 
    5557    } 
    5658 
     
    6163   * @return Database 
    6264   */ 
    63   protected function getDatabase(
     65  protected function getDatabase($driver = null
    6466  { 
    6567    $database = new Database; 
    66     $database->setPlatform($this->getPlatform()); 
     68    $database->setPlatform($this->getPlatform($driver)); 
    6769 
    6870    return $database; 
     
    7274   * @return DefaultPlatform 
    7375   */ 
    74   protected function getPlatform(
     76  protected function getPlatform($driver = null
    7577  { 
    76     $class = ucwords(sfPropelBaseTask::getGeneratorConfig()->getBuildProperty('database')).'Platform'; 
     78    if (is_null($driver)) 
     79    { 
     80      $driver = sfPropelBaseTask::getGeneratorConfig()->getBuildProperty('database'); 
     81    } 
     82 
     83    $class = ucwords($driver).'Platform'; 
    7784    return new $class; 
    7885  } 
  • plugins/sfPropelPlugin/branches/migration/lib/propel/migration/model/sfPropelTable.class.php

    r11229 r11230  
    8888 
    8989  /** 
     90   * Exports the configured table as create table SQL. 
     91   *  
     92   * @param   string $driver 
     93   *  
     94   * @return  string 
     95   */ 
     96  public function asCreateTableSql($driver = null) 
     97  { 
     98    $table = $this->unwrap(); 
     99 
     100    $generatorConfig = sfPropelBaseTask::getGeneratorConfig(); 
     101    if (is_null($driver)) 
     102    { 
     103      $driver = $generatorConfig->getBuildProperty('database'); 
     104    } 
     105    else 
     106    { 
     107      $table->setDatabase($this->getDatabase($driver)); 
     108    } 
     109 
     110    $builderClass = ucwords($driver).'DDLBuilder'; 
     111    $builder = new $builderClass($table); 
     112    $builder->setGeneratorConfig($generatorConfig); 
     113 
     114    $script  = $builder->getDatabaseStartDDL(); 
     115    $script .= $builder->build(); 
     116    $script .= $builder->getDatabaseEndDDL(); 
     117 
     118    return $script; 
     119  } 
     120 
     121  /** 
    90122   * @see sfPropelModel 
    91123   */ 
     
    94126    if (is_null($value)) 
    95127    { 
    96       $this->table->doFinalInitialization(); 
    97       return $this->table; 
     128      $table = clone $this->table; 
     129      $table->doFinalInitialization(); 
     130 
     131      return $table; 
    98132    } 
    99133