Class: Versions extends Model

Keeps a change history of any Model object.



// saving a new version
Versions::add ($obj);

// getting the history of an object
$history = Versions::history ($obj);

// get recent changes by current user
$recent = Versions::recent (User::$user);

// compare current version of a web page to previous:

// 1. fetch the page
$w = new Webpage ('index');

// 2. get the previous version (limit=1, offset=1)
$history = Versions::history ($w, 1, 1);

// 3. restore the first result's object
$v = new Versions;
$w2 = $v->restore ($history[0]);

// 4. compare the two
$modified_fields = Versions::diff ($w, $w2);



  • id - versions id
  • class - class name of the object
  • pkey - object's 'key' field value
  • user - user id or 0 if no user saved
  • ts - date/time of the change
  • serialized - serialized version of the object


public $table = '#prefix#versions'

The database table name.


public static add ($obj)

Add a version to the store.

public restore ($vobj = false)

Recreate an object from the stored version. Takes any result from recent() or history().

public static recent ($user = false, $limit = 10, $offset = 0)

Get recent versions by a user or everyone.

public static history ($obj, $limit = 10, $offset = 0)

Get recent versions of an object, or of objects of a specific class. If $limit is set to true (boolean), it will return a count of the history.

public static diff ($obj1, $obj2)

Compare two versions of a Model object. Returns an array of properties that have changed between the two versions, but does no comparison of the changes themselves. Note that this looks at the data array of the Model objects, not object properties, so it will not work on ordinary objects, only Model-based objects and objects returned by the recent() and history() methods.

public static get_classes ()

Get a list of classes that have objects stored.

public static display_name ($name)

Get the display name for a class.

public static plural_name ($name)

Get the plural name for a class.