Samuell1 / revisions-plugin

Revisions allows to extend any model with Revisionable trait with more features and easy to use.
https://octobercms.com/plugin/samuell-revisions
MIT License
9 stars 7 forks source link

Jsonable fields are getting all logged right now, even when there is not a single change #33

Closed TimFoerster closed 1 year ago

TimFoerster commented 2 years ago

They have also null values instead of empty arrays. Don't know if that is Ocms v3 related.

image

TimFoerster commented 2 years ago

All entries are also stored twice?

TimFoerster commented 2 years ago

All entries are also stored twice?

Both listen to the same events, therefore it will be stored twice.

https://github.com/Samuell1/revisions-plugin/blob/da905839a75fcf7c4c4e6853cf45fb33b1fa1bda/traits/Revisions.php#L15-L35

Revisionable:

public function initializeRevisionable()
    {
        if (!is_array($this->revisionable)) {
            throw new Exception(sprintf(
                'The $revisionable property in %s must be an array to use the Revisionable trait.',
                get_class($this)
            ));
        }

        $this->bindEvent('model.afterUpdate', function () {
            $this->revisionableAfterUpdate();
        });

        $this->bindEvent('model.afterDelete', function () {
            $this->revisionableAfterDelete();
        });
    }
Samuell1 commented 2 years ago

@TimFoerster Hey, you need to only include trait from this plugin, if you add both traits it will fire 2 times.

TimFoerster commented 2 years ago

This is already the case

use Samuell\Revisions\Traits\Revisions;

class Company extends Model
{
    use Revisions;

    protected $revisionable = [
        'section',
        'name',
        'address',
        'type',
        'station_id',
        'content',
        'contacts',
        'divisions',
        'persons'
    ];
    ...    

Error appears only with ocms 3.

Samuell1 commented 2 years ago

@TimFoerster if you remove that bindEvent it works correctly?

skacco commented 2 years ago

I have the same problem. You need to comment this part on your plugin inside revisions/traits/Revisions.php

       /* $model->bindEvent('model.afterUpdate', function () use ($model) {
            $model->revisionableAfterUpdate();
        });

        $model->bindEvent('model.afterDelete', function () use ($model) {
            $model->revisionableAfterDelete();
        });*/
Samuell1 commented 1 year ago

@skacco @TimFoerster Hey, if you can pull master changes and try it out if it works correctly, Thanks!