https://github.com/mathsgod/r-db-eventlog
https://github.com/mathsgod/r-db-eventlog
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/mathsgod/r-db-eventlog
- Owner: mathsgod
- License: mit
- Created: 2022-10-14T03:00:49.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-10-14T03:08:59.000Z (over 3 years ago)
- Last Synced: 2025-03-13T09:03:25.033Z (over 1 year ago)
- Language: PHP
- Size: 13.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# r-db-eventlog
Auto generated event log when a database record is created, inserted and deleted.
## setup
Create database table EventLog
```sql
CREATE TABLE `EventLog` (
`eventlog_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`class` varchar(64) DEFAULT NULL,
`id` int(10) unsigned NOT NULL,
`action` varchar(64) DEFAULT NULL,
`source` json DEFAULT NULL,
`target` json DEFAULT NULL,
`remark` text,
`user_id` int(10) unsigned NOT NULL,
`created_time` datetime NOT NULL,
`status` int(10) unsigned DEFAULT '0',
`different` json DEFAULT NULL,
PRIMARY KEY (`eventlog_id`),
KEY `class` (`class`),
KEY `user_id` (`user_id`),
KEY `id` (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
```
Register listeners
```php
$schema = \R\DB\Model::GetSchema();
$subscriber = new ListenerSubscriber();
$subscriber->setUserId(1);
$schema->eventDispatcher()->subscribeListenersFrom($subscriber);
```