2017 © Pedro Peláez
 

yii2-extension yii2-pgsql-audit

Audit for ActiveRecord models for Yii2, for PostgreSQL only

image

tigrov/yii2-pgsql-audit

Audit for ActiveRecord models for Yii2, for PostgreSQL only

  • Friday, March 23, 2018
  • by Tigros
  • Repository
  • 1 Watchers
  • 0 Stars
  • 14 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 8 Versions
  • 0 % Grown

The README.md

yii2-pgsql-audit

Audit for ActiveRecord models for Yii2, for PostgreSQL only., (*1)

The extension is used as a behavior for an ActiveRecord model. It will store all changes for the model and gives you possibility to review the changes and revert them., (*2)

Latest Stable Version Build Status, (*3)

Limitation

It is for PostgreSQL only., (*4)

The extension optimized for integer type of \Yii::$app->user->id
and for ActiveRecord models with integer type of primary key., (*5)

If you have different of integer types, you can inherit the classes and make the necessary changes. Also you need to make changes in the audit table schema., (*6)

  • Since 1.2.0 requires PHP >= 5.5
  • Since 1.3.0 requires Yii >= 2.0.14.2

Dependents

The extension depends on follow extensions: * Tigrov/yii2-pgsql-enum, (*7)

Installation

The preferred way to install this extension is through composer., (*8)

Either run, (*9)

php composer.phar require --prefer-dist tigrov/yii2-pgsql-audit

or add, (*10)

"tigrov/yii2-pgsql-audit": "~1.0"

to the require section of your composer.json file., (*11)

Configuration

Once the extension is installed, configure migrations in config.php:, (*12)

return [
    // ...
    'controllerMap' => [
        'migrate' => [
            'class' => 'yii\console\controllers\MigrationController',
        ],
    ],
    // ...
];

and apply migrations:, (*13)

yii migrate

Usage

Add the behavior AuditableBehavior to a model class., (*14)

class Model extends \yii\db\ActiveRecord
{
    public function behaviors()
    {
        return [
            AuditableBehavior::class,
        ];
    }
}

Some examples how you can use it:, (*15)

$model = new Model;
$model->value = 'a value';
$model->save();

$model->createdAt; // created date and time
$model->createdBy; // instance of \Yii::$app->user->identityClass

// then update it
$model->value = 'new value';
$model->save();

$model->updatedAt; // updated date and time
$model->updatedBy; // instance of \Yii::$app->user->identityClass

// additional features
$model->firstAudit; // \tigrov\pgsql\audit\Audit
$model->lastAudit; // \tigrov\pgsql\audit\Audit

$model->lastAudit->model; // ActiveRecord
$model->lastAudit->user; // instance of \Yii::$app->user->identityClass

$model->lastAudit->revert(); // revert the last changes
$model->firstAudit->revert(); // revert to the first model version

Audit::findByModel($model); // ActiveQuery, to get audit records for the model
Audit::findByUserId($userId); // ActiveQuery, to get audit records for a user

License

MIT, (*16)

The Versions

23/03 2018

dev-master

9999999-dev

Audit for ActiveRecord models for Yii2, for PostgreSQL only

  Sources   Download

MIT

The Requires

 

by Sergei Tigrov

extension postgresql postgres yii2 pgsql audit

23/03 2018

1.3.0

1.3.0.0

Audit for ActiveRecord models for Yii2, for PostgreSQL only

  Sources   Download

MIT

The Requires

 

by Sergei Tigrov

extension postgresql postgres yii2 pgsql audit

01/03 2018

1.2.0

1.2.0.0

Audit for ActiveRecord models for Yii2, for PostgreSQL only

  Sources   Download

MIT

The Requires

 

by Sergei Tigrov

extension postgresql postgres yii2 pgsql audit

07/10 2017

1.1.3

1.1.3.0

Audit for ActiveRecord models for Yii2, for PostgreSQL only

  Sources   Download

MIT

The Requires

 

by Sergei Tigrov

extension postgresql postgres yii2 pgsql audit

24/09 2017

1.1.2

1.1.2.0

Audit for ActiveRecord models for Yii2, for PostgreSQL only

  Sources   Download

MIT

The Requires

 

by Sergei Tigrov

extension postgresql postgres yii2 pgsql audit

23/07 2017

1.1.1

1.1.1.0

Audit for ActiveRecord models for Yii2, for PostgreSQL only

  Sources   Download

MIT

The Requires

 

by Sergei Tigrov

extension postgresql postgres yii2 pgsql audit

23/07 2017

1.1.0

1.1.0.0

Audit for ActiveRecord models for Yii2, for PostgreSQL only

  Sources   Download

MIT

The Requires

 

by Sergei Tigrov

extension postgresql postgres yii2 pgsql audit

31/05 2017

1.0.0

1.0.0.0

Audit for ActiveRecord models for Yii2, for PostgreSQL only

  Sources   Download

MIT

The Requires

 

by Sergei Tigrov

extension postgresql postgres yii2 pgsql audit