Not a developer? Go to MovableType.com

MT5 Documentation

Revision history in Plugin

About MT::Revisable interface

Movable Type 5 comes with a revision history framework built in. What does that mean? It means that a developer can easily use revision history for own objects.

The following methods are supported on any revisable object:

 $obj->pack_revision()

Creates the hashref that will be stored as a particular revision of the object. By default, this hashref contains the values of the object's normal and meta columns. The ''<package>::pack_revision'' callback can be used to add values from the plugin to be stored with the revision.

 $obj->unpack_revision($packed_obj) 

The opposite of ''pack_revision'', takes the ''$packed_obj'' hashref and unpacks it, setting the values of ''$obj'' as needed. The ''<package>::unpack_revision'' callback can be used for any other keys added to ''$packged_obj'' that are not part of the normal or meta columns.

 $obj->save_revision()

Called automatically when an object is saved from the MT web interface or posted via a 3rd party client (on a low priority api/cms_post_save callback). Saves a revision only if at least one revisioned column has changed.

 $obj->load_revision(\%terms, \%args)

Loads revisions for the ''$obj''. Arguments work similarly to ''MT::Object->load''. Thus, one can simply do ''$obj->load_revision($rev_numer)'' or pass terms and args. load_revision should return an/array of arrayref(s).

 $obj->apply_revision(\%terms, \%args)

Rolls back to the state of the object at ''$obj-load_revision(\%terms, \%args)'' and saves this action as a revision.

Manage revision history

Inheriting from the Revisable Interface

To make an object revisable, a developer do need only two actions.

  • Their package inherits from the MTRevisable interface.
  • Add 'revisioned' to any column.

Here is the sample code.


    package My::Object::Model;
    use base qw ( MT::Object MT::Revisable );

    __PACKAGE__->install_properties({
        'id'   => 'integer not null auto_increment',
        'text' => 'string(255) not null revisioned',
        # ...
    });

    1;

Using the MT::Revisable Interface

Then you get the methods in the Revisable interface on your model objects:

    sub load_my_revision {
        my ( $obj_id, $rev_id ) = @_;
        my $obj = My::Object::Model->load( $obj_id );
        my $rev = $obj->load_revision( { rev_number => $rev_id } );

        # ...
    }

Back