rmrevin/yii2-changelog Active record changelog extension for Yii 2 framework

activerecordhistorychangelog

Active record changelog extension for Yii 2 framework

This extension provides a changelog functional.

For license information check the LICENSE-file.

Support

Installation

The preferred way to install this extension is through composer.

Either run

composer require "rmrevin/yii2-changelog:~1.0"

or add

"rmrevin/yii2-changelog": "~1.0",

to the require section of your composer.json file.

Execute migrations:

php yii migrate --migrationPath=@rmrevin/yii/changelog/migrations

Usage

To view the history, you can use a special panel for debug. Or make your own section to view the data in your administration panel.

To enable the debug panel, add the following code in the module configuration debug.

    'modules' => [
        // ...
        'debug' => [
            'class' => yii\debug\Module::className(),
            'panels' => [
                rmrevin\yii\changelog\debug\panels\ChangelogPanel::class,
            ],
        ],
    ],

For ActiveRecord models for which you want to track changes, you must implement the interface rmrevin\yii\changelog\interfaces\LoggableInterface and add the behavior of rmrevin\yii\changelog\behaviors\ChangelogBehavior.

Example:

<?php

use rmrevin\yii\changelog\interfaces\LoggableInterface;
use rmrevin\yii\changelog\behaviors\ChangelogBehavior;
use yii\db\ActiveRecord;

/**
 * Class ShopItem
 *
 * @property integer $id
 * @property integer $number
 * @property string $title
 * @property integer $created_at
 * @property integer $updated_at
 * @property integer $synchronized_at
 */
class ShopItem extends ActiveRecord implements LoggableInterface
{

    /**
     * @inheritdoc
     */
    public function __toString()
    {
        return sprintf('[%s] %s', $this->number, $this->title);
    }

    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
            // ...
            [
                'class' => ChangelogBehavior::class,
                'ignoreAttributes' => [ // these attributes are not tracked
                    'updated_at',
                    'synchronized_at',
                ],
            ],
        ];
    }
}

Done

Now when you try to create, modify or delete an instance of a model ShopItem in the table {{%changelog}} will be recorded relevant information.

Changelog

2016-10-05 - 1.0.1

  • Bugfix #1

2016-07-14 - 1.0.0

  • Change mysql table engine to ARCHIVE.
  • Added collector log for the bulk insert.
  • Global refactoring.

2016-06-01 - 0.1.4

  • Added the ability to use his model to save log.

2016-04-21 - 0.1.2

  • Update summary debug panel view to new css.
  • Updated packages.

2015-12-28 - 0.1.1

  • Rename excludeAttributes to ignoreAttributes.

2015-12-28 - 0.1.0

  • Initial extension.

Statistics

Downloads
GitHub Stars
GitHub Forks

Releases

Comments



1.0.1 is the latest of 7 releases



MIT license
Stats
10 github stars & 4 github forks
0 downloads in the last day
1 downloads in the last 30 days
250 total downloads