marcj / change-logger-behavior
A behavior allowing you to log one or more columns in a extra logging table like the versionable behavior for Propel2.
Installs: 32 581
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 5
Forks: 1
Open Issues: 0
Requires
- propel/propel: 2.0.*@dev
Requires (Dev)
- phpunit/phpunit: ~4.0
This package is auto-updated.
Last update: 2024-12-11 00:13:09 UTC
README
ChangeLoggerBehavior
A behavior for Propel2, like the VersionableBehavior, but column based. It logs basically all changes
into a extra logger table, defined for each column you have specified in the log
parameter.
Usage
<table name="user"> <column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER" /> <column name="username" type="VARCHAR" size="100" primaryString="true" /> <behavior name="change_logger"> <parameter name="log" value="username"/> <parameter name="created_at" value="true"/> </behavior> </table>
If you haven't installed this behavior through composer, you need to specify the full class name as behavior name:
<behavior name="\MJS\ChangeLogger\ChangeLoggerBehavior">
You can also define multiple columns. Each column gets a own logger table.
<parameter name="log" value="username, email"/>
$user = UserQuery::create()->findByUsername('Klaus'); $user->setUsername('Erik'); $user->setUsernameChangeComment('Due to XY'); $user->setUsernameChangeBy('Superuser'); $user->save() $usernameChangeLogs = UserUsernameLogQuery::create() ->filterByOrigin($user) ->orderByVersion('desc') ->find(); foreach ($usernameChangeLogs as $log) { echo $log->getVersion(); echo $log->getId(); //foreignKey to `user` echo $log->getUsername(); //'Klaus' echo $log->getCreatedAt(); //timestamp }
Parameter
with its default value.
<parameter name="created_at" value="false" /> <parameter name="created_by" value="false" /> <parameter name="comment" value="false" /> <parameter name="created_at_column" value="log_created_at" /> <parameter name="created_by_column" value="log_created_by" /> <parameter name="comment_column" value="log_comment" /> <parameter name="version_column" value="version" /> <parameter name="log" value="" />