402

Product support

Get help in the plugin support forum.

Categories

Revision History is an OctoberCMS plugin developed to enables the option the view the record revisions of the content at both - the ‘Record Level’ as well as ‘Field Level’. One can also revert back to the changes made by them, when at the Record & Field Level. This enhances the speed and functionality, along with making it more and more easier for the user.

Why choose Revision History?

  • Easy to Revert Back to the Old Content
  • Clarity of Changes made
  • Quickens the Process
  • Easy Identification of User who made the Change

Salient Features:

  • Review Record Revisions at Record & Field Level
  • Revert Back to Changes from Record & Field Level
Main Display

Usage of ‘Revision History’:

The implementation of the ‘Revision History’ plugin is as easy as it is to use it. One can start using this plugin by implementing its code into the respective file that they wish to use it in. Let us share that code with you, along with a few steps and examples that will help you through the process of using ‘Revision History’.

STEP 1

When your model path is - i.e. yourprojectfolder/plugins/addweb/custom/models/Custom.php

  • Add the below code into your plugin’s model file
  • Take the model code from the official website of OctoberCMS for Revisionable
  • Add the one function shared below, which is also used to get the current user details for logging-in. This will help the system to identify both the changes and the user who made the respective change.

     public function diff() {
         $history = $this->revision_history;
     }

Example:

Pre Model (Before the above code is added)

<?php namespace Addweb\Custom\Models;
use Model;

/**
 * Model
 */
class Custom extends Model
{
use \October\Rain\Database\Traits\Validation;

public $timestamps = false;

public $table = 'addweb_custom_';

/**
 * @var array Validation rules
 */
public $rules = [
];

}

Post Model (After the above code is added)

<?php namespace Addweb\Custom\Models;

use Model;
use BackendAuth; //Add for current user

class Custom extends Model
{
use \October\Rain\Database\Traits\Validation;

// For Revisionable namespace
use \October\Rain\Database\Traits\Revisionable; 

public $timestamps = false;

// Add  for revisions limit
public $revisionableLimit = 200; 

        // Add for revisions on particular field
protected $revisionable = ["id","name","description"];

public $table = 'addweb_custom_';
public $rules = [
];

     // Add  below relationship with Revision model 
     public $morphMany = [
    'revision_history' => ['System\Models\Revision', 'name' => 'revisionable']
     ];

     // Add below function use for get current user details
public function diff(){
    $history = $this->revision_history;
}
public function getRevisionableUser()
{
    return BackendAuth::getUser()->id;
}
}

STEP 2

When your model path is - i.e yourprojectfolder/plugins/addweb/custom/models/custom/columns.yaml

  • Add the below code under the columns.yml file

     revisions:
    type: partial
    path: ~/plugins/saurabhdhariwal/revisionhistory/models/revisionhistory/partials/_content_column.htm
    searchable: false
    sortable: false
    valueFrom: id

Example:

Pre columns.yaml (Before adding the above code)

columns:
id:
    label: ID
    type: number
name:
    label: NAME
    type: text
    searchable: true
    sortable: true
description:
    label: DESCRIPTION
    type: text
    searchable: true
    sortable: true

Post columns.yaml (After adding the above code)

columns:
id:
    label: ID
    type: number
name:
    label: NAME
    type: text
    searchable: true
    sortable: true
description:
    label: DESCRIPTION
    type: text
    searchable: true
    sortable: true
revisions:
    type: partial
    path: ~/plugins/saurabhdhariwal/revisionhistory/models/revisionhistory/partials/_content_column.htm
    searchable: false
    sortable: false
    valueFrom: id

STEP 3

When your model path is - i.e yourprojectfolder/plugins/addweb/custom/Plugin.php

  • Include the below namespace(s) into your Plugin.php file

     use SaurabhDhariwal\Revisionhistory\Classes\Diff as Diff;
     use System\Models\Revision as Revision;
  • Now, add the below line of code into function boot(). (If no boot() method exists then create a new one and put below code inside boot method.)

     /* Extetions for revision */
     Revision::extend(function($model){
         /* Revison can access to the login user */
         $model->belongsTo['user'] = ['Backend\Models\User'];
    
         /* Revision can use diff function */
         $model->addDynamicMethod('getDiff', function() use ($model){
         return Diff::toHTML(Diff::compare($model->old_value, $model->new_value));
     });
     });
     /* End for revision */ 

Example:

Pre Plugin.php (Before adding the above code)

<?php namespace Addweb\Custom;

use System\Classes\PluginBase;

class Plugin extends PluginBase
{
public function registerComponents()
{
}

public function registerSettings()
{
}
}

Post Plugin.php (After adding the above code)

<?php namespace Addweb\Custom;

use System\Classes\PluginBase;
use SaurabhDhariwal\Revisionhistory\Classes\Diff as Diff;
use System\Models\Revision as Revision;

class Plugin extends PluginBase
{
public function boot()
{

  /* Extetions for revision */
  Revision::extend(function($model){
    /* Revison can access to the login user */
    $model->belongsTo['user'] = ['Backend\Models\User'];

    /* Revision can use diff function */
    $model->addDynamicMethod('getDiff', function() use ($model){
      return Diff::toHTML(Diff::compare($model->old_value, $model->new_value));
    });
  });
}
public function registerComponents()
{
}

public function registerSettings()
{
}
}
  • Found the plugin useful on 17 Dec, 2019

    its simple but very usefull

  • author

    Replied on 6 Apr, 2020

    Thanks for the feedback, Fran.

  • Found the plugin useful on 19 Jan, 2019

    Rly usefull

  • author

    Replied on 28 Jan, 2019

    Thanks for the feedback Sergey.

1.0.2

Update composer and change in controller name as per guidelines.

Aug 01, 2021

1.0.1

First version of revisionhistory

Jan 17, 2019