vgalkin-dev/yii2-audit
Composer 安装命令:
composer require vgalkin-dev/yii2-audit
包简介
Extensions to the Yii 2 PHP framework allowing tracking and viewing change history of a model.
README 文档
README
Extensions to the Yii 2 PHP framework allowing tracking and viewing change history of a model.
Changes are tracked using triggers, but model events should also be available as a fallback when using an unsupported database.
Provides:
- a model behavior:
- loads older model versions
- temporarily disabled tracking
- a command to manage and verify audit database objects
- a controller action with a view to view model change history
Installation
Install via composer:
composer require nineinchnick/yii2-audit
Warning! If the database is restored from a dump, it's necessary to reenumaret table oids in audits.logged_actions.relation_id column using the following query:
UPDATE audits.logged_actions SET relation_id = (schema_name || '.' || table_name)::regclass::oid;
Recording changes
Attach the behavior to the model, after the Blameable and Timestamp behaviors:
use yii\behaviors\BlameableBehavior; use yii\behaviors\TimestampBehavior; use nineinchnick\audit\behaviors\TrackableBehavior; public function behaviors() { return [ BlameableBehavior::className(), TimestampBehavior::className(), [ 'class' => TrackableBehavior::className(), 'mode' => TrackableBehavior::MODE_TRIGGER, ], ]; }
If using trigger mode, run a command that generates migrations, which would create or update database objects like triggers and audit tables.
First, configure the controller in your console config:
'controllerMap' => [ 'audit' => [ 'class' => 'nineinchnick\audit\console\AuditController', ], ], // .... rest of configuration
Then run the command:
./yii audit/migration --modelName=AR_MODEL_CLASS
where AR_MODEL_CLASS is your model class name.
Displaying changes
To view the change history, use the provided module in your app config:
'modules' => [ 'audit' => [ 'class' => 'nineinchnick\audit\Module', ], // .... other modules ],
Sample configuration
'audit' => [ 'class' => 'nineinchnick\audit\Module', 'tables' => [ 'orders' => [ 'model' => 'netis\orders\models\Order', 'hiddenColumns' => ['id', 'created_on', 'author_id'], 'updateSkip' => ['updated_on', 'editor_id'], 'relations' => [ 'editor' => [ 'type' => 'LEFT JOIN', 'table' => '{{%users}}', 'on' => 'editor_id = u.id', 'alias' => 'u', 'representive_columns' => 'username', 'label' => Yii::t('models', 'Editor'), ], ] ], ], 'filters' => [ 'dateFrom' => [ 'format' => 'date', 'attribute' => 'operation_date', 'widgetClass' => 'omnilight\widgets\DatePicker', 'options' => ['class' => 'form-control'], 'dateFormat' => 'yyyy-MM-dd', 'rules' => [ [ 'validator' => 'date', 'options' => ['format' => 'Y-m-d'], ] ], 'criteria' => [ 'operator' => '>=', ], ], 'dateTo' => [ 'format' => 'date', 'attribute' => 'operation_date', 'widgetClass' => 'omnilight\widgets\DatePicker', 'options' => ['class' => 'form-control'], 'dateFormat' => 'yyyy-MM-dd', 'rules' => [ [ 'validator' => 'date', 'options' => ['format' => 'Y-m-d'], ] ], 'criteria' => [ 'operator' => '<=', ], ], ], ],
References
vgalkin-dev/yii2-audit 适用场景与选型建议
vgalkin-dev/yii2-audit 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13.09k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 08 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 vgalkin-dev/yii2-audit 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 vgalkin-dev/yii2-audit 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 13.09k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 20
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-08-26