Development

#2267 ([PATCH] sfPropelDatabase generate wrong configuration on multiple datasource (symfony 1.1).)

You must first sign up to be able to contribute.

Ticket #2267 (closed defect: fixed)

Opened 1 year ago

Last modified 1 year ago

[PATCH] sfPropelDatabase generate wrong configuration on multiple datasource (symfony 1.1).

Reported by: tohenk Assigned to: fabien
Priority: minor Milestone: 1.1.0
Component: model Version: 1.1.0 DEV
Keywords: Cc:
Qualification: Unreviewed

Description

sfPropelDatabase which inherit sfDatabase now have __construct() constructor that will call initialize with empty array.

Looking at generated config_databases.yml.php, first step is a new sfPropelDatabase created and second step, it's initialized.

On first step initialize called with empty parameters and connection named propel.

On second step initialize called with parameters and connection name based on configuration.

Typically, this won't fall if only one connection defined in configuration and named propel by default (second step call to initialize replace the first call).

But, with multiple datasource defined, on next datasource, when sfPropelDatabase created it may replace the existing datasource named propel which previously initialized.

Attachments

sfPropelDatabase.diff (0.6 kB) - added by tohenk on 09/20/07 08:29:45.

Change History

09/20/07 08:29:45 changed by tohenk

  • attachment sfPropelDatabase.diff added.

10/01/07 08:14:40 changed by dwhittle

  • qualification set to Unreviewed.

I dont understand, can you provide an example with snippet of code?

12/20/07 15:29:08 changed by francois

  • version changed from 1.0.0 to 1.1.0.
  • component changed from plugins to model.

12/26/07 23:12:25 changed by fabien

  • status changed from new to closed.
  • resolution set to fixed.

in r6729

12/28/07 12:43:45 changed by pookey

  • milestone set to 1.1.0.

this change has somehow broken something with sfDoctrinPlugin 1.1 - I've not had a chance to figure out what yet though...

although, sfDoctrineDatabase

sfDatabase -

 34   public function __construct($parameters = array())
 35   {
 36     $this->initialize($parameters);
 37   }

however... sfDoctrineDatabase does this:

 35   public function initialize($parameters = array(), $name = null)
 36   {
 37     if (!$parameters)
 38     {
 39       return;
 40     }
 41
 42     parent::initialize($parameters);
 43

also, it seems that sfPropelDatabase does similar...

 34   public function initialize($parameters = null, $name = 'propel')
 35   {
 36     parent::initialize($parameters);
 37
 38     if (!$this->hasParameter('datasource'))
 39     {
 40       $this->setParameter('datasource', $name);
 41     }

I'm not fully understanding these changes, so i'm rolling back for now....

12/29/07 04:52:36 changed by tohenk

Change in r6729 doesn't fix this. sfPropelDatabase which extend sfDatabase have a __construct() with only one argument. But in generated databases.yml config shown:

<?php
// auto-generated by sfDatabaseConfigHandler
// date: 2007/12/29 10:12:00

$database = new sfPropelDatabase(array (
  'phptype' => 'mysql',
  'hostspec' => 'localhost',
  'database' => 'simpeg_web',
  'username' => 'root',
  'password' => NULL,
), 'propel');
$this->databases['propel'] = $database;

$database = new sfPropelDatabase(array (
  'phptype' => 'mysql',
  'hostspec' => 'localhost',
  'database' => 'simpeg',
  'username' => 'root',
  'password' => NULL,
), 'master-local');
$this->databases['master-local'] = $database;

sfPropelDatabase constructor called with two argument, so the second argument will never passed to sfPropelDatabase.

The Workaround is to override sfPropelDatabase constructor like this:

class sfPropelDatabase extends sfCreoleDatabase
{
  static protected
    $config = array();

  /**
   * Class constructor.
   *
   * @see initialize()
   */
  public function __construct($parameters = array(), $name = 'propel')
  {
    $this->initialize($parameters, $name);
  }

  public function initialize($parameters = null, $name = 'propel')
  {
    parent::initialize($parameters);

    if (!$this->hasParameter('datasource'))
    {
      $this->setParameter('datasource', $name);
    }

I think this can also applied to sfDoctrineDatabase.

12/29/07 08:38:40 changed by fabien

in r6805