Symfony: Hacking sfDoctrineActAsSignablePlugin to allow updated and created by specific user

I’m using sfDoctrineActAsSignablePlugin (V1.0.0) to audit record creation and updates. ie fields created_by and updated_by are automatically created and updated.

This is perfect when running from browsers. But when running as command line such as loading initial data (via symfony doc:build –all –and-load) or customized task to import data, the fields are set to null. The project I’m working on requires these fields to set to specific user (a non-login user) when data are created and / or updated by these tasks.

Hacking the code

Edit /path/to/plugins/sfDoctrineActAsSignablePlugin/lib/listener. Make changes to the following function, line 78 and 101 of the code:

public function getUserId($type) {
  $options = $this->_options['type']; // was in line 78, move it here
  if (0 != strncasecmp(PHP_SAPI, 'cli', 3)) {
    // $options = $this->_options['type']; // original code
    ..... // code as is
  } } elseif (!class_exists("pakeApp")) {
    ..... // code as is
  } else {
    // return null;  // original code
    switch ($options['type']) {
      case 'integer':
        return sfConfig::get('app_signable_cli_userid', null);
        break;
      case 'string':
        return sfConfig::get('app_signable_cli_username', null);
        break;
      }
    }
  }
}

Config app.yml

This is optional. The plugin will run as original if not used. Config username or userid (as in sf_guard_user) depending if created_by and updated_by is string or integer:

all:
  signable:
    cli_username:   auto
    cli_userid:     10

Leave a Reply

Your email address will not be published. Required fields are marked *