This repository has been archived by the owner on May 14, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
76 lines (52 loc) · 1.81 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
Acts as versioned behaviour plugin for Akelos Active Records
===================================
This plugin adds versioning capabilities to you Active Record Models.
Installation
--------------------------------
./script/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 // behaviour handler
* $Chapter->versioned->load() // Loads versions, pass true to force a db reload
* $Chapter->versioned->revertToVersion(3); // Rolling back a version
* $Chapter->versioned->find(); // Same as find() but scoped to older versions
* $Chapter->versions // Guess what? An array with your versions
* $Chapter->versions[2]->getNext(); // Next versioned item if exists
* $Chapter->versions[2]->getPrevious(); // Previous versioned item if exists