tigrov/yii2-pgsql-audit 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tigrov/yii2-pgsql-audit

Composer 安装命令:

composer require tigrov/yii2-pgsql-audit

包简介

Audit for ActiveRecord models for Yii2, for PostgreSQL only

README 文档

README

Audit for ActiveRecord models for Yii2, for PostgreSQL only.

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.

Latest Stable Version Build Status

Limitation

It is for PostgreSQL only.

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

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.

  • 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:

Installation

The preferred way to install this extension is through composer.

Either run

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

or add

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

to the require section of your composer.json file.

Configuration

Once the extension is installed, configure migrations in config.php:

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

and apply migrations:

yii migrate

Usage

Add the behavior AuditableBehavior to a model class.

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

Some examples how you can use it:

$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

统计信息

  • 总下载量: 50
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-05-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固