Development

Changeset 24620

You must first sign up to be able to contribute.

Changeset 24620

Show
Ignore:
Timestamp:
12/01/09 00:38:19 (3 years ago)
Author:
Kris.Wallsmith
Message:

[1.3, 1.4] fixed module option being ignored in *:generate-admin task (closes #5572, #6773)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.3/lib/plugins/sfDoctrinePlugin/lib/task/sfDoctrineGenerateAdminTask.class.php

    r23810 r24620  
    102102    $name = strtolower(preg_replace(array('/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'), '\\1_\\2', $model)); 
    103103 
     104    if (isset($options['module'])) 
     105    { 
     106      $route = $this->getRouteFromName($name); 
     107      if ($route && !$this->checkRoute($route, $model, $options['module'])) 
     108      { 
     109        $name .= '_'.$options['module']; 
     110      } 
     111    } 
     112 
    104113    $routing = sfConfig::get('sf_app_config_dir').'/routing.yml'; 
    105114    $content = file_get_contents($routing); 
     
    178187    return false; 
    179188  } 
     189 
     190  /** 
     191   * Checks whether a route references a model and module. 
     192   * 
     193   * @param mixed  $route  A route collection 
     194   * @param string $model  A model name 
     195   * @param string $module A module name 
     196   * 
     197   * @return boolean 
     198   */ 
     199  protected function checkRoute($route, $model, $module) 
     200  { 
     201    if ($route instanceof sfDoctrineRouteCollection) 
     202    { 
     203      $options = $route->getOptions(); 
     204      return $model == $options['model'] && $module == $options['module']; 
     205    } 
     206 
     207    return false; 
     208  } 
    180209} 
  • branches/1.3/lib/plugins/sfPropelPlugin/lib/task/sfPropelGenerateAdminTask.class.php

    r23194 r24620  
    102102    $name = strtolower(preg_replace(array('/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'), '\\1_\\2', $model)); 
    103103 
     104    if (isset($options['module'])) 
     105    { 
     106      $route = $this->getRouteFromName($name); 
     107      if ($route && !$this->checkRoute($route, $model, $options['module'])) 
     108      { 
     109        $name .= '_'.$options['module']; 
     110      } 
     111    } 
     112 
    104113    $routing = sfConfig::get('sf_app_config_dir').'/routing.yml'; 
    105114    $content = file_get_contents($routing); 
     
    108117    if (!isset($routesArray[$name])) 
    109118    { 
    110       $primaryKey = 'id'; 
    111       $map = call_user_func(array($model.'PEER', 'getTableMap')); 
    112       foreach ($map->getColumns() as $column) 
    113       { 
    114         if ($column->isPrimaryKey()) 
    115         { 
    116           $primaryKey = call_user_func(array(constant($model.'::PEER'), 'translateFieldName'), $column->getPhpName(), BasePeer::TYPE_PHPNAME, BasePeer::TYPE_FIELDNAME); 
    117           break; 
    118         } 
    119       } 
    120  
     119      $primaryKey = $this->getPrimaryKey($model); 
    121120      $module = $options['module'] ? $options['module'] : $name; 
    122121      $content = sprintf(<<<EOF 
     
    187186    return false; 
    188187  } 
     188 
     189  /** 
     190   * Checks whether a route references a model and module. 
     191   * 
     192   * @param mixed  $route  A route collection 
     193   * @param string $model  A model name 
     194   * @param string $module A module name 
     195   * 
     196   * @return boolean 
     197   */ 
     198  protected function checkRoute($route, $model, $module) 
     199  { 
     200    if ($route instanceof sfPropelRouteCollection) 
     201    { 
     202      $options = $route->getOptions(); 
     203      return $model == $options['model'] && $module == $options['module']; 
     204    } 
     205 
     206    return false; 
     207  } 
     208 
     209  /** 
     210   * Returns the name of the model's primary key column. 
     211   * 
     212   * @param string $model A model name 
     213   * 
     214   * @return string A column name 
     215   */ 
     216  protected function getPrimaryKey($model) 
     217  { 
     218    $map = call_user_func(array(constant($model.'::PEER'), 'getTableMap')); 
     219 
     220    if (!$pks = $map->getPrimaryKeys()) 
     221    { 
     222      return 'id'; 
     223    } 
     224 
     225    $column = array_shift($pks); 
     226 
     227    return $column->getName(); 
     228  } 
    189229} 
  • branches/1.4/lib/plugins/sfDoctrinePlugin/lib/task/sfDoctrineGenerateAdminTask.class.php

    r23810 r24620  
    102102    $name = strtolower(preg_replace(array('/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'), '\\1_\\2', $model)); 
    103103 
     104    if (isset($options['module'])) 
     105    { 
     106      $route = $this->getRouteFromName($name); 
     107      if ($route && !$this->checkRoute($route, $model, $options['module'])) 
     108      { 
     109        $name .= '_'.$options['module']; 
     110      } 
     111    } 
     112 
    104113    $routing = sfConfig::get('sf_app_config_dir').'/routing.yml'; 
    105114    $content = file_get_contents($routing); 
     
    178187    return false; 
    179188  } 
     189 
     190  /** 
     191   * Checks whether a route references a model and module. 
     192   * 
     193   * @param mixed  $route  A route collection 
     194   * @param string $model  A model name 
     195   * @param string $module A module name 
     196   * 
     197   * @return boolean 
     198   */ 
     199  protected function checkRoute($route, $model, $module) 
     200  { 
     201    if ($route instanceof sfDoctrineRouteCollection) 
     202    { 
     203      $options = $route->getOptions(); 
     204      return $model == $options['model'] && $module == $options['module']; 
     205    } 
     206 
     207    return false; 
     208  } 
    180209} 
  • branches/1.4/lib/plugins/sfPropelPlugin/lib/task/sfPropelGenerateAdminTask.class.php

    r23194 r24620  
    102102    $name = strtolower(preg_replace(array('/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'), '\\1_\\2', $model)); 
    103103 
     104    if (isset($options['module'])) 
     105    { 
     106      $route = $this->getRouteFromName($name); 
     107      if ($route && !$this->checkRoute($route, $model, $options['module'])) 
     108      { 
     109        $name .= '_'.$options['module']; 
     110      } 
     111    } 
     112 
    104113    $routing = sfConfig::get('sf_app_config_dir').'/routing.yml'; 
    105114    $content = file_get_contents($routing); 
     
    108117    if (!isset($routesArray[$name])) 
    109118    { 
    110       $primaryKey = 'id'; 
    111       $map = call_user_func(array($model.'PEER', 'getTableMap')); 
    112       foreach ($map->getColumns() as $column) 
    113       { 
    114         if ($column->isPrimaryKey()) 
    115         { 
    116           $primaryKey = call_user_func(array(constant($model.'::PEER'), 'translateFieldName'), $column->getPhpName(), BasePeer::TYPE_PHPNAME, BasePeer::TYPE_FIELDNAME); 
    117           break; 
    118         } 
    119       } 
    120  
     119      $primaryKey = $this->getPrimaryKey($model); 
    121120      $module = $options['module'] ? $options['module'] : $name; 
    122121      $content = sprintf(<<<EOF 
     
    187186    return false; 
    188187  } 
     188 
     189  /** 
     190   * Checks whether a route references a model and module. 
     191   * 
     192   * @param mixed  $route  A route collection 
     193   * @param string $model  A model name 
     194   * @param string $module A module name 
     195   * 
     196   * @return boolean 
     197   */ 
     198  protected function checkRoute($route, $model, $module) 
     199  { 
     200    if ($route instanceof sfPropelRouteCollection) 
     201    { 
     202      $options = $route->getOptions(); 
     203      return $model == $options['model'] && $module == $options['module']; 
     204    } 
     205 
     206    return false; 
     207  } 
     208 
     209  /** 
     210   * Returns the name of the model's primary key column. 
     211   * 
     212   * @param string $model A model name 
     213   * 
     214   * @return string A column name 
     215   */ 
     216  protected function getPrimaryKey($model) 
     217  { 
     218    $map = call_user_func(array(constant($model.'::PEER'), 'getTableMap')); 
     219 
     220    if (!$pks = $map->getPrimaryKeys()) 
     221    { 
     222      return 'id'; 
     223    } 
     224 
     225    $column = array_shift($pks); 
     226 
     227    return $column->getName(); 
     228  } 
    189229}