From 87c5bcdd146ec186763c96b162d6bbb425efd732 Mon Sep 17 00:00:00 2001 From: reloxx13 Date: Thu, 6 Sep 2018 16:22:24 +0200 Subject: [PATCH 1/2] Correct readme add behavior in table class not entity. add option fields description --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0c14520..946fbc0 100644 --- a/README.md +++ b/README.md @@ -27,9 +27,8 @@ Or run the following command directly without changing your `composer.json`: `composer require josegonzalez/cakephp-version:dev-master` -## Usage -In your app's `config/bootstrap.php` add: +In your app's `config/bootstrap.php` add to load the Plugin: ```php Plugin::load('Josegonzalez/Version', ['bootstrap' => true]); @@ -93,7 +92,7 @@ class PostEntity extends Entity { } ``` -Attach the behavior in the models you want with: +Attach the behavior in the table initialize function you want with: ```php public function initialize(array $config) { @@ -259,3 +258,4 @@ There are five behavior configurations that may be used: - `additionalVersionFields`: (Default `['created']`) The additional or custom fields of the versioned table to be exposed as well. By default prefixed with `version_`, e.g. `'version_user_id'` for `'user_id'`. - `referenceName`: (Default: db table name) Discriminator used to identify records in the version table. - `onlyDirty`: (Default: false) Set to true to version only dirty properties. +- `fields`: List of fields which should get saved in the versions table, if not defined all fields will be saved. Can be string or array From e95287e8e019fe981326a676c09c530c93ec73b6 Mon Sep 17 00:00:00 2001 From: reloxx13 Date: Fri, 7 Sep 2018 10:51:17 +0200 Subject: [PATCH 2/2] Listener Hints Add some more Listener Hints --- README.md | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 946fbc0..70bf2b1 100644 --- a/README.md +++ b/README.md @@ -135,8 +135,10 @@ CREATE TABLE `version` ( ``` Then define an event listener to handle the event and pass in additional metadata, for example: - +App/src/Event/VersionListener.php ```php +namespace App\Event; + use Cake\Event\Event; use Cake\Event\EventListenerInterface; @@ -158,7 +160,7 @@ class VersionListener implements EventListenerInterface { ``` Your event listener can then be attached in your project, for example: - +in bootstrap.php ```php use App\Event\VersionListener; use Cake\Event\EventManager; @@ -172,7 +174,7 @@ This can provide useful functionality, but ensure that if your event listener re `version_id`, `model`, `foreign_key`, `field`, `content` or `created` that this is the intended behavior. #### Storing user_id as Meta Data -To store the `user_id` as additional meta data is easiest in combination with [Muffin/Footprint](https://github.com/UseMuffin/Footprint). +To store the `modified by user id` as additional meta data is easiest in combination with [Muffin/Footprint](https://github.com/UseMuffin/Footprint). The above `insertAdditionalData()` method could then look like this: ```php @@ -184,13 +186,14 @@ The above `insertAdditionalData()` method could then look like this: public function insertAdditionalData(Event $event) { $data = [ - ... + //your additional custom data ]; + //get modified_by_user_id from footprint plugin which holds the current logged in user entity if ($event->data('_footprint')) { $user = $event->data('_footprint'); - $data += [ - 'user_id' => $user['id'], + $data += [ + 'modified_by_user_id' => $user->id, ]; }