marcj/change-logger-behavior

There is no license information available for the latest version (dev-master) of this package.

A behavior allowing you to log one or more columns in a extra logging table like the versionable behavior for Propel2.

dev-master 2015-01-08 12:05 UTC

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="" />