yii2mod / yii2-data-sync-behavior
Behavior for export data to local files from database tables. Changes are tracked using model events.
Installs: 135
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 3
Forks: 2
Open Issues: 0
Type:yii2-extension
Requires
- php: >=5.5
- yiisoft/yii2: >=2.0.8
Requires (Dev)
This package is not auto-updated.
Last update: 2017-08-20 08:17:09 UTC
README
Behavior for export data to local files from database tables. Changes are tracked using model events.
[](https://packagist.org/packages /yii2mod/yii2-data-sync-behavior)
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist yii2mod/yii2-data-sync-behavior "*"
or add
"yii2mod/yii2-data-sync-behavior": "*"
to the require section of your composer.json
file.
Recording changes
Attach the behavior to the model:
use yii2mod\datasync\DataSyncBehavior; public function behaviors() { return [ 'dataSync' => [ 'class' => DataSyncBehavior::className(), // `folderPath` property maybe need to change. 'folderPath' => '@app/config/data' ], ]; }
- After model events(AFTER_UPDATE, AFTER_INSERT, AFTER_DELETE) behavior will be automatically create files in default path(@app/config/data) with data from this model.
- Files will be created in json format.
Import changes
- Add
datasync
command to console config:
'controllerMap' => [
'datasync' => [
'class' => 'yii2mod\datasync\commands\DataSyncCommand',
// `folderPath` property maybe need to change.
'folderPath' => '@app/config/data'
],
],
-
Execute command from console. For example:
php yii datasync - synchronize data for all files php yii datasync/index --table=User - synchronize data only for `User` table