Logs changes for defined columns in a extra logger table, for Propel2
PHP
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
tests
.gitignore
.travis.yml
LICENSE
README.md
composer.json
phpunit.xml

README.md

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