Symfony 1.4 / Doctrine 1.2 ProjectConfiguration PluginConfiguration Doctrine Event Listeners
References
- https://symfony.com/legacy/doc/gentle-introduction/1_4/en/17-Extending-Symfony
- http://doctrine1.readthedocs.io/en/latest/en/manual/event-listeners.html
- http://doctrine1.readthedocs.io/en/latest/en/manual/connections.html
- https://symfony.com/blog/a-week-of-symfony-145-5-11-october-2009
- https://stackoverflow.com/questions/4282482/set-mysql-session-variable-timezone-using-doctrine-1-2-and-zend-framework
Events
- doctrine.configure
- doctrine.configure_connection
Handled by Doctrine in sfDoctrineDatabase::initialize() e.g. L119
/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/database/sfDoctrineDatabase.class.php
Usage in ProjectConfiguration or PluginConfiguration
- config/ProjectConfiguration.class.php or e.g.
- plugins/ullCorePlugin/config/ullCorePluginConfiguration.class.php
class ullCorePluginConfiguration extends sfPluginConfiguration
{
public function setup()
{
$this->dispatcher->connect('doctrine.configure_connection',
array('ullCorePluginConfiguration', 'configureDoctrineConnection')
);
}
/**
* Configure doctrine connection globally for ullright/ullCorePlugin
* @param sfEvent $event
*/
public static function configureDoctrineConnection(sfEvent $event)
{
$connection = $event['connection'];
// Configure MySQL compatiblity mode for MySQL >= 5.7
$connection->addListener(new Doctrine_Event_Listener_Mysql_Mode());
}
}
plugins/ullCorePlugin/lib/Doctrine_Event_Listener_Mysql_Mode.class.php
class Doctrine_Event_Listener_Mysql_Mode extends Doctrine_EventListener
{
public function postConnect(Doctrine_Event $event)
{
$conn = $event->getInvoker();
//$conn->execute('SET SESSION sql_mode=""');
$conn->execute("SET SESSION sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''))");
}
}
The example above is the solution for Symfony 1.4 usage with MySQL > 5.7 and error "SQLSTATE[HY000]: General error: 3065 Expression #1 of ORDER BY clause is not in SELECT list, references column 'xxxxxxx' which is not in SELECT list; this is incompatible with DISTINCT

