This plugin adds versioning capabilities to you Active Record Models.
./script/plugin install acts_as_versioned
Say you have a Chapter model and you want to keep the latest 20 modifications for each chapter.
./app/models/chapter.php
<?php class Chapter extends ActiveRecord { var $acts_as = array('versioned' => array('limit'=>10)); } ?>
./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(); } } ?>
$Chapter->versioned
$Chapter->versioned->load()
$Chapter->versioned->revertToVersion(3);
$Chapter->versioned->find();
$Chapter->versions
$Chapter->versions[2]->getNext();
$Chapter->versions[2]->getPrevious();