Changeset 3082 for trunk/lib/MT/Upgrade.pm
- Timestamp:
- 10/03/08 01:07:01 (14 months ago)
- Files:
-
- 1 modified
-
trunk/lib/MT/Upgrade.pm (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/MT/Upgrade.pm
r3013 r3082 166 166 $code = MT->handler_to_coderef($code); 167 167 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)) { 169 174 $param{offset} = $result; $result = 1; 170 175 $self->add_step($name, %param); … … 216 221 my $fn = \%MT::Upgrade::functions; 217 222 my @these_steps = @steps; 223 218 224 while (@these_steps) { 219 225 my $step = shift @these_steps; … … 225 231 $fn->{$b->[0]}->{priority} } @these_steps; 226 232 } 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; 227 238 } 228 239 return 1; … … 838 849 } 839 850 851 sub 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 840 938 sub core_update_records { 841 939 my $self = shift; … … 858 956 } 859 957 my $offset = $param{offset}; 958 my $count = $param{count}; 959 if (!$count) { 960 $count = $class->count; 961 } 962 return unless $count; 860 963 if ($offset) { 861 my $count = $class->count;862 return unless $count;863 964 $self->progress(sprintf("$msg (%d%%)", ($offset/$count*100)), $param{step}); 864 965 } else { … … 893 994 } 894 995 $code->($obj); 895 use Data::Dumper;896 996 $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)); 898 998 $continue = 1, last if time > $start + $MAX_TIME; 899 999 } 900 1000 } 901 1001 if ($continue) { 902 return $offset;1002 return { offset => $offset, count => $count }; 903 1003 } else { 904 1004 $self->progress("$msg (100%)", $param{step});
