| 54 | | !$dest{ObjectDriver} || ($dest{ObjectDriver} eq 'DBM' && $dest{DataSource})) { |
|---|
| 55 | | |
|---|
| 56 | | for my $dbspec (@DBSPECS) { |
|---|
| 57 | | $src{$dbspec} ||= $cfg->$dbspec(); |
|---|
| 58 | | } |
|---|
| 59 | | |
|---|
| 60 | | my %src_selected = ('DBM' => '', 'DBI::mysql' => '', 'DBI::postgres' => '', 'DBI::sqlite' => ''); |
|---|
| 61 | | my %dest_selected = ('DBM' => '', 'DBI::mysql' => '', 'DBI::postgres' => '', 'DBI::sqlite' => ''); |
|---|
| 62 | | $src_selected{$src{ObjectDriver}} = 'selected' if $src{ObjectDriver}; |
|---|
| 63 | | $dest_selected{$dest{ObjectDriver}} = 'selected' if $dest{ObjectDriver}; |
|---|
| 64 | | print <<HTML; |
|---|
| | 57 | !$dst{ObjectDriver} || ($dst{ObjectDriver} eq 'DBM' && $dst{DataSource})) { |
|---|
| | 58 | |
|---|
| | 59 | for my $dbspec (@DBSPECS) { |
|---|
| | 60 | $src{$dbspec} ||= $cfg->$dbspec(); |
|---|
| | 61 | } |
|---|
| | 62 | |
|---|
| | 63 | my %src_selected = ('DBM' => '', 'DBI::mysql' => '', 'DBI::postgres' => '', 'DBI::sqlite' => ''); |
|---|
| | 64 | my %dst_selected = ('DBM' => '', 'DBI::mysql' => '', 'DBI::postgres' => '', 'DBI::sqlite' => ''); |
|---|
| | 65 | $src_selected{$src{ObjectDriver}} = 'selected' if $src{ObjectDriver}; |
|---|
| | 66 | $dst_selected{$dst{ObjectDriver}} = 'selected' if $dst{ObjectDriver}; |
|---|
| | 67 | |
|---|
| | 68 | print <<HTML; |
|---|
| 100 | | <option value="DBM" $dest_selected{'DBM'}>BerkeleyDB</option> |
|---|
| 101 | | <option value="DBI::mysql" $dest_selected{'DBI::mysql'}>MySQL</option> |
|---|
| 102 | | <option value="DBI::postgres" $dest_selected{'DBI::postgres'}>PostgreSQL</option> |
|---|
| 103 | | <option value="DBI::sqlite" $dest_selected{'DBI::sqlite'}>SQLite</option> |
|---|
| | 104 | <option value="DBM" $dst_selected{'DBM'}>BerkeleyDB</option> |
|---|
| | 105 | <option value="DBI::mysql" $dst_selected{'DBI::mysql'}>MySQL</option> |
|---|
| | 106 | <option value="DBI::postgres" $dst_selected{'DBI::postgres'}>PostgreSQL</option> |
|---|
| | 107 | <option value="DBI::sqlite" $dst_selected{'DBI::sqlite'}>SQLite</option> |
|---|
| 131 | | # set dest driver |
|---|
| 132 | | for my $dbspec (@DBSPECS) { |
|---|
| 133 | | $cfg->set($dbspec, $dest{$dbspec}); |
|---|
| 134 | | } |
|---|
| 135 | | MT::Object->set_driver($dest{ObjectDriver}) |
|---|
| 136 | | or die MT::ObjectDriver->errstr; |
|---|
| 137 | | my $dbh = MT::Object->driver->{dbh}; |
|---|
| 138 | | my $schema = File::Spec->catfile($MT_DIR, 'schemas', $type . '.dump'); |
|---|
| 139 | | open FH, $schema or die "Can't open schema file '$schema': $!"; |
|---|
| 140 | | my $ddl; |
|---|
| 141 | | { local $/; $ddl = <FH> } |
|---|
| 142 | | close FH; |
|---|
| 143 | | my @stmts = split /;/, $ddl; |
|---|
| 144 | | print "Loading database schema...\n\n"; |
|---|
| 145 | | for my $stmt (@stmts) { |
|---|
| | 133 | # set dst driver |
|---|
| | 134 | for my $dbspec (@DBSPECS) { |
|---|
| | 135 | $cfg->set($dbspec, $dst{$dbspec}); |
|---|
| | 136 | } |
|---|
| | 137 | MT::Object->set_driver($dst{ObjectDriver}) |
|---|
| | 138 | or die MT::ObjectDriver->errstr; |
|---|
| | 139 | my $dbh = MT::Object->driver->{dbh}; |
|---|
| | 140 | $dbh->begin_work if $type eq 'sqlite'; |
|---|
| | 141 | my $schema = File::Spec->catfile($MT_DIR, 'schemas', $type . '.dump'); |
|---|
| | 142 | open FH, $schema or die "Can't open schema file '$schema': $!"; |
|---|
| | 143 | my $ddl; |
|---|
| | 144 | { local $/; $ddl = <FH> } |
|---|
| | 145 | close FH; |
|---|
| | 146 | my @stmts = split /;/, $ddl; |
|---|
| | 147 | print "<p>Loading database schema...</p>\n\n"; |
|---|
| | 148 | for my $stmt (@stmts) { |
|---|
| 157 | | print "<p>Dumping $class:<br />\n"; |
|---|
| 158 | | |
|---|
| 159 | | # set source driver |
|---|
| 160 | | for my $dbspec (@DBSPECS) { |
|---|
| 161 | | $cfg->set($dbspec, $src{$dbspec}); |
|---|
| 162 | | } |
|---|
| 163 | | MT::Object->set_driver($src{ObjectDriver}); |
|---|
| 164 | | |
|---|
| 165 | | eval "use $class"; |
|---|
| 166 | | my $iter = $class->load_iter; |
|---|
| 167 | | |
|---|
| 168 | | my %names; |
|---|
| 169 | | |
|---|
| 170 | | # set dest driver |
|---|
| 171 | | for my $dbspec (@DBSPECS) { |
|---|
| 172 | | $cfg->set($dbspec, $dest{$dbspec}); |
|---|
| 173 | | } |
|---|
| 174 | | MT::Object->set_driver($dest{ObjectDriver}); |
|---|
| 175 | | |
|---|
| 176 | | my $i = 0; |
|---|
| 177 | | while (my $o = $iter->()) { |
|---|
| 178 | | $ids{$class} = $o->id |
|---|
| 179 | | if !$ids{$class} || $o->id > $ids{$class}; |
|---|
| 180 | | ## Look for duplicate template, category, and author names, |
|---|
| 181 | | ## because we have uniqueness constraints in the DB. |
|---|
| 182 | | if ($class eq 'MT::Template') { |
|---|
| 183 | | my $key = lc($o->name) . $o->blog_id; |
|---|
| 184 | | if ($names{$class}{$key}++) { |
|---|
| 185 | | print " Found duplicate template name '" . |
|---|
| 186 | | $o->name; |
|---|
| 187 | | $o->name($o->name . ' ' . $names{$class}{$key}); |
|---|
| 188 | | print "'; renaming to '" . $o->name . "'\n"; |
|---|
| 189 | | } |
|---|
| 190 | | ## Touch the text column to make sure we read in |
|---|
| 191 | | ## any linked templates. |
|---|
| 192 | | my $text = $o->text; |
|---|
| 193 | | } elsif ($class eq 'MT::Author') { |
|---|
| 194 | | my $key = lc($o->name); |
|---|
| 195 | | if ($names{$class . $o->type}{$key}++) { |
|---|
| 196 | | print " Found duplicate author name '" . |
|---|
| 197 | | $o->name; |
|---|
| 198 | | $o->name($o->name . ' ' . $names{$class}{$key}); |
|---|
| 199 | | print "'; renaming to '" . $o->name . "'\n"; |
|---|
| 200 | | } |
|---|
| 201 | | $o->email('') unless defined $o->email; |
|---|
| 202 | | $o->set_password('') unless defined $o->password; |
|---|
| 203 | | } elsif ($class eq 'MT::Category') { |
|---|
| 204 | | my $key = lc($o->label) . $o->blog_id; |
|---|
| 205 | | if ($names{$class}{$key}++) { |
|---|
| 206 | | print " Found duplicate category label '" . |
|---|
| 207 | | $o->label; |
|---|
| 208 | | $o->label($o->label . ' ' . $names{$class}{$key}); |
|---|
| 209 | | print "'; renaming to '" . $o->label . "'\n"; |
|---|
| 210 | | } |
|---|
| 211 | | } elsif ($class eq 'MT::Trackback') { |
|---|
| 212 | | $o->entry_id(0) unless defined $o->entry_id; |
|---|
| 213 | | $o->category_id(0) unless defined $o->category_id; |
|---|
| 214 | | } elsif ($class eq 'MT::Entry') { |
|---|
| 215 | | $o->allow_pings(0) |
|---|
| 216 | | if defined $o->allow_pings && $o->allow_pings eq ''; |
|---|
| 217 | | $o->allow_comments(0) |
|---|
| 218 | | if defined $o->allow_comments && $o->allow_comments eq ''; |
|---|
| | 161 | print "<p>Dumping $class:<br />\n"; |
|---|
| | 162 | |
|---|
| | 163 | # set source driver |
|---|
| | 164 | for my $dbspec (@DBSPECS) { |
|---|
| | 165 | $cfg->set($dbspec, $src{$dbspec}); |
|---|
| 220 | | |
|---|
| 221 | | $i++; |
|---|
| 222 | | print $o->save ? "." : "!<br />" . $o->errstr; |
|---|
| 223 | | $i % 10 or print " "; |
|---|
| 224 | | $i % 100 or print "<br />"; |
|---|
| 225 | | } |
|---|
| 226 | | print "</p>\n\n"; |
|---|
| | 167 | MT::Object->set_driver($src{ObjectDriver}); |
|---|
| | 168 | |
|---|
| | 169 | eval "use $class"; |
|---|
| | 170 | my $iter = $class->load_iter; |
|---|
| | 171 | |
|---|
| | 172 | my %names; |
|---|
| | 173 | |
|---|
| | 174 | # set dst driver |
|---|
| | 175 | for my $dbspec (@DBSPECS) { |
|---|
| | 176 | $cfg->set($dbspec, $dst{$dbspec}); |
|---|
| | 177 | } |
|---|
| | 178 | MT::Object->set_driver($dst{ObjectDriver}); |
|---|
| | 179 | MT::Object->driver->{dbh}->begin_work if $type eq 'sqlite'; |
|---|
| | 180 | |
|---|
| | 181 | my $i = 0; |
|---|
| | 182 | while (my $obj = $iter->()) { |
|---|
| | 183 | $ids{$class} = $obj->id |
|---|
| | 184 | if !$ids{$class} || $obj->id > $ids{$class}; |
|---|
| | 185 | ## Look for duplicate template, category, and author names, |
|---|
| | 186 | ## because we have uniqueness constraints in the DB. |
|---|
| | 187 | if ($class eq 'MT::Template') { |
|---|
| | 188 | my $key = lc($obj->name) . $obj->blog_id; |
|---|
| | 189 | if ($names{$class}{$key}++) { |
|---|
| | 190 | print " Found duplicate template name '" . |
|---|
| | 191 | $obj->name; |
|---|
| | 192 | $obj->name($obj->name . ' ' . $names{$class}{$key}); |
|---|
| | 193 | print "'; renaming to '" . $obj->name . "'\n"; |
|---|
| | 194 | } |
|---|
| | 195 | ## Touch the text column to make sure we read in |
|---|
| | 196 | ## any linked templates. |
|---|
| | 197 | my $text = $obj->text; |
|---|
| | 198 | } elsif ($class eq 'MT::Author') { |
|---|
| | 199 | my $key = lc($obj->name); |
|---|
| | 200 | if ($names{$class . $obj->type}{$key}++) { |
|---|
| | 201 | print " Found duplicate author name '" . |
|---|
| | 202 | $obj->name; |
|---|
| | 203 | $obj->name($obj->name . ' ' . $names{$class}{$key}); |
|---|
| | 204 | print "'; renaming to '" . $obj->name . "'\n"; |
|---|
| | 205 | } |
|---|
| | 206 | $obj->email('') unless defined $obj->email; |
|---|
| | 207 | $obj->set_password('') unless defined $obj->password; |
|---|
| | 208 | } elsif ($class eq 'MT::Category') { |
|---|
| | 209 | my $key = lc($obj->label) . $obj->blog_id; |
|---|
| | 210 | if ($names{$class}{$key}++) { |
|---|
| | 211 | print " Found duplicate category label '" . |
|---|
| | 212 | $obj->label; |
|---|
| | 213 | $obj->label($obj->label . ' ' . $names{$class}{$key}); |
|---|
| | 214 | print "'; renaming to '" . $obj->label . "'\n"; |
|---|
| | 215 | } |
|---|
| | 216 | } elsif ($class eq 'MT::Trackback') { |
|---|
| | 217 | $obj->entry_id(0) unless defined $obj->entry_id; |
|---|
| | 218 | $obj->category_id(0) unless defined $obj->category_id; |
|---|
| | 219 | } elsif ($class eq 'MT::Entry') { |
|---|
| | 220 | $obj->allow_pings(0) |
|---|
| | 221 | if defined $obj->allow_pings && $obj->allow_pings eq ''; |
|---|
| | 222 | $obj->allow_comments(0) |
|---|
| | 223 | if defined $obj->allow_comments && $obj->allow_comments eq ''; |
|---|
| | 224 | } |
|---|
| | 225 | |
|---|
| | 226 | $i++; |
|---|
| | 227 | $obj->save |
|---|
| | 228 | or die $obj->errstr; |
|---|
| | 229 | print "."; |
|---|
| | 230 | $i % 10 or print " "; |
|---|
| | 231 | $i % 100 or print "<br />\n"; |
|---|
| | 232 | } |
|---|
| | 233 | print "</p>\n\n"; |
|---|
| | 234 | MT::Object->driver->{dbh}->commit if $type eq 'sqlite'; |
|---|