angelxmoreno/cakephp-auditor

Auditor plugin for CakePHP

1.0.2 2018-03-01 12:57 UTC

This package is auto-updated.

Last update: 2024-04-16 02:58:34 UTC


README

Requirements

* CakePHP 3.4.0+
* PHP 5.6+

Installation

You can install this plugin into your CakePHP application using composer.

The recommended way to install composer packages is:

composer require angelxmoreno/cakephp-auditor

Then you need to apply two behaviors:

  1. One on your UsersTable ( the Auditors )
$this->addBehavior('Auditor.Auditor');
  1. Another on your tables you with to track
$this->addBehavior('Auditor.Audit');

Options

For the AuditBehavior you have the following default options:

[
    'attach'      => true,
    'reverse'     => false,
    'skip_fields' => [],
]

attach: Boolean ( default true)

Whether or not the behavior should attach the given table to the AuditsTable as a HasMany association

reverse: Boolean ( default false)

Whether or not the behavior should attach the AuditsTable to the given table as a belongsTo association

skip_fields: Array ( default empty array)

The fields that should be ignored when saving the diff of the previous and current fields.

[ It is recommended to add your created and modified fields]

Extras

I personally use a BaseTable and extend all my Table classes from that. It makes it easier to add traits, methods and other goodies to all my Table classes. I created a convenience method to conditionally add the Audit behavior when the Table class is not the AuditsTable. You can make use of it like so:

\Auditor\Model\Behavior\AuditBehavior::makeAuditable($this, [
    'attach'      => false,
    'skip_fields' => ['modified', 'created'],
]);

License

Copyright 2018 Angel S. Moreno (angelxmoreno). All rights reserved.

Licensed under the MIT License. Redistributions of the source code included in this repository must retain the copyright notice found in each file.