Home > Symfony 1.3 & 1.4 > Symfony 1.4 Doctrine Extension Blameable w sfGuard

Symfony 1.4 Doctrine Extension Blameable w sfGuard

Here’s how to set up the blameable extension for Doctrine 1.2 through Symfony.

1 – in your Symfony project folder, create a folder called “doctrine_extensions” under the lib folder: lib/doctrine_extensions

2 – Download the Blameable extension from Doctrine-project.org and copy it to the newly created doctrine_extensions folder. It should look like this:
lib/doctrine_extensions/Blameable

3 – update you’re yml file actAs section:

myTableClass:
  connection: doctrine
  tableName: myTableName
  actAs:
    Blameable:
      listener: BlameableSymfony
      columns:
        created:
          disabled: true
        updated:
          name: updated_by          

*NOTE: my db field is called updated_by and i’m not using the created option, so i’ve disabled it. I’ve also created a yml key value called listener. I point the listener to a class called BlameableSymfony, which overrides the doctrine getUserIdentity() to use the sfGuard user id.

4 – Override the Blameable getUserIdentity() method. To do this i create the file lib/doctrine_extensions/Blameable/lib/Doctrine/Template/Listener/BlameableSymfony.php and add this content:

<?php
/**
 * extending Doctrine_Template_Listener_Blameable to use symfony sf_guard_user id
 */
class BlameableSymfony extends Doctrine_Template_Listener_Blameable
{
    /**
     * 
     * @return int $ident sf_guard_user.id
     */
    public function getUserIdentity()
    {        
        $ident = sfContext::getInstance()->getUser()->getGuardUser()->getId();

        return $ident;            
    }
}

That’s it! Good Luck!

Categories: Symfony 1.3 & 1.4 Tags:
  1. jhon
    March 11th, 2010 at 03:10 | #1

    i tested this snippet but for some strange reason i get an error if i put doctrine extensions inside a directory other than /lib (e.g lib/doctrine_extensions). symfony doesn’t find files.

    suggestions? any help would be highly appreciated. thanks
    (sorry for my english… i’m ussing google :)

  2. lleung
    March 11th, 2010 at 08:08 | #2

    jhon,

    Doctrine is expecting the files in there. Unless you change the plugin source, you will not be able to change extension directory. Not hard, but you will need to change this each time there is an update.

  3. Sean
    March 11th, 2010 at 08:48 | #3

    Hey jhon,

    My current set up is as such:

    .../symfony
            apps/
            cache/
            config/
            data/
            lib/
                    doctrine_extentions/
                            Blamable/
                    filter/
                    form/
                    model/
                    vendor/
            log/
    ...
    

    If you’ve created the folder in the vendor/symfony/lib, that might be the problem.

  4. Florian
    May 11th, 2010 at 09:12 | #4

    Hi,

    Just a problem with sfContext and uts –fabulous– message:

    The “default” context does not exist.

    when coming from php CLI ( symfony console and doctrine:data-load ) for example.

    You should use something else to get the user id, (aka: Doctrine_Manager params )

    like this:

    public function getFiltrableId()
    {
    $id = Doctrine_Manager::getInstance()->getParam($this->_options['filtrable_column']['name'], ‘doctrine/behavior/filtrable’);

    if(is_null($id) && isset($this->_options['filtrable_column']['default'])) {
    $id = $this->_options['filtrable_column']['default'];
    }
    return $id;
    }

  5. May 12th, 2010 at 17:36 | #5

    I’m looking for the Blameable extension, but it looks like Jonathan has just rearranged the Doctrine project website, and the link to the Extensions is not working. Would it be possible for you to email the extension to me?

    Thanks,

    – brent

  6. Lloyd Leung
    May 13th, 2010 at 10:13 | #6

    I can’t find it either on the website… will advise once we find it.

  7. Tom
  8. May 22nd, 2010 at 11:23 | #8

    @Brent Williams
    I send an email to Jonathan Wage, and he replied that the extensions can be found at the following URL:
    http://svn.doctrine-project.org/extensions/

  9. March 23rd, 2011 at 02:42 | #9

    This plugin seems to have the same functionalities as sfDoctrineActAsSignablePlugin: http://www.symfony-project.org/plugins/sfDoctrineActAsSignablePlugin

  1. No trackbacks yet.