olegf13 / yii2-mongorevision-behavior
MongoRevision behavior for Yii 2
Installs: 23
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 1
Open Issues: 0
Type:yii2-extension
Requires
- yiisoft/yii2: *
- yiisoft/yii2-mongodb: ~2.1
This package is not auto-updated.
Last update: 2024-11-09 19:40:18 UTC
README
This behavior provides automatic revision creation of any ActiveRecord object(s) into MongoDB collection.
It means, that the extension will automatically save "previous version" of your ActiveRecord object after it's been updated.
So you can store and track the history of all your data changes.
To describe in detail, MongoRevision behavior will collect "old" AR object attributes, fill the revisionOwnerId
,
revisionOwnerModel
, revisionDate
and revisionUser
attributes with the corresponding values;
and then store the resulting AR object revision in particular MongoDB revision
collection.
Behavior is called after the associated AR object is being updated (EVENT_AFTER_UPDATE).
Installation
This extension requires MongoDb Extension for Yii 2.
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist olegf13/yii2-mongorevision-behavior "*"
or add
"olegf13/yii2-mongorevision-behavior": "*"
to the require section of your composer.json
file.
Usage
To use MongoRevisionBehavior, insert the following code to your ActiveRecord class:
use olegf13\mongorevision\MongoRevisionBehavior; // ... public function behaviors() { return [ MongoRevisionBehavior::className(), ]; }
If your MongoDB connection name is different or you want to use a different collection or attribute names, you may configure behavior properties like the following:
use olegf13\mongorevision\MongoRevisionBehavior; // ... public function behaviors() { return [ [ 'class' => MongoRevisionBehavior::className(), 'mongoConnectionName' => 'mongodb', 'mongoCollection' => 'revision', 'revisionOwnerIdAttribute' => 'ownerId', 'revisionOwnerModelAttribute' => 'ownerModel', 'revisionDateAttribute' => 'revisionDate', 'revisionUserAttribute' => 'revisionUser', ], ]; }