Executing SQL after loading your data fixtures in symfony 1.4 post

Posted on 2010-07-26 by jwage


Sometimes you may need to execute some SQL after your data fixtures are loaded in symfony 1.4 if you need to do something that is specific to your RDBMS that is not supported by Doctrine or Propel. Thankfully symfony 1.4 has many well placed events which allow you to hook in to core functionality and execute your own code when certain actions are performed.

Here is an example where you execute some manually SQL statements after the doctrine:data-load task:

class ProjectConfiguration extends sfProjectConfiguration
{
  public function setup()
  {
    // ...
    $this->dispatcher->connect('command.post_command', array(
      $this, 'listenToCommandPostCommandEvent'
    ));
  }

  public function listenToCommandPostCommandEvent(sfEvent $event)
  {
    $invoker = $event->getSubject();
    if ($invoker instanceof sfDoctrineDataLoadTask)
    {
      $conn = Doctrine_Manager::connection();
      $conn->exec(// ...);
    }
  }
}

Symfony 1.4 has many events that you can use to customize things when developing your project. Read more about events in the 1.4 documentation.