yii2mod/yii2-data-sync-behavior

This package is abandoned and no longer maintained. No replacement package was suggested.

Behavior for export data to local files from database tables. Changes are tracked using model events.

1.3 2016-11-22 14:43 UTC

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.

[Latest Stable Version](https://packagist.org/packages /yii2mod/yii2-data-sync-behavior) Total Downloads License Build Status

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

  1. Add datasync command to console config:
   'controllerMap' => [
       'datasync' =>  [
           'class' => 'yii2mod\datasync\commands\DataSyncCommand',
           // `folderPath` property maybe need to change.
           'folderPath' => '@app/config/data'
       ],
   ],
  1. 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