1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
# Movable Type (r) Open Source (C) 2001-2012 Six Apart, Ltd.
# This program is distributed under the terms of the
# GNU General Public License, version 2.
#
# $Id$
package MT::Upgrade::v1;
use strict;
sub upgrade_functions {
return {
# < 2.0
'core_create_placements' => {
version_limit => 2.0,
priority => 9.1,
updater => {
type => 'entry',
label => 'Creating entry category placements...',
condition => sub { $_[0]->category_id },
code => sub {
require MT::Placement;
my $entry = shift;
my $existing = MT::Placement->load(
{ entry_id => $entry->id,
category_id => $entry->category_id
}
);
if ( !$existing ) {
my $place = MT::Placement->new;
$place->entry_id( $entry->id );
$place->blog_id( $entry->blog_id );
$place->category_id( $entry->category_id );
$place->is_primary(1);
$place->save;
}
$entry->category_id(0);
},
},
},
'core_create_template_maps' => {
version_limit => 2.0,
code => \&core_create_template_maps,
priority => 9.1,
},
};
}
sub core_create_template_maps {
my $self = shift;
my (%param) = @_;
my $offset = $param{offset};
require MT::Template;
require MT::TemplateMap;
require MT::Blog;
my $msg = $self->translate_escape("Creating template maps...");
if ($offset) {
my $count = MT::Template->count;
return 1 unless $count;
$self->progress( sprintf( "$msg (%d%%)", ( $offset / $count * 100 ) ),
1 );
}
else {
$self->progress( $msg, 1 );
}
my $iter = MT::Template->load_iter( undef,
{ offset => $offset, limit => $self->max_rows + 1 } );
my $start = time;
my $continue = 0;
my $count = 0;
while ( my $tmpl = $iter->() ) {
$offset++;
my $blog = MT::Blog->load( $tmpl->blog_id );
my (@at);
if ( $tmpl->type eq 'archive' ) {
@at = qw( Daily Weekly Monthly );
}
elsif ( $tmpl->type eq 'category' ) {
@at = ('Category');
}
elsif ( $tmpl->type eq 'page' ) {
@at = ('Page');
}
elsif ( $tmpl->type eq 'individual' ) {
@at = ('Individual');
}
else {
next;
}
for my $at (@at) {
my $meth = 'archive_tmpl_' . lc($at);
my $file_tmpl = $blog->$meth();
my $existing = MT::TemplateMap->load(
{ blog_id => $blog->id,
archive_type => $at,
template_id => $tmpl->id
}
);
if ( !$existing ) {
my $map = MT::TemplateMap->new;
if ($file_tmpl) {
$self->progress(
$self->translate_escape(
"Mapping template ID [_1] to [_2] ([_3]).",
$tmpl->id, $at, $file_tmpl
)
);
$map->file_template($file_tmpl);
}
else {
$self->progress(
$self->translate_escape(
"Mapping template ID [_1] to [_2].", $tmpl->id,
$at
)
);
}
$map->archive_type($at);
$map->is_preferred(1);
$map->template_id( $tmpl->id );
$map->blog_id( $tmpl->blog_id );
$map->save
or return $self->error(
$self->translate_escape(
"Error saving record: [_1].",
$map->errstr
)
);
}
}
$count++;
$continue = 1, last if $count == $self->max_rows;
$continue = 1, last if time > $start + $self->max_time;
}
if ($continue) {
$iter->end;
return $offset;
}
else {
$self->progress( "$msg (100%)", 1 );
}
1;
}
1;
|