Development

Changeset 7059

You must first sign up to be able to contribute.

Changeset 7059

Show
Ignore:
Timestamp:
01/15/08 01:28:46 (10 months ago)
Author:
dwhittle
Message:

dwhittle: merged sf + propel changes to branch + fixed tests

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/dwhittle/1.1/lib/form/sfForm.class.php

    r6992 r7059  
    208208   * @param string The field name 
    209209   * @param sfForm A sfForm instance 
    210    * @param string The format to use for widget name 
    211210   * @param string A HTML decorator for the embedded form 
    212211   */ 
    213   public function embedForm($name, sfForm $form, $nameFormat = null, $decorator = null) 
    214   { 
    215     // change the name format for the embedded widget 
    216     if (is_null($nameFormat)) 
    217     { 
    218       $nameFormat = $this->generateNameFormatForEmbedded($name, $this->widgetSchema->getNameFormat()); 
    219     } 
    220  
     212  public function embedForm($name, sfForm $form, $decorator = null) 
     213  { 
    221214    $form = clone $form; 
    222215    unset($form[self::$CSRFFieldName]); 
    223216 
    224217    $widgetSchema = $form->getWidgetSchema(); 
    225     $widgetSchema->setNameFormat($nameFormat); 
    226218 
    227219    $this->setDefault($name, $form->getDefaults()); 
     
    240232   * @param string  The field name 
    241233   * @param sfForm  A sfForm instance 
    242    * @param integer The number of times to include the form 
    243    * @param string  The format to use for widget name 
     234   * @param integer The number of times to embed the form 
    244235   * @param string  A HTML decorator for the main form around embedded forms 
    245236   * @param string  A HTML decorator for each embedded form 
    246237   */ 
    247   public function embedFormForEach($name, sfForm $form, $n, $nameFormat = null, $decorator = null, $innerDecorator = null, $attributes = array(), $options = array(), $labels = array()) 
    248   { 
    249     // change the name format for the embedded widget 
    250     if (is_null($nameFormat)) 
    251     { 
    252       $nameFormat = $this->generateNameFormatForEmbedded($name, $this->widgetSchema->getNameFormat()); 
    253     } 
    254  
     238  public function embedFormForEach($name, sfForm $form, $n, $decorator = null, $innerDecorator = null, $attributes = array(), $options = array(), $labels = array()) 
     239  { 
    255240    $form = clone $form; 
    256241    unset($form[self::$CSRFFieldName]); 
     242 
     243    $widgetSchema = $form->getWidgetSchema(); 
    257244 
    258245    // generate labels and default values 
     
    262249      if (!isset($labels[$i])) 
    263250      { 
    264         $labels[$i] = sprintf('%s (%s)', $form->getWidgetSchema()->generateLabelName($name), $i); 
     251        $labels[$i] = sprintf('%s (%s)', $widgetSchema->generateLabelName($name), $i); 
    265252      } 
    266253 
     
    270257    $this->setDefault($name, $defaults); 
    271258 
    272     $decorator = is_null($decorator) ? $form->getWidgetSchema()->getFormFormatter()->getDecoratorFormat() : $decorator; 
    273     $innerDecorator = is_null($innerDecorator) ? $form->getWidgetSchema()->getFormFormatter()->getDecoratorFormat() : $innerDecorator; 
    274  
    275     $this->widgetSchema[$name] = new sfWidgetFormSchemaDecorator(new sfWidgetFormSchemaForEach($nameFormat, new sfWidgetFormSchemaDecorator($form->getWidgetSchema(), $innerDecorator), $n, $attributes, $options, $labels), $decorator); 
     259    $decorator = is_null($decorator) ? $widgetSchema->getFormFormatter()->getDecoratorFormat() : $decorator; 
     260    $innerDecorator = is_null($innerDecorator) ? $widgetSchema->getFormFormatter()->getDecoratorFormat() : $innerDecorator; 
     261 
     262    $this->widgetSchema[$name] = new sfWidgetFormSchemaDecorator(new sfWidgetFormSchemaForEach(new sfWidgetFormSchemaDecorator($widgetSchema, $innerDecorator), $n, $attributes, $options, $labels), $decorator); 
    276263    $this->validatorSchema[$name] = new sfValidatorSchemaForEach($form->getValidatorSchema(), $n); 
    277264 
     
    573560      $values = $this->isBound ? $this->taintedValues : $this->defaults; 
    574561 
    575       $this->formFields[$name] = new sfFormField($widget, $this->getFormField(), $name, isset($values[$name]) ? $values[$name] : null, $this->errorSchema[$name]); 
     562      $class = $widget instanceof sfWidgetFormSchema ? 'sfFormFieldSchema' : 'sfFormField'; 
     563 
     564      $this->formFields[$name] = new $class($widget, $this->getFormField(), $name, isset($values[$name]) ? $values[$name] : null, $this->errorSchema[$name]); 
    576565    } 
    577566 
     
    609598   * Returns a form field for the main widget schema. 
    610599   * 
    611    * @return sfFormField A sfFormField instance 
     600   * @return sfFormFieldSchema A sfFormFieldSchema instance 
    612601   */ 
    613602  protected function getFormField() 
     
    615604    if (is_null($this->formField)) 
    616605    { 
    617       $this->formField = new sfFormField($this->widgetSchema, null, null, $this->isBound ? $this->taintedValues : $this->defaults, $this->errorSchema); 
     606      $this->formField = new sfFormFieldSchema($this->widgetSchema, null, null, $this->isBound ? $this->taintedValues : $this->defaults, $this->errorSchema); 
    618607    } 
    619608 
    620609    return $this->formField; 
    621   } 
    622  
    623   /** 
    624    * Generates a name format for embedded forms. 
    625    * 
    626    * @param  string The widget name 
    627    * @param  string The current name format 
    628    * 
    629    * @return string The name format to use for embedding 
    630    * 
    631    * @see embedFormForEach() 
    632    * @see embedForm() 
    633    */ 
    634   protected function generateNameFormatForEmbedded($name, $nameFormat) 
    635   { 
    636     // if current name format is something[%s], change it to something[$name][%s] 
    637     // else change it to $name[%s] 
    638     if ('[%s]' === substr($nameFormat, -4)) 
    639     { 
    640       return sprintf('%s[%s][%%s]', substr($nameFormat, 0, -4), $name); 
    641     } 
    642     else 
    643     { 
    644       return sprintf('%s[%%s]', $name); 
    645     } 
    646610  } 
    647611 
     
    733697    return $str; 
    734698  } 
     699 
     700  public function __clone() 
     701  { 
     702    $this->widgetSchema    = clone $this->widgetSchema; 
     703    $this->validatorSchema = clone $this->validatorSchema; 
     704 
     705    // we rebind the cloned form because Exceptions are not clonable 
     706    $this->bind($this->taintedValues, $this->taintedFiles); 
     707  } 
    735708} 
  • branches/dwhittle/1.1/lib/form/sfFormField.class.php

    r6198 r7059  
    1717 * @version    SVN: $Id$ 
    1818 */ 
    19 class sfFormField implements ArrayAccess 
     19class sfFormField 
    2020{ 
    2121  protected 
     
    2424    $name   = '', 
    2525    $value  = null, 
    26     $error  = null, 
    27     $fields = array(); 
     26    $error  = null; 
    2827 
    2928  /** 
    3029   * Constructor. 
    3130   * 
    32    * @param sfWidget         A sfWidget instance 
     31   * @param sfWidgetForm     A sfWidget instance 
    3332   * @param sfFormField      The sfFormField parent instance (null for the root widget) 
    3433   * @param string           The field name 
     
    3635   * @param sfValidatorError A sfValidatorError instance 
    3736   */ 
    38   public function __construct(sfWidget $widget, sfFormField $parent = null, $name, $value, sfValidatorError $error = null) 
     37  public function __construct(sfWidgetForm $widget, sfFormField $parent = null, $name, $value, sfValidatorError $error = null) 
    3938  { 
    4039    $this->widget = $widget; 
     
    8079  public function renderRow($help = '') 
    8180  { 
    82     if ($this->widget instanceof sfWidgetFormSchema
    83     { 
    84       throw new LogicException('Unable to format a row on a sfWidgetFormSchema.'); 
     81    if (is_null($this->parent)
     82    { 
     83      throw new LogicException(sprintf('Unable to render the row for "%s".', $this->name)); 
    8584    } 
    8685 
    8786    $field = $this->parent->getWidget()->renderField($this->name, $this->value, $this->error); 
    8887 
    89     return strtr($this->parent->getWidget()->getFormFormatter()->formatRow($this->renderLabel(), $field, $this->error, $help), array('%hidden_fields%' => '')); 
     88    $error = $this->error instanceof sfValidatorErrorSchema ? $this->error->getGlobalErrors() : $this->error; 
     89 
     90    return strtr($this->parent->getWidget()->getFormFormatter()->formatRow($this->renderLabel(), $field, $error, $help), array('%hidden_fields%' => '')); 
    9091  } 
    9192 
     
    9596   * The formatted list will use the parent widget schema formatter. 
    9697   * 
    97    * @param  string The widget name 
    98    * 
    9998   * @return string The formatted error list 
    10099   */ 
    101100  public function renderError() 
    102101  { 
    103     if ($this->widget instanceof sfWidgetFormSchema) 
    104     { 
    105       throw new LogicException('Unable to format an error list on a sfWidgetFormSchema.'); 
    106     } 
    107  
    108     return $this->parent->getWidget()->getFormFormatter()->formatErrorsForRow($this->error); 
     102    if (is_null($this->parent)) 
     103    { 
     104      throw new LogicException(sprintf('Unable to render the error for "%s".', $this->name)); 
     105    } 
     106 
     107    $error = $this->error instanceof sfValidatorErrorSchema ? $this->error->getGlobalErrors() : $this->error; 
     108 
     109    return $this->parent->getWidget()->getFormFormatter()->formatErrorsForRow($error); 
    109110  } 
    110111 
     
    116117  public function renderLabel() 
    117118  { 
    118     if ($this->widget instanceof sfWidgetFormSchema
    119     { 
    120       throw new LogicException('Unable to render a label on a sfWidgetFormSchema.'); 
     119    if (is_null($this->parent)
     120    { 
     121      throw new LogicException(sprintf('Unable to render the label for "%s".', $this->name)); 
    121122    } 
    122123 
     
    131132  public function renderLabelName() 
    132133  { 
    133     if ($this->widget instanceof sfWidgetFormSchema
    134     { 
    135       throw new LogicException('Unable to render a label name on a sfWidgetFormSchema.'); 
     134    if (is_null($this->parent)
     135    { 
     136      throw new LogicException(sprintf('Unable to render the label name for "%s".', $this->name)); 
    136137    } 
    137138 
     
    198199    return !is_null($this->error) && count($this->error); 
    199200  } 
    200  
    201   /** 
    202    * Returns true if the bound field exists (implements the ArrayAccess interface). 
    203    * 
    204    * @param  string  The name of the bound field 
    205    * 
    206    * @return Boolean true if the widget exists, false otherwise 
    207    */ 
    208   public function offsetExists($name) 
    209   { 
    210     return $this->widget instanceof sfWidgetFormSchema ? isset($this->widget[$name]) : false; 
    211   } 
    212  
    213   /** 
    214    * Returns the form field associated with the name (implements the ArrayAccess interface). 
    215    * 
    216    * @param  string      The offset of the value to get 
    217    * 
    218    * @return sfFormField A form field instance 
    219    */ 
    220   public function offsetGet($name) 
    221   { 
    222     if (!isset($this->fields[$name])) 
    223     { 
    224       if (!$this->widget instanceof sfWidgetFormSchema) 
    225       { 
    226         throw new LogicException(sprintf('Cannot get a form field on a non widget schema (%s given).', get_class($this->widget))); 
    227       } 
    228  
    229       if (is_null($widget = $this->widget[$name])) 
    230       { 
    231         throw new InvalidArgumentException(sprintf('Widget "%s" does not exist.', $name)); 
    232       } 
    233  
    234       $this->fields[$name] = new sfFormField($widget, $this, $name, isset($this->value[$name]) ? $this->value[$name] : null, isset($this->error[$name]) ? $this->error[$name] : null); 
    235     } 
    236  
    237     return $this->fields[$name]; 
    238   } 
    239  
    240   /** 
    241    * Throws an exception saying that values cannot be set (implements the ArrayAccess interface). 
    242    * 
    243    * @param string (ignored) 
    244    * @param string (ignored) 
    245    * 
    246    * @throws <b>LogicException</b> 
    247    */ 
    248   public function offsetSet($offset, $value) 
    249   { 
    250     throw new LogicException('Cannot update form fields (read-only).'); 
    251   } 
    252  
    253   /** 
    254    * Throws an exception saying that values cannot be unset (implements the ArrayAccess interface). 
    255    * 
    256    * @param string (ignored) 
    257    * 
    258    * @throws LogicException 
    259    */ 
    260   public function offsetUnset($offset) 
    261   { 
    262     throw new LogicException('Cannot remove form fields (read-only).'); 
    263   } 
    264201} 
  • branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/data/generator/sfPropelForm/default/template/sfPropelFormGeneratedTemplate.php

    r6971 r7059  
    6565    if (!isset($this-><?php echo $name ?>Choices)) 
    6666    { 
    67       $this-><?php echo $name ?>Choices = array(<?php !$info[2] and print "'' => ''" ?>); 
     67      $this-><?php echo $name ?>Choices = array(<?php !$info[2] && !$info[3] and print "'' => ''" ?>); 
    6868      foreach (<?php echo $info[0] ?>Peer::doSelect(new Criteria(), $this->getConnection()) as $object) 
    6969      { 
  • branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/lib/propel/builder/SfMapBuilderBuilder.php

    r6707 r7059  
    2424    if (!DataModelBuilder::getBuildProperty('builderAddComments')) 
    2525    { 
    26       $code = sfToolkit::stripComments($map); 
     26      $code = sfToolkit::stripComments($code); 
    2727    } 
    2828 
  • branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/lib/propel/generator/sfPropelFormGenerator.class.php

    r6971 r7059  
    137137   * This method does not returns foreign keys that are also primary keys. 
    138138   * 
    139    * @return array An array composed of: an array of foreign key PHP names, A Boolean to indicate whether the column is required or not 
     139   * @return array An array composed of:  
     140   *                 * The foreign table PHP name 
     141   *                 * The foreign key PHP name 
     142   *                 * A Boolean to indicate whether the column is required or not 
     143   *                 * A Boolean to indicate whether the column is a many to many relationship or not 
    140144   */ 
    141145  public function getForeignKeyNames() 
     
    146150      if (!$column->isPrimaryKey() && $column->isForeignKey()) 
    147151      { 
    148         $names[] = array($this->getForeignTable($column)->getPhpName(), $column->getPhpName(), $column->isNotNull()); 
     152        $names[] = array($this->getForeignTable($column)->getPhpName(), $column->getPhpName(), $column->isNotNull(), false); 
    149153      } 
    150154    } 
     
    152156    foreach ($this->getManyToManyTables() as $tables) 
    153157    { 
    154       $names[] = array($tables['relatedTable']->getPhpName(), $tables['middleTable']->getPhpName(), false); 
     158      $names[] = array($tables['relatedTable']->getPhpName(), $tables['middleTable']->getPhpName(), false, true); 
    155159    } 
    156160 
  • branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/lib/vendor/propel-generator/classes/propel/engine/builder/om/php5/PHP5ObjectBuilder.php

    r7042 r7059  
    22 
    33/* 
    4  *  $Id: PHP5ObjectBuilder.php 920 2008-01-13 22:26:02Z hans
     4 *  $Id: PHP5ObjectBuilder.php 924 2008-01-14 20:44:36Z ron
    55 * 
    66 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
  • branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/lib/vendor/propel-generator/classes/propel/phing/PropelDataDumpTask.php

    r7042 r7059  
     1<?php 
     2 
     3/* 
     4 *  $Id: PropelDataDumpTask.php 612 2007-03-27 09:39:00Z heltem $ 
     5 * 
     6 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
     7 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
     8 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
     9 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
     10 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
     11 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
     12 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
     13 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
     14 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
     15 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
     16 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
     17 * 
     18 * This software consists of voluntary contributions made by many individuals 
     19 * and is licensed under the LGPL. For more information please see 
     20 * <http://propel.phpdb.org>. 
     21 */ 
     22 
     23/** 
     24 * Dumps the contenst of selected databases to XML data dump file. 
     25 * 
     26 * The generated XML files can have corresponding DTD files generated using the 
     27 * PropelDataDTDTask.  The results of the data dump can be converted to SQL using 
     28 * the PropelDataSQLTask class. 
     29 * 
     30 * The database may be specified (via 'databaseName' attribute) if you only want to dump 
     31 * the contents of one database.  Otherwise it is assumed that all databases described 
     32 * by datamodel schema file(s) will be dumped. 
     33 * 
     34 * @author     Hans Lellelid <hans@xmpl.org> (Propel) 
     35 * @author     Fedor Karpelevitch <fedor.karpelevitch@home.com> (Torque) 
     36 * @author     Jason van Zyl <jvanzyl@zenplex.com> (Torque) 
     37 * @author     Daniel Rall <dlr@finemaltcoding.com> (Torque) 
     38 * @version    $Revision: 612 $ 
     39 * @package    propel.phing 
     40 */ 
     41class PropelDataDumpTask extends AbstractPropelDataModelTask { 
     42 
     43  /** 
     44   * Database name. 
     45   * The database name may be optionally specified in the XML if you only want 
     46   * to dump the contents of one database. 
     47   */ 
     48  private $databaseName; 
     49 
     50  /** 
     51   * Database URL used for Creole connection. 
     52   * This is a PEAR-compatible (loosely) DSN URL. 
     53   */ 
     54  private $databaseUrl; 
     55 
     56  /** 
     57   * Database driver used for Creole connection. 
     58   * This should normally be left blank so that default (Creole built-in) driver for database type is used. 
     59   */ 
     60  private $databaseDriver; 
     61 
     62  /** 
     63   * Database user used for Creole connection. 
     64   * @deprecated Put username in databaseUrl. 
     65   */ 
     66  private $databaseUser; 
     67 
     68  /** 
     69   * Database password used for Creole connection. 
     70   * @deprecated Put password in databaseUrl. 
     71   */ 
     72  private $databasePassword; 
     73 
     74  /** 
     75   * Properties file that maps a data XML file to a particular database. 
     76   * @var        PhingFile 
     77   */ 
     78  private $datadbmap; 
     79 
     80  /** 
     81   * The database connection used to retrieve the data to dump. 
     82   * Needs to be public so that the TableInfo class can access it. 
     83   */ 
     84  public $conn; 
     85 
     86  /** 
     87   * The statement used to acquire the data to dump. 
     88   */ 
     89  private $stmt; 
     90 
     91  /** 
     92   * Set the file that maps between data XML files and databases. 
     93   * 
     94   * @param      PhingFile $sqldbmap the db map 
     95   * @return     void 
     96   */ 
     97  public function setDataDbMap(PhingFile $datadbmap) 
     98  { 
     99    $this->datadbmap = $datadbmap; 
     100  } 
     101 
     102  /** 
     103   * Get the file that maps between data XML files and databases. 
     104   * 
     105   * @return     PhingFile $datadbmap. 
     106   */ 
     107  public function getDataDbMap() 
     108  { 
     109    return $this->datadbmap; 
     110  } 
     111 
     112  /** 
     113   * Get the database name to dump 
     114   * 
     115   * @return     The DatabaseName value 
     116   */ 
     117  public function getDatabaseName() 
     118  { 
     119    return $this->databaseName; 
     120  } 
     121 
     122  /** 
     123   * Set the database name 
     124   * 
     125   * @param      v The new DatabaseName value 
     126   */ 
     127  public function setDatabaseName($v) 
     128  { 
     129    $this->databaseName = $v; 
     130  } 
     131 
     132  /** 
     133   * Get the database url 
     134   * 
     135   * @return     The DatabaseUrl value 
     136   */ 
     137  public function getDatabaseUrl() 
     138  { 
     139    return $this->databaseUrl; 
     140  } 
     141 
     142  /** 
     143   * Set the database url 
     144   * 
     145   * @param      string $v The PEAR-compatible database DSN URL. 
     146   */ 
     147  public function setDatabaseUrl($v) 
     148  { 
     149    $this->databaseUrl = $v; 
     150  } 
     151 
     152  /** 
     153   * Get the database user 
     154   * 
     155   * @return     string database user 
     156   * @deprecated 
     157   */ 
     158  public function getDatabaseUser() 
     159  { 
     160    return $this->databaseUser; 
     161  } 
     162 
     163  /** 
     164   * Set the database user 
     165   * 
     166   * @param      string $v The new DatabaseUser value 
     167   * @deprecated Specify user in DSN URL. 
     168   */ 
     169  public function setDatabaseUser($v) 
     170  { 
     171    $this->databaseUser = $v; 
     172  } 
     173 
     174  /** 
     175   * Get the database password 
     176   * 
     177   * @return     string database password 
     178   */ 
     179  public function getDatabasePassword() 
     180  { 
     181    return $this->databasePassword; 
     182  } 
     183 
     184  /** 
     185   * Set the database password 
     186   * 
     187   * @param      string $v The new DatabasePassword value 
     188   * @deprecated Specify database password in DSN URL. 
     189   */ 
     190  public function setDatabasePassword($v) 
     191  { 
     192    $this->databasePassword = $v; 
     193  } 
     194 
     195  /** 
     196   * Get the database driver name 
     197   * 
     198   * @return     string database driver name 
     199   */ 
     200  public function getDatabaseDriver() 
     201  { 
     202    return $this->databaseDriver; 
     203  } 
     204 
     205  /** 
     206   * Set the database driver name 
     207   * 
     208   * @param      string $v The new DatabaseDriver value 
     209   */ 
     210  public function setDatabaseDriver($v) 
     211  { 
     212    $this->databaseDriver = $v; 
     213  } 
     214 
     215  /** 
     216   * Create the data XML -> database map. 
     217   * 
     218   * This is necessary because there is currently no other method of knowing which 
     219   * data XML files correspond to which database.  This map allows us to convert multiple 
     220   * data XML files into SQL. 
     221   * 
     222   * @throws     IOException - if unable to store properties 
     223   */ 
     224  private function createDataDbMap() 
     225  { 
     226    if ($this->getDataDbMap() === null) { 
     227      return; 
     228    } 
     229 
     230    // Produce the sql -> database map 
     231    $datadbmap = new Properties(); 
     232 
     233    // Check to see if the sqldbmap has already been created. 
     234    if ($this->getDataDbMap()->exists()) { 
     235      $datadbmap->load($this->getDataDbMap()); 
     236    } 
     237 
     238    foreach ($this->getDataModels() as $dataModel) {            // there is really one 1 db per datamodel 
     239      foreach ($dataModel->getDatabases() as $database) { 
     240 
     241        // if database name is specified, then we only want to dump that one db. 
     242        if (empty($this->databaseName) || ($this->databaseName && $database->getName() == $this->databaseName)) { 
     243          $outFile = $this->getMappedFile($dataModel->getName()); 
     244          $datadbmap->setProperty($outFile->getName(), $database->getName()); 
     245        } 
     246      } 
     247    } 
     248 
     249    try { 
     250      $datadbmap->store($this->getDataDbMap(), "Data XML file -> Database map"); 
     251    } catch (IOException $e) { 
     252      throw new IOException("Unable to store properties: ". $e->getMessage()); 
     253    } 
     254  } 
     255 
     256  /** 
     257   * Iterates through each datamodel/database, dumps the contents of all tables and creates a DOM XML doc. 
     258   * 
     259   * @return     void 
     260   * @throws     BuildException 
     261   */ 
     262  public function main() 
     263  { 
     264    $this->validate(); 
     265 
     266    $buf = "Database settings:\n" 
     267      . " driver: " . ($this->databaseDriver ? $this->databaseDriver : "(default)" ). "\n" 
     268      . " URL: " . $this->databaseUrl . "\n" 
     269      . ($this->databaseUser ? " user: " . $this->databaseUser . "\n" : "") 
     270      . ($this->databasePassword ? " password: " . $this->databasePassword . "\n" : ""); 
     271 
     272    $this->log($buf, PROJECT_MSG_VERBOSE); 
     273 
     274    // 1) First create the Data XML -> database name map. 
     275    $this->createDataDbMap(); 
     276 
     277    // 2) Now go create the XML files from teh database(s) 
     278    foreach ($this->getDataModels() as $dataModel) {            // there is really one 1 db per datamodel 
     279      foreach ($dataModel->getDatabases() as $database) { 
     280 
     281        // if database name is specified, then we only want to dump that one db. 
     282        if (empty($this->databaseName) || ($this->databaseName && $database->getName() == $this->databaseName)) { 
     283 
     284          $outFile = $this->getMappedFile($dataModel->getName()); 
     285 
     286          $this->log("Dumping data to XML for database: " . $database->getName()); 
     287          $this->log("Writing to XML file: " . $outFile->getName()); 
     288 
     289          try { 
     290 
     291            $url = str_replace("@DB@", $database->getName(), $this->databaseUrl); 
     292 
     293            if ($url !== $this->databaseUrl) { 
     294              $this->log("New (resolved) URL: " . $url, PROJECT_MSG_VERBOSE); 
     295            } 
     296 
     297            if (empty($url)) { 
     298              throw new BuildException("Unable to connect to database; no PDO connection URL specified.", $this->getLocation()); 
     299            } 
     300 
     301            $this->conn = new PDO($url, $this->databaseUser, $this->databasePassword); 
     302            $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
     303 
     304            $doc = $this->createXMLDoc($database); 
     305            $doc->save($outFile->getAbsolutePath()); 
     306 
     307          } catch (SQLException $se) { 
     308            $this->log("SQLException while connecting to DB: ". $se->getMessage(), PROJECT_MSG_ERR); 
     309            throw new BuildException($se); 
     310          } 
     311        } // if databaseName && database->getName == databaseName 
     312      } // foreach database 
     313    } // foreach datamodel 
     314  } 
     315 
     316  /** 
     317   * Gets ResultSet of query to fetch all data from a table. 
     318   * @param      string $tableName 
     319   * @return     ResultSet 
     320   */ 
     321  private function getTableDataStmt($tableName) { 
     322    // Set Statement object in associated PropelDataDump 
     323    // instance. 
     324    $stmt = $this->conn->prepare("SELECT * FROM " . $this->getPlatformForTargetDatabase()->quoteIdentifier ( $tableName ) ); 
     325    $stmt->execute(); 
     326    return $stmt; 
     327  } 
     328 
     329  /** 
     330   * Creates a DOM document containing data for specified database. 
     331   * @param      Database $database 
     332   * @return     DOMDocument 
     333   */ 
     334  private function createXMLDoc(Database $database) { 
     335 
     336    $doc = new DOMDocument('1.0', 'utf-8'); 
     337    $doc->formatOutput = true; // pretty printing 
     338    $doc->appendChild($doc->createComment("Created by data/dump/Control.tpl template.")); 
     339 
     340    $dsNode = $doc->createElement("dataset"); 
     341    $dsNode->setAttribute("name", "all"); 
     342    $doc->appendChild($dsNode); 
     343 
     344    $this->log("Building DOM tree containing data from tables:"); 
     345 
     346    foreach ($database->getTables() as $tbl) { 
     347      $this->log("\t+ " . $tbl->getName()); 
     348      $stmt = $this->getTableDataStmt($tbl->getName()); 
     349      while ($row = $stmt->fetch()) { 
     350        $rowNode = $doc->createElement($tbl->getPhpName()); 
     351        foreach ($tbl->getColumns() as $col) { 
     352          $cval = $row[$col->getName()]; 
     353          if ($cval !== null) { 
     354            $rowNode->setAttribute($col->getPhpName(), iconv($this->dbEncoding, 'utf-8', $cval)); 
     355          } 
     356        } 
     357        $dsNode->appendChild($rowNode); 
     358        unset($rowNode); 
     359      } 
     360      unset($stmt); 
     361    } 
     362 
     363    return $doc; 
     364  } 
     365} 
  • branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/lib/vendor/propel-generator/projects/bookstore/schema.xml

    r7042 r7059  
    55    <column name="id" required="true" primaryKey="true" 
    66      autoIncrement="true" type="INTEGER" description="Book Id" /> 
    7     <column name="title" type="VARCHAR" required="true" size="255" 
     7    <column name="title" type="VARCHAR" required="true" 
    88      description="Book Title" /> 
    99    <column name="isbn" required="true" type="VARCHAR" size="24" 
  • branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/lib/vendor/propel-generator/resources/xsl/database.xsl

    r5729 r7059  
    259259        <xsl:attribute name='lazyLoad'>false</xsl:attribute> 
    260260      </xsl:if> 
     261      <xsl:if test='@type = "VARCHAR" and not(boolean(@size) )'> 
     262        <xsl:attribute name='size'>255</xsl:attribute> 
     263      </xsl:if> 
    261264      <xsl:apply-templates select='@*'/> 
    262265      <xsl:apply-templates select='inheritance'/> 
  • branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/lib/vendor/propel/adapter/DBAdapter.php

    r6879 r7059  
    11<?php 
    22/* 
    3  *  $Id: DBAdapter.php 900 2008-01-02 01:33:26Z hans
     3 *  $Id: DBAdapter.php 922 2008-01-14 20:29:24Z ron
    44 * 
    55 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
     
    3939 * @author     Brett McLaughlin <bmclaugh@algx.net> (Torque) 
    4040 * @author     Daniel Rall <dlr@finemaltcoding.com> (Torque) 
    41  * @version    $Revision: 900
     41 * @version    $Revision: 922
    4242 * @package    propel.adapter 
    4343 */ 
     
    205205 
    206206  /** 
     207   * Quotes a database table which could have space seperating it from an alias, both should be identified seperately 
     208   * @param      string $table The table name to quo 
     209   * @return     string The quoted table name 
     210   **/ 
     211  public function quoteIdentifierTable($table) { 
     212    return implode(" ", array_map(array($this, "quoteIdentifier"), explode(" ", $table) ) ); 
     213  } 
     214 
     215  /** 
    207216   * Returns the native ID method for this RDBMS. 
    208217   * @return     int one of DBAdapter:ID_METHOD_SEQUENCE, DBAdapter::ID_METHOD_AUTOINCREMENT. 
  • branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/lib/vendor/propel/util/BasePeer.php

    r7042 r7059  
    11<?php 
    22/* 
    3  *  $Id: BasePeer.php 919 2008-01-13 21:12:24Z hans
     3 *  $Id: BasePeer.php 922 2008-01-14 20:29:24Z ron
    44 * 
    55 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
     
    3636 * @author     Brett McLaughlin <bmclaugh@algx.net> (Torque) 
    3737 * @author     Stephen Haberman <stephenh@chase3000.com> (Torque) 
    38  * @version    $Revision: 919
     38 * @version    $Revision: 922
    3939 * @package    propel.util 
    4040 */ 
     
    847847    // from / join tables quoten if it is necessary 
    848848    if ($db->useQuoteIdentifier()) { 
    849       $fromClause = array_map(array($db, 'quoteIdentifier'), $fromClause); 
    850       $joinClause = $joinClause ? $joinClause : array_map(array($db, 'quoteIdentifier'), $joinClause); 
     849      $fromClause = array_map(array($db, 'quoteIdentifierTable'), $fromClause); 
     850      $joinClause = $joinClause ? $joinClause : array_map(array($db, 'quoteIdentifierTable'), $joinClause); 
    851851    } 
    852852 
  • branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/data/sql/lib.model.schema.sql

    r5125 r7059  
    1010( 
    1111  [id] INTEGER  NOT NULL PRIMARY KEY, 
    12   [title] VARCHAR(255)
     12  [title] VARCHAR(255)  NOT NULL
    1313  [body] MEDIUMTEXT, 
    1414  [online] INTEGER, 
  • branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/base/BaseArticleForm.class.php