Changeset 2847

Show
Ignore:
Timestamp:
07/28/08 03:33:20 (4 months ago)
Author:
arvind
Message:

* All user-editable entry fields are now revisioned (status, comments, pings etc.)
* Collision checking for input from MT::App::CMS

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/feature-revision-histories/lib/MT/Entry.pm

    r2790 r2847  
    3131            type        => 'smallint', 
    3232            not_null    => 1, 
    33             label       => 'Status' 
     33            label       => 'Status', 
     34            revisioned  => 1 
    3435        }, 
    3536        'author_id' => { 
    3637            type        => 'integer', 
    3738            not_null    => 1, 
    38             label       => 'Author' 
     39            label       => 'Author', 
     40            revisioned  => 1 
    3941        }, 
    4042        'allow_comments' => { 
    4143            type        => 'boolean', 
    42             label       => 'Accept Comments' 
     44            label       => 'Accept Comments', 
     45            revisioned  => 1 
    4346        }, 
    4447        'title' => { 
     
    7376        'allow_pings' => { 
    7477            type        => 'boolean', 
    75             label       => 'Accept Trackbacks' 
     78            label       => 'Accept Trackbacks', 
     79            revisioned  => 1 
    7680        }, 
    7781        'keywords' => { 
  • branches/feature-revision-histories/lib/MT/Revisable.pm

    r2831 r2847  
    1010 
    1111use strict; 
     12 
     13our $MAX_REVISIONS = 20; 
    1214 
    1315sub install_properties { 
     
    2426    $class->install_column('current_revision'); 
    2527    $props->{defaults}{current_revision} = 0; 
     28     
     29    # To track how many revisions to store for each object, add 
     30    # a meta column in MT::Blog 
     31    # my $blog_class = MT->model('blog'); 
     32    # $blog_class->install_meta({ column_defs => { 
     33    #     "max_${datasource}_revision" => 'integer' 
     34    # }}); 
    2635     
    2736    # Callbacks: clean list of changed columns to only 
     
    141150    $obj->gather_changed_cols($orig); 
    142151     
     152    # Collision Checking 
     153    my $changed_cols = $obj->{changed_revisioned_cols}; 
     154    my $modified_by = $orig->author; 
     155     
     156    if(scalar @$changed_cols) { 
     157        if($app->isa('MT::App::CMS')  
     158                && $app->param('current_revision') != $orig->current_revision) { 
     159            my %param = ( 
     160                collision   => 1, 
     161                return_args => $app->param('return_args'), 
     162                modified_by_nickname => $modified_by->nickname 
     163            ); 
     164            return $app->forward( "view", \%param ); 
     165        } 
     166    }     
     167     
    143168    $obj->increment_revision($orig); # Added here for consistency 
    144169} 
     
    174199sub pack_revision { 
    175200    my $obj = shift; 
    176     my $values; 
    177201    my $values = $obj->column_values; 
    178202 
     
    292316} 
    293317 
     318sub diff_object { 
     319    my $obj_a = shift; 
     320    my ($obj_b, $diff_args) = @_; 
     321     
     322    return $obj_a->error(MT->translate("There aren't the same types of objects, expecting two [_1]", 
     323                                            lc $obj_a->class_label_plural)) 
     324        if ref $obj_a ne ref $obj_b; 
     325         
     326    my %diff;     
     327    my $cols = $obj_a->revisioned_columns(); 
     328    foreach my $col (@$cols) { 
     329        $diff{$col} = _diff_string($obj_a->$col, $obj_b->$col, $diff_args); 
     330    }     
     331 
     332    return \%diff;     
     333} 
     334 
    294335sub diff_revision { 
    295336    my $obj = shift; 
     
    310351     
    311352    return $obj->error(MT->translate("Did not get two [_1]", lc $obj->class_label_plural)) 
    312         if ref $obj_a ne 'MT::Entry' || ref $obj_b ne 'MT::Entry'
     353        if ref $obj_a ne ref $obj || ref $obj_b ne ref $obj
    313354     
    314355    my %diff;     
     
    337378            push @result, { 
    338379                flag => $diff->[0], 
    339                 value => ($diff->[0] eq '+') ? $diff->[2] : $diff->[1] 
     380                text => ($diff->[0] eq '+') ? $diff->[2] : $diff->[1] 
    340381            }; 
    341382        } else { 
    342383            push @result, { 
    343384                flag => '-', 
    344                 value => $diff->[1] 
     385                text => $diff->[1] 
    345386            }; 
    346387            push @result, { 
    347388                flag => '+', 
    348                 value => $diff->[2] 
     389                text => $diff->[2] 
    349390            }; 
    350391        }