| 24 | | =start |
|---|
| 25 | | for my $blog (MT::Blog->load) { |
|---|
| 26 | | my @ts = offset_time_list(time, $blog); |
|---|
| 27 | | my $now = sprintf "%04d%02d%02d%02d%02d%02d", |
|---|
| 28 | | $ts[5]+1900, $ts[4]+1, @ts[3,2,1,0]; |
|---|
| 29 | | print "Publishing entries for blog ", $blog->id, " up to ", $now, "\n" |
|---|
| 30 | | if VERBOSE; |
|---|
| 31 | | my $iter = MT::Entry->load_iter({blog_id => $blog->id, |
|---|
| 32 | | status => FUTURE}, |
|---|
| 33 | | {'sort' => 'created_on', |
|---|
| 34 | | direction => 'descend'}); |
|---|
| 35 | | my @queue; |
|---|
| 36 | | while (my $entry = $iter->()) { |
|---|
| 37 | | push @queue, $entry->id if $entry->created_on le $now; |
|---|
| 38 | | } |
|---|
| 39 | | |
|---|
| 40 | | my $changed = 0; |
|---|
| 41 | | my $total_changed = 0; |
|---|
| 42 | | my @results; |
|---|
| 43 | | my %rebuild_queue; |
|---|
| 44 | | my %ping_queue; |
|---|
| 45 | | foreach my $entry_id (@queue) { |
|---|
| 46 | | my $entry = MT::Entry->load($entry_id); |
|---|
| 47 | | print $entry->id, "\n" if VERBOSE; |
|---|
| 48 | | $entry->status(RELEASE); |
|---|
| 49 | | $entry->save |
|---|
| 50 | | or die $entry->errstr; |
|---|
| 51 | | |
|---|
| 52 | | $rebuild_queue{$entry->id} = $entry; |
|---|
| 53 | | $ping_queue{$entry->id} = 1; |
|---|
| 54 | | my $n = $entry->next(1); |
|---|
| 55 | | $rebuild_queue{$n->id} = $n if $n; |
|---|
| 56 | | my $p = $entry->previous(1); |
|---|
| 57 | | $rebuild_queue{$p->id} = $p if $p; |
|---|
| 58 | | $changed++; |
|---|
| 59 | | $total_changed++; |
|---|
| 60 | | } |
|---|
| 61 | | if ($changed) { |
|---|
| 62 | | MT::Util::start_background_task(sub { |
|---|
| 63 | | my $rebuilt; |
|---|
| 64 | | foreach my $id (keys %rebuild_queue) { |
|---|
| 65 | | my $entry = $rebuild_queue{$id}; |
|---|
| 66 | | $mt->rebuild_entry( Entry => $entry, Blog => $blog ) |
|---|
| 67 | | or die $mt->errstr; |
|---|
| 68 | | if ($ping_queue{$id}) { |
|---|
| 69 | | $mt->ping_and_save( Entry => $entry, Blog => $blog ) |
|---|
| 70 | | or not VERBOSE or print "Ping error: ", $mt->errstr, "\n"; |
|---|
| 71 | | } |
|---|
| 72 | | $rebuilt++; |
|---|
| 73 | | } |
|---|
| 74 | | print "Rebuilt $rebuilt entries\n" if VERBOSE; |
|---|
| 75 | | }); |
|---|
| 76 | | $mt->rebuild_indexes( Blog => $blog ) |
|---|
| 77 | | or die $mt->errstr; |
|---|
| 78 | | } |
|---|
| 79 | | print "$changed updated in blog ", $blog->id, "\n" if VERBOSE; |
|---|
| 80 | | } |
|---|
| 81 | | =cut |
|---|
| 82 | | |
|---|