nti/audit-bundle
Composer 安装命令:
composer require nti/audit-bundle
包简介
Audit bundle for symfony3 and doctrine orm, logs any database change
README 文档
README
This bundle creates an audit log for all doctrine ORM database related changes:
- inserts ion changes, association and dissociation actions.
- if there is an user and updates including their diffs and relation field diffs.
- many to many relatin token storage, it will link him to the log.
- the audit entries are inserted within the same transaction during flush, if something fails the state remains clean.
Basically you can track any change from these log entries if they were managed through standard ORM operations.
NOTE: audit cannot track DQL or direct SQL updates or delete statement executions.
Pre-Install
To continue using Query Loggers methods within the audit log bundle, Symfony versions up to 6.x require the installation of firehed/dbal-logger v1.0.1. Make sure to have this installed before proceeding to the next step.
Install
First, install it with composer:
composer require nti/audit-bundle
Then, add it in your AppKernel bundles.
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
...
new DataDog\AuditBundle\DataDogAuditBundle(),
...
);
...
}
Using Query:
//SQL
CREATE TABLE audit_logs (id INT AUTO_INCREMENT NOT NULL, source_id INT NOT NULL, target_id INT DEFAULT NULL, blame_id INT DEFAULT NULL, action VARCHAR(12) NOT NULL, tbl VARCHAR(128) NOT NULL, diff LONGTEXT DEFAULT NULL COMMENT'(DC2Type:json_array)', logged_at DATETIME NOT NULL, UNIQUE INDEX UNIQ_D62F2858953C1C61 (source_id), UNIQUE INDEX UNIQ_D62F2858158E0B66 (target_id), UNIQUE INDEX UNIQ_D62F28588C082A2E (blame_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET UTF8 COLLATE UTF8_unicode_ci ENGINE = InnoDB;
CREATE TABLE audit_associations (id INT AUTO_INCREMENT NOT NULL, typ VARCHAR(128) NOT NULL, tbl VARCHAR(128) DEFAULT NULL, label VARCHAR(255) DEFAULT NULL, fk VARCHAR(255) NOT NULL, class VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET UTF8 COLLATE UTF8_unicode_ci ENGINE = InnoDB;
CREATE TABLE audit_request (id INT AUTO_INCREMENT NOT NULL, method VARCHAR(255) DEFAULT NULL, controller VARCHAR(255) DEFAULT NULL, route VARCHAR(255) DEFAULT NULL, route_params LONGTEXT DEFAULT NULL, ip VARCHAR(255) DEFAULT NULL, user_name VARCHAR(255) DEFAULT NULL,portal VARCHAR(255) DEFAULT NULL, query_data LONGTEXT DEFAULT NULL, data LONGTEXT DEFAULT NULL, created_on DATETIME DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET UTF8 COLLATE UTF8_unicode_ci ENGINE = InnoDB; ALTER TABLE audit_logs ADD CONSTRAINT FK_D62F2858953C1C61 FOREIGN KEY (source_id) REFERENCES audit_associations (id);
ALTER TABLE audit_logs ADD CONSTRAINT FK_D62F2858158E0B66 FOREIGN KEY (target_id) REFERENCES audit_associations (id);
ALTER TABLE audit_logs ADD CONSTRAINT FK_D62F28588C082A2E FOREIGN KEY (blame_id) REFERENCES audit_associations(id);
ALTER TABLE audit_associations ADD created_on DATETIME NOT NULL;
Using Doctrine Schema:
// Doctrine
php bin/console doctrine:schema:update -f
Config
Enable the audit request in the project:
// app/config.yml
# DataDog
data_dog_audit:
audit_request:
enabled: true
If you will use a custom database connection use following config:
// app/config.yml
# DataDog
data_dog_audit:
database:
connection_name: nti_logs
audit_request:
enabled: true
See How to Work with multiple Entity Managers and Connections
Annotations
Annotations has to use in the controller, add Annotations NTIAudit in the class:
//src/Bundle/Controller/Controller.php
use DataDog\AuditBundle\Annotations\NTIAudit;
/**
* Class Controller
* @package AppBundle\Controller
* @NTIAudit()
* @Route("/controller")
*/
class Controller extends Controller {
//TODO CODE HERE
}
Unaudited Entities
Sometimes, you might not want to create audit log entries for particular entities.
You can achieve this by listing those entities under the unaudited_entities configuration
key in your config.yml, for example:
data_dog_audit:
unaudited_entities:
- AppBundle\Entity\NoAuditForThis
Specify Audited Entities
Sometimes, it is also possible, that you want to create audit log entries only for particular entities. You can achieve it quite similar to unaudited entities. You can list them under the audited_entities configuration key in your config.yml, for example:
data_dog_audit:
audited_entities:
- AppBundle\Entity\AuditForThis
You can specify either audited or unaudited entities. If both are specified, only audited entities would be taken into account.
Command
For delete audit data:
php bin/console nti:audit:delete {qtyDays}
License
NTI
nti/audit-bundle 适用场景与选型建议
nti/audit-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.79k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2019 年 06 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「log」 「orm」 「bundle」 「doctrine」 「Audit」 「symfony3」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 nti/audit-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 nti/audit-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 nti/audit-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Kinikit - PHP Application development framework MVC component
2lenet/EasyAdminPlusBundle
PHP Database ORM for Symfony1. Do NOT use for new projects: please move to a newest Symfony release and Doctrine2
The bundle for easy using json-rpc api on your project
Provide a way to secure accesses to all routes of an symfony application.
DMS Meetup API Bundle, enables Meetup API clients in services
统计信息
- 总下载量: 2.79k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 26
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-06-05