by prettyscripts on 2010-05-25 14:36:07
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.
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 (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; | |
} | |
} | |
} | |
} |
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 |