symfony: hacking sfDoctrineActAsSignablePlugin to allow updated and created by specific user

by prettyscripts on 2010-05-25 14:36:07

symfony

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:

PHP:

public function getUserId($type) {
  $options $this->_options['type']; // was in line 78, move it here
  if (!= 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:

Code:

all:
  signable:
    cli_username:   auto
    cli_userid:     10

Tags: created, hack, plugin, symfony, updated, user

No feedback yet

Leave a comment


Your email address will not be revealed on this site.
PoorExcellent
note: all comments are moderated. do not spam and do not advertise. only comments relevant to the post will be published.
(Line breaks become <br />)
(For my next comment on this site)
(Allow users to contact me through a message form -- Your email will not be revealed!)