Changeset 7059
- Timestamp:
- 01/15/08 01:28:46 (10 months ago)
- Files:
-
- branches/dwhittle/1.1/lib/form/sfForm.class.php (modified) (8 diffs)
- branches/dwhittle/1.1/lib/form/sfFormField.class.php (modified) (8 diffs)
- branches/dwhittle/1.1/lib/form/sfFormFieldSchema.class.php (copied) (copied from branches/1.1/lib/form/sfFormFieldSchema.class.php)
- branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/data/generator/sfPropelForm/default/template/sfPropelFormGeneratedTemplate.php (modified) (1 diff)
- branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/lib/propel/builder/SfMapBuilderBuilder.php (modified) (1 diff)
- branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/lib/propel/generator/sfPropelFormGenerator.class.php (modified) (3 diffs)
- branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/lib/vendor/propel-generator/classes/propel/engine/builder/om/php5/PHP5ObjectBuilder.php (modified) (1 diff)
- branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/lib/vendor/propel-generator/classes/propel/phing/PropelDataDumpTask.php (modified) (1 diff)
- branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/lib/vendor/propel-generator/projects/bookstore/schema.xml (modified) (1 diff)
- branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/lib/vendor/propel-generator/resources/xsl/database.xsl (modified) (1 diff)
- branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/lib/vendor/propel/adapter/DBAdapter.php (modified) (3 diffs)
- branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/lib/vendor/propel/util/BasePeer.php (modified) (3 diffs)
- branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/config/schema-transformed.xml (added)
- branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/data/sql/lib.model.schema.sql (modified) (1 diff)
- branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/base/BaseArticleForm.class.php (modified) (2 diffs)
- branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/base/BaseAuthorArticleForm.class.php (modified) (2 diffs)
- branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/base/BaseAuthorForm.class.php (modified) (1 diff)
- branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/base/BaseBookForm.class.php (modified) (1 diff)
- branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/base/BaseCategoryForm.class.php (modified) (1 diff)
- branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/model/map/ArticleMapBuilder.php (modified) (1 diff)
- branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/model/om/BaseArticle.php (modified) (64 diffs)
- branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/model/om/BaseArticlePeer.php (modified) (55 diffs)
- branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/model/om/BaseAuthor.php (modified) (38 diffs)
- branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/model/om/BaseAuthorArticle.php (modified) (38 diffs)
- branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/model/om/BaseAuthorArticlePeer.php (modified) (55 diffs)
- branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/model/om/BaseAuthorPeer.php (modified) (31 diffs)
- branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/model/om/BaseBook.php (modified) (38 diffs)
- branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/model/om/BaseBookPeer.php (modified) (31 diffs)
- branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/model/om/BaseCategory.php (modified) (38 diffs)
- branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/model/om/BaseCategoryPeer.php (modified) (31 diffs)
- branches/dwhittle/1.1/lib/validator/sfValidatorErrorSchema.class.php (modified) (1 diff)
- branches/dwhittle/1.1/lib/validator/sfValidatorSchema.class.php (modified) (4 diffs)
- branches/dwhittle/1.1/lib/validator/sfValidatorSchemaForEach.class.php (modified) (1 diff)
- branches/dwhittle/1.1/lib/widget/sfWidgetFormSchema.class.php (modified) (7 diffs)
- branches/dwhittle/1.1/lib/widget/sfWidgetFormSchemaDecorator.class.php (modified) (5 diffs)
- branches/dwhittle/1.1/lib/widget/sfWidgetFormSchemaForEach.class.php (modified) (3 diffs)
- branches/dwhittle/1.1/test/functional/cacheTest.php (modified) (5 diffs)
- branches/dwhittle/1.1/test/functional/dimensionsTest.php (modified) (1 diff)
- branches/dwhittle/1.1/test/functional/fixtures/project/apps/dimensions/config/factories.yml (modified) (2 diffs)
- branches/dwhittle/1.1/test/unit/form/sfFormFieldSchemaTest.php (copied) (copied from branches/1.1/test/unit/form/sfFormFieldSchemaTest.php)
- branches/dwhittle/1.1/test/unit/form/sfFormFieldTest.php (modified) (7 diffs)
- branches/dwhittle/1.1/test/unit/form/sfFormTest.php (modified) (8 diffs)
- branches/dwhittle/1.1/test/unit/validator/sfValidatorErrorSchemaTest.php (modified) (2 diffs)
- branches/dwhittle/1.1/test/unit/validator/sfValidatorSchemaTest.php (modified) (9 diffs)
- branches/dwhittle/1.1/test/unit/widget/sfWidgetFormSchemaDecoratorTest.php (modified) (4 diffs)
- branches/dwhittle/1.1/test/unit/widget/sfWidgetFormSchemaForEachTest.php (modified) (2 diffs)
- branches/dwhittle/1.1/test/unit/widget/sfWidgetFormSchemaTest.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/dwhittle/1.1/lib/form/sfForm.class.php
r6992 r7059 208 208 * @param string The field name 209 209 * @param sfForm A sfForm instance 210 * @param string The format to use for widget name211 210 * @param string A HTML decorator for the embedded form 212 211 */ 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 { 221 214 $form = clone $form; 222 215 unset($form[self::$CSRFFieldName]); 223 216 224 217 $widgetSchema = $form->getWidgetSchema(); 225 $widgetSchema->setNameFormat($nameFormat);226 218 227 219 $this->setDefault($name, $form->getDefaults()); … … 240 232 * @param string The field name 241 233 * @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 244 235 * @param string A HTML decorator for the main form around embedded forms 245 236 * @param string A HTML decorator for each embedded form 246 237 */ 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 { 255 240 $form = clone $form; 256 241 unset($form[self::$CSRFFieldName]); 242 243 $widgetSchema = $form->getWidgetSchema(); 257 244 258 245 // generate labels and default values … … 262 249 if (!isset($labels[$i])) 263 250 { 264 $labels[$i] = sprintf('%s (%s)', $ form->getWidgetSchema()->generateLabelName($name), $i);251 $labels[$i] = sprintf('%s (%s)', $widgetSchema->generateLabelName($name), $i); 265 252 } 266 253 … … 270 257 $this->setDefault($name, $defaults); 271 258 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); 276 263 $this->validatorSchema[$name] = new sfValidatorSchemaForEach($form->getValidatorSchema(), $n); 277 264 … … 573 560 $values = $this->isBound ? $this->taintedValues : $this->defaults; 574 561 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]); 576 565 } 577 566 … … 609 598 * Returns a form field for the main widget schema. 610 599 * 611 * @return sfFormField A sfFormFieldinstance600 * @return sfFormFieldSchema A sfFormFieldSchema instance 612 601 */ 613 602 protected function getFormField() … … 615 604 if (is_null($this->formField)) 616 605 { 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); 618 607 } 619 608 620 609 return $this->formField; 621 }622 623 /**624 * Generates a name format for embedded forms.625 *626 * @param string The widget name627 * @param string The current name format628 *629 * @return string The name format to use for embedding630 *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 else643 {644 return sprintf('%s[%%s]', $name);645 }646 610 } 647 611 … … 733 697 return $str; 734 698 } 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 } 735 708 } branches/dwhittle/1.1/lib/form/sfFormField.class.php
r6198 r7059 17 17 * @version SVN: $Id$ 18 18 */ 19 class sfFormField implements ArrayAccess19 class sfFormField 20 20 { 21 21 protected … … 24 24 $name = '', 25 25 $value = null, 26 $error = null, 27 $fields = array(); 26 $error = null; 28 27 29 28 /** 30 29 * Constructor. 31 30 * 32 * @param sfWidget A sfWidget instance31 * @param sfWidgetForm A sfWidget instance 33 32 * @param sfFormField The sfFormField parent instance (null for the root widget) 34 33 * @param string The field name … … 36 35 * @param sfValidatorError A sfValidatorError instance 37 36 */ 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) 39 38 { 40 39 $this->widget = $widget; … … 80 79 public function renderRow($help = '') 81 80 { 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)); 85 84 } 86 85 87 86 $field = $this->parent->getWidget()->renderField($this->name, $this->value, $this->error); 88 87 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%' => '')); 90 91 } 91 92 … … 95 96 * The formatted list will use the parent widget schema formatter. 96 97 * 97 * @param string The widget name98 *99 98 * @return string The formatted error list 100 99 */ 101 100 public function renderError() 102 101 { 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); 109 110 } 110 111 … … 116 117 public function renderLabel() 117 118 { 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)); 121 122 } 122 123 … … 131 132 public function renderLabelName() 132 133 { 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)); 136 137 } 137 138 … … 198 199 return !is_null($this->error) && count($this->error); 199 200 } 200 201 /**202 * Returns true if the bound field exists (implements the ArrayAccess interface).203 *204 * @param string The name of the bound field205 *206 * @return Boolean true if the widget exists, false otherwise207 */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 get217 *218 * @return sfFormField A form field instance219 */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 LogicException259 */260 public function offsetUnset($offset)261 {262 throw new LogicException('Cannot remove form fields (read-only).');263 }264 201 } branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/data/generator/sfPropelForm/default/template/sfPropelFormGeneratedTemplate.php
r6971 r7059 65 65 if (!isset($this-><?php echo $name ?>Choices)) 66 66 { 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 "'' => ''" ?>); 68 68 foreach (<?php echo $info[0] ?>Peer::doSelect(new Criteria(), $this->getConnection()) as $object) 69 69 { branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/lib/propel/builder/SfMapBuilderBuilder.php
r6707 r7059 24 24 if (!DataModelBuilder::getBuildProperty('builderAddComments')) 25 25 { 26 $code = sfToolkit::stripComments($ map);26 $code = sfToolkit::stripComments($code); 27 27 } 28 28 branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/lib/propel/generator/sfPropelFormGenerator.class.php
r6971 r7059 137 137 * This method does not returns foreign keys that are also primary keys. 138 138 * 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 140 144 */ 141 145 public function getForeignKeyNames() … … 146 150 if (!$column->isPrimaryKey() && $column->isForeignKey()) 147 151 { 148 $names[] = array($this->getForeignTable($column)->getPhpName(), $column->getPhpName(), $column->isNotNull() );152 $names[] = array($this->getForeignTable($column)->getPhpName(), $column->getPhpName(), $column->isNotNull(), false); 149 153 } 150 154 } … … 152 156 foreach ($this->getManyToManyTables() as $tables) 153 157 { 154 $names[] = array($tables['relatedTable']->getPhpName(), $tables['middleTable']->getPhpName(), false );158 $names[] = array($tables['relatedTable']->getPhpName(), $tables['middleTable']->getPhpName(), false, true); 155 159 } 156 160 branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/lib/vendor/propel-generator/classes/propel/engine/builder/om/php5/PHP5ObjectBuilder.php
r7042 r7059 2 2 3 3 /* 4 * $Id: PHP5ObjectBuilder.php 92 0 2008-01-13 22:26:02Z hans$4 * $Id: PHP5ObjectBuilder.php 924 2008-01-14 20:44:36Z ron $ 5 5 * 6 6 * 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 */ 41 class 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 5 5 <column name="id" required="true" primaryKey="true" 6 6 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" 8 8 description="Book Title" /> 9 9 <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 259 259 <xsl:attribute name='lazyLoad'>false</xsl:attribute> 260 260 </xsl:if> 261 <xsl:if test='@type = "VARCHAR" and not(boolean(@size) )'> 262 <xsl:attribute name='size'>255</xsl:attribute> 263 </xsl:if> 261 264 <xsl:apply-templates select='@*'/> 262 265 <xsl:apply-templates select='inheritance'/> branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/lib/vendor/propel/adapter/DBAdapter.php
r6879 r7059 1 1 <?php 2 2 /* 3 * $Id: DBAdapter.php 9 00 2008-01-02 01:33:26Z hans$3 * $Id: DBAdapter.php 922 2008-01-14 20:29:24Z ron $ 4 4 * 5 5 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS … … 39 39 * @author Brett McLaughlin <bmclaugh@algx.net> (Torque) 40 40 * @author Daniel Rall <dlr@finemaltcoding.com> (Torque) 41 * @version $Revision: 9 00$41 * @version $Revision: 922 $ 42 42 * @package propel.adapter 43 43 */ … … 205 205 206 206 /** 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 /** 207 216 * Returns the native ID method for this RDBMS. 208 217 * @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 1 1 <?php 2 2 /* 3 * $Id: BasePeer.php 9 19 2008-01-13 21:12:24Z hans$3 * $Id: BasePeer.php 922 2008-01-14 20:29:24Z ron $ 4 4 * 5 5 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS … … 36 36 * @author Brett McLaughlin <bmclaugh@algx.net> (Torque) 37 37 * @author Stephen Haberman <stephenh@chase3000.com> (Torque) 38 * @version $Revision: 9 19$38 * @version $Revision: 922 $ 39 39 * @package propel.util 40 40 */ … … 847 847 // from / join tables quoten if it is necessary 848 848 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); 851 851 } 852 852 branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/data/sql/lib.model.schema.sql
r5125 r7059 10 10 ( 11 11 [id] INTEGER NOT NULL PRIMARY KEY, 12 [title] VARCHAR(255) ,12 [title] VARCHAR(255) NOT NULL, 13 13 [body] MEDIUMTEXT, 14 14 [online] INTEGER, branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/base/BaseArticleForm.class.php