Table of Contents

Acts as versioned plugin for Akelos Active Records

This plugin adds versioning capabilities to you Active Record Models.

Installation

./script/plugin install acts_as_versioned

Enabling versioning in your models

Say you have a Chapter model and you want to keep the latest 20 modifications for each chapter.

Adding the acts as behaviour to your Chapter model

./app/models/chapter.php

<?php
 
class Chapter extends ActiveRecord
{
    var $acts_as = array('versioned' => array('limit'=>10));
}
 
?>

Modifying your ''chapters'' table to add a version number and create a ''chapter_versions'' table

./app/installers/chapter_installer.php

<?php
 
Ak::import('Chapter');
Ak::loadPlugins();
 
class ChapterInstaller extends AkInstaller
{
    function up_1()
    {
        //.....
    }
 
    function up_2()
    {
        $Chapter =& new Chapter();
        $Chapter->versioned->createVersionedTable();
    }
 
    function down_1()
    {
        //.....
    }
 
    function down_2()
    {
        $Chapter =& new Chapter();
        $Chapter->versioned->dropVersionedTable();
    }
}
 
?>

Using your brand new versioning system

$Chapter->versioned
$Chapter->versioned->load()
$Chapter->versioned->revertToVersion(3);
$Chapter->versioned->find();
$Chapter->versions
$Chapter->versions[2]->getNext();
$Chapter->versions[2]->getPrevious();