| 352 | | updater => { |
| 353 | | type => 'entry', |
| 354 | | label => 'Assigning entry comment and TrackBack counts...', |
| 355 | | condition => sub { |
| 356 | | require MT::Comment; |
| 357 | | my $comment_count = MT::Comment->count( |
| 358 | | { |
| 359 | | entry_id => $_[0]->id, |
| 360 | | visible => 1, |
| 361 | | } |
| 362 | | ); |
| 363 | | $_[0]->comment_count($comment_count); |
| 364 | | require MT::Trackback; |
| 365 | | require MT::TBPing; |
| 366 | | my $tb = MT::Trackback->load( { entry_id => $_[0]->id } ); |
| 367 | | my $ping_count; |
| 368 | | if ($tb) { |
| 369 | | my $ping_count = MT::TBPing->count( |
| 370 | | { |
| 371 | | tb_id => $tb->id, |
| 372 | | visible => 1, |
| 373 | | } |
| 374 | | ); |
| 375 | | $_[0]->ping_count($ping_count); |
| 376 | | } |
| 377 | | ( $comment_count || $ping_count ); |
| 378 | | }, |
| 379 | | # only count once and set it, so code do nothing. |
| 380 | | # it doesn't have the unnecessary save. |
| 381 | | code => sub { 1; }, |
| 382 | | }, |
| | 352 | code => \&core_update_entry_counts, |
| 492 | | }, |
| 493 | | }, |
| 494 | | }, |
| 495 | | 'core_assign_all_permisssions_blog_admin' => { |
| 496 | | version_limit => 4.0063, |
| 497 | | priority => 3.4, |
| 498 | | updater => { |
| 499 | | type => 'permission', |
| 500 | | label => 'Assigning all permissions to blog administrator...', |
| 501 | | condition => sub { |
| 502 | | $_[0]->can_administer_blog && $_[0]->blog_id; |
| 503 | | }, |
| 504 | | code => sub { |
| 505 | | my ($perm) = shift; |
| 506 | | $perm->set_full_permissions; |
| 507 | | }, |
| 508 | | }, |
| 509 | | }, |
| 510 | | 'core_recover_sysadmin_permissions' => { |
| 511 | | version_limit => 4.0066, |
| 512 | | priority => 3.5, |
| 513 | | updater => { |
| 514 | | type => 'permission', |
| 515 | | label => 'Recover permissions of system administrators...', |
| 516 | | condition => sub { |
| 517 | | !$_[0]->blog_id && !$_[0]->has('administer') && $_[0]->can_administer_blog; |
| 518 | | }, |
| 519 | | code => sub { |
| 520 | | my ($perm) = shift; |
| 521 | | $perm->set_permissions('system'); |
| | 1132 | sub core_update_entry_counts { |
| | 1133 | my $self = shift; |
| | 1134 | my (%param) = @_; |
| | 1135 | |
| | 1136 | my $class = MT->model('entry'); |
| | 1137 | return $self->error($self->translate_escape("Error loading class: [_1].", $param{type})) |
| | 1138 | unless $class; |
| | 1139 | |
| | 1140 | my $msg = $self->translate_escape("Assigning entry comment and TrackBack counts..."); |
| | 1141 | my $offset = $param{offset} || 0; |
| | 1142 | my $count = $param{count}; |
| | 1143 | if (!$count) { |
| | 1144 | $count = $class->count({ class => '*' }); |
| | 1145 | } |
| | 1146 | return unless $count; |
| | 1147 | if ($offset) { |
| | 1148 | $self->progress(sprintf("$msg (%d%%)", ($offset/$count*100)), $param{step}); |
| | 1149 | } else { |
| | 1150 | $self->progress($msg, $param{step}); |
| | 1151 | } |
| | 1152 | |
| | 1153 | my $continue = 0; |
| | 1154 | my $driver = $class->driver; |
| | 1155 | |
| | 1156 | my $iter = $class->load_iter({ class => '*' }, { offset => $offset, limit => $MAX_ROWS+1 }); |
| | 1157 | my $start = time; |
| | 1158 | my ( %touched, %c, %tb ); |
| | 1159 | my $rows = 0; |
| | 1160 | while (my $e = $iter->()) { |
| | 1161 | $rows++; |
| | 1162 | $c{$e->id} = $e; |
| | 1163 | if (my $tb = $e->trackback) { |
| | 1164 | $tb{$tb->id} = $e; |
| | 1165 | } |
| | 1166 | $continue = 1, last if scalar $rows == $MAX_ROWS; |
| | 1167 | } |
| | 1168 | if ( $continue ) { |
| | 1169 | $iter->end; |
| | 1170 | $offset += $rows; |
| | 1171 | } |
| | 1172 | |
| | 1173 | # now gather counts -- comments |
| | 1174 | if (my $grp_iter = MT::Comment->count_group_by({ |
| | 1175 | visible => 1, |
| | 1176 | entry_id => [ keys %c ], |
| | 1177 | }, { |
| | 1178 | group => ['entry_id'], |
| | 1179 | })) { |
| | 1180 | while (my ($count, $id) = $grp_iter->()) { |
| | 1181 | my $e = $c{$id} or next; |
| | 1182 | if ((!defined $e->comment_count) || (($e->comment_count || 0) != $count)) { |
| | 1183 | $e->comment_count($count); |
| | 1184 | $touched{$e->id} = $e; |
| | 1185 | } |
| | 1186 | } |
| | 1187 | } |
| | 1188 | |
| | 1189 | # pings |
| | 1190 | if ( %tb ) { |
| | 1191 | if (my $grp_iter = MT::TBPing->count_group_by({ |
| | 1192 | visible => 1, |
| | 1193 | tb_id => [ keys %tb ], |
| | 1194 | }, { |
| | 1195 | group => ['tb_id'], |
| | 1196 | })) { |
| | 1197 | while (my ($count, $id) = $grp_iter->()) { |
| | 1198 | my $e = $tb{$id} or next; |
| | 1199 | if ((!defined $e->ping_count) || (($e->ping_count || 0) != $count)) { |
| | 1200 | $e->ping_count($count); |
| | 1201 | $touched{$e->id} = $e; |
| | 1202 | } |
| | 1203 | } |
| | 1204 | } |
| | 1205 | } |
| | 1206 | |
| | 1207 | foreach my $e (values %touched) { |
| | 1208 | $e->save; |
| | 1209 | } |
| | 1210 | |
| | 1211 | if ($continue) { |
| | 1212 | return { offset => $offset, count => $count }; |
| | 1213 | } else { |
| | 1214 | $self->progress("$msg (100%)", $param{step}); |
| | 1215 | } |
| | 1216 | 1; |
| | 1217 | } |
| | 1218 | |