sfPropel13Plugin

ざっと試した感じ以下の3点が気になったので、とりあえず動くようにしてみました。

  • databases.ymlのencoding指定が無視される。
  • デバッグツールバーSQLが表示されない。
  • Propel1.3で正式対応しているReplication設定ができない。
<?php

class myPropel13Database extends sfPropel13Database
{
    public function initialize($parameters = null, $name = 'propel')
    {
        parent::initialize($parameters, $name);
        
        if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) {
            Propel::setLogger(myPropel13LogWrapper::getInstance());
        }
    }
    
    public function addConfig()
    {
        parent::addConfig();
        
        $conparams = self::$config['propel']['datasources'][$this->getParameter('datasource')]['connection'];
        
        if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) {
            $conparams['classname'] = 'DebugPDO';
        }
        
        if (isset($conparams['encoding'])) {
            $conparams['settings']['charset']['value'] = $conparams['encoding'];
        }
        
        self::$config['propel']['datasources'][$this->getParameter('datasource')]['connection'] = $conparams;
        
        if ($slaves = $this->getParameter('slaves')) {
            if (isset($slaves['dsn'])) {
                $slaves = $this->mergeParams($conparams, $slaves);
            } else {
                foreach ($slaves as &$slave) {
                    $slave = $this->mergeParams($conparams, $slave);
                }
            }
            self::$config['propel']['datasources'][$this->getParameter('datasource')]['slaves']['connection'] = $slaves;
        }
    }
    
    protected function mergeParams($master_params, $slave_params)
    {
        $params = array_merge($master_params, $slave_params);
        if (isset($params['username'])) {
            $params['user'] = $params['username'];
            unset($params['username']);
        }
        return $params;
    }
}
<?php

class myPropel13LogWrapper extends sfPropel13LogWrapper
{
    public static function getInstance()
    {
        if (!sfPropel13LogWrapper::$instance) {
            $class = __CLASS__;
            sfPropel13LogWrapper::$instance = new $class();
        }
        
        return sfPropel13LogWrapper::$instance;
    }
    
    public function log($message, $priority = SF_LOG_INFO)
    {
        foreach (array('prepare', 'exec', 'query') as $type) {
            if (strpos($message, $type) === 0) {
                $this->logger()->log('{Propel} executeQuery : ' . $message, $priority);
                return;
            }
        }
        
        parent::log($message, $priority);
    }
}
all:
  propel:
    class:          myPropel13Database
    param:
      dsn:          mysql:dbname=propel-13-test;host=localhost
      username:     master
      password:     master
      encoding:     utf8
      instance-pooling: true
      
      slaves:
        -
          dsn:          mysql:dbname=propel-13-test;host=slave
          username:     slave
          password:     slave