Show
Ignore:
Timestamp:
10/03/08 01:07:01 (14 months ago)
Author:
bchoate
Message:

Merging fireball branch changes to-date to trunk: svn merge -r2974:3081 http://code.sixapart.com/svn/movabletype/branches/fireball .

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/lib/MT/Upgrade.pm

    r3013 r3082  
    166166        $code = MT->handler_to_coderef($code); 
    167167        my $result = $code->($self, %param, %update_params, step => $name); 
    168         if ((defined $result) && ($result > 1)) { 
     168        if (ref $result eq 'HASH') { 
     169            $param{$_} = $result->{$_} for keys %$result; 
     170            $result = 1; 
     171            $self->add_step($name, %param); 
     172        } 
     173        elsif ((defined $result) && ($result > 1)) { 
    169174            $param{offset} = $result; $result = 1; 
    170175            $self->add_step($name, %param); 
     
    216221        my $fn = \%MT::Upgrade::functions; 
    217222        my @these_steps = @steps; 
     223 
    218224        while (@these_steps) { 
    219225            my $step = shift @these_steps; 
     
    225231                                      $fn->{$b->[0]}->{priority} } @these_steps; 
    226232            } 
     233 
     234            # Reset the request to eliminate any caching that may be 
     235            # happening there (objects tend to cache into the request 
     236            # with the 'cache_property' method) 
     237            MT->request->reset; 
    227238        } 
    228239        return 1; 
     
    838849} 
    839850 
     851sub core_update_entry_counts { 
     852    my $self = shift; 
     853    my (%param) = @_; 
     854 
     855    my $class = MT->model('entry'); 
     856    return $self->error($self->translate_escape("Error loading class: [_1].", $param{type})) 
     857        unless $class; 
     858 
     859    my $msg = $self->translate_escape("Assigning entry comment and TrackBack counts..."); 
     860    my $offset = $param{offset} || 0; 
     861    my $count = $param{count}; 
     862    if (!$count) { 
     863        $count = $class->count({ class => '*' }); 
     864    } 
     865    return unless $count; 
     866    if ($offset) { 
     867        $self->progress(sprintf("$msg (%d%%)", ($offset/$count*100)), $param{step}); 
     868    } else { 
     869        $self->progress($msg, $param{step}); 
     870    } 
     871 
     872    my $continue = 0; 
     873    my $driver = $class->driver; 
     874 
     875    my $iter = $class->load_iter({ class => '*' }, { offset => $offset, limit => $MAX_ROWS+1 }); 
     876    my $start = time; 
     877    my ( %touched, %c, %tb ); 
     878    my $rows = 0; 
     879    while (my $e = $iter->()) { 
     880        $rows++; 
     881        $c{$e->id} = $e; 
     882        if (my $tb = $e->trackback) { 
     883            $tb{$tb->id} = $e; 
     884        } 
     885        $continue = 1, last if scalar $rows == $MAX_ROWS; 
     886    } 
     887    if ( $continue ) { 
     888        $iter->end; 
     889        $offset += $rows; 
     890    } 
     891 
     892    # now gather counts -- comments 
     893    if (my $grp_iter = MT::Comment->count_group_by({ 
     894        visible => 1, 
     895        entry_id => [ keys %c ], 
     896    }, { 
     897        group => ['entry_id'], 
     898    })) { 
     899        while (my ($count, $id) = $grp_iter->()) { 
     900            my $e = $c{$id} or next; 
     901            if ((!defined $e->comment_count) || (($e->comment_count || 0) != $count)) { 
     902                $e->comment_count($count); 
     903                $touched{$e->id} = $e; 
     904            } 
     905        } 
     906    } 
     907 
     908    # pings 
     909    if ( %tb ) { 
     910        if (my $grp_iter = MT::TBPing->count_group_by({ 
     911            visible => 1, 
     912            tb_id => [ keys %tb ], 
     913        }, { 
     914            group => ['tb_id'], 
     915        })) { 
     916            while (my ($count, $id) = $grp_iter->()) { 
     917                my $e = $tb{$id} or next; 
     918                if ((!defined $e->ping_count) || (($e->ping_count || 0) != $count)) { 
     919                    $e->ping_count($count); 
     920                    $touched{$e->id} = $e; 
     921                } 
     922            } 
     923        } 
     924    } 
     925 
     926    foreach my $e (values %touched) { 
     927        $e->save; 
     928    } 
     929 
     930    if ($continue) { 
     931        return { offset => $offset, count => $count }; 
     932    } else { 
     933        $self->progress("$msg (100%)", $param{step}); 
     934    } 
     935    1; 
     936} 
     937 
    840938sub core_update_records { 
    841939    my $self = shift; 
     
    858956    } 
    859957    my $offset = $param{offset}; 
     958    my $count = $param{count}; 
     959    if (!$count) { 
     960        $count = $class->count; 
     961    } 
     962    return unless $count; 
    860963    if ($offset) { 
    861         my $count = $class->count; 
    862         return unless $count; 
    863964        $self->progress(sprintf("$msg (%d%%)", ($offset/$count*100)), $param{step}); 
    864965    } else { 
     
    893994            } 
    894995            $code->($obj); 
    895             use Data::Dumper; 
    896996            $obj->save() 
    897                 or return $self->error($self->translate_escape("Error saving [_1] record # [_3]: [_2]... [_4].", $class_label, $obj->errstr, $obj->id, Dumper($obj))); 
     997                or return $self->error($self->translate_escape("Error saving [_1] record # [_3]: [_2]...", $class_label, $obj->errstr, $obj->id)); 
    898998            $continue = 1, last if time > $start + $MAX_TIME; 
    899999        } 
    9001000    } 
    9011001    if ($continue) { 
    902         return $offset; 
     1002        return { offset => $offset, count => $count }; 
    9031003    } else { 
    9041004        $self->progress("$msg (100%)", $param{step});