Changeset 109
- Timestamp:
- 07/16/05 02:51:35 (3 years ago)
- Files:
-
- mt-db-convert/trunk/mt-db-convert.cgi (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
mt-db-convert/trunk/mt-db-convert.cgi
r12 r109 3 3 # This is a derived work from the following: 4 4 # 5 # Copyright 2001-200 4Six Apart. This code cannot be redistributed without5 # Copyright 2001-2005 Six Apart. This code cannot be redistributed without 6 6 # permission from www.movabletype.org. 7 7 # 8 # $Id: mt-db2sql.cgi ,v 1.18 2004/09/29 21:33:03 ezra Exp$8 # $Id: mt-db2sql.cgi 12446 2005-05-25 21:32:39Z bchoate $ 9 9 use strict; 10 11 my $VERSION = '0.11'; 10 12 11 13 my($MT_DIR); … … 24 26 print <<HTML; 25 27 <html> 26 <head><title> MT-DB-CONVERT: Converting your MT data</title></head>28 <head><title>mt-db-convert $VERSION: Converting your MT data</title></head> 27 29 <body> 28 <p><strong> MT-DB-CONVERT: Coverting your MT data between multiple dbengines</strong></p>30 <p><strong>mt-db-convert $VERSION: Coverting your MT data between DB engines</strong></p> 29 31 HTML 30 32 … … 47 49 48 50 my (%src, %dst); 49 50 for my $dbspec (@DBSPECS) { 51 $src{$dbspec} = $q->param('src_' . $dbspec) || ''; 52 $dst{$dbspec} = $q->param('dst_' . $dbspec) || ''; 51 foreach (@DBSPECS) { 52 $src{$_} = $q->param('src_' . $_) || ''; 53 $dst{$_} = $q->param('dst_' . $_) || ''; 53 54 } 54 55 … … 57 58 !$dst{ObjectDriver} || ($dst{ObjectDriver} eq 'DBM' && $dst{DataSource})) { 58 59 59 for my $dbspec (@DBSPECS) { 60 $src{$dbspec} ||= $cfg->$dbspec(); 61 } 60 $src{$_} ||= $cfg->$_() foreach (@DBSPECS); 62 61 63 62 my %src_selected = ('DBM' => '', 'DBI::mysql' => '', 'DBI::postgres' => '', 'DBI::sqlite' => ''); … … 66 65 $dst_selected{$dst{ObjectDriver}} = 'selected' if $dst{ObjectDriver}; 67 66 67 my $script_name = ($0 =~ m$!) ? $1 : 'mt-db-convert.cgi'; 68 68 69 print <<HTML; 69 70 <p>Please fill the following:</p> 70 71 71 <form method="post" action="$0"> 72 <fieldset style="float:left; width:40%"> 72 <form method="post" action="$script_name"> 73 <style>fieldset { width: 40%; float: left; }</style> 74 <fieldset> 73 75 <legend>Source DB Configuration</legend> 74 76 <dl> 75 <dt>DataSource: ( mandatory if usingBerkeleyDB)</dt>77 <dt>DataSource: (Required for BerkeleyDB)</dt> 76 78 <dd><input name="src_DataSource" type="text" value="$src{DataSource}" /></dd> 77 79 <dt>ObjectDriver:</dt> … … 94 96 </fieldset> 95 97 96 <fieldset style="float:left; width:40%">98 <fieldset> 97 99 <legend>Destination DB Configuration</legend> 98 100 <dl> 99 <dt>DataSource: ( mandatory if usingBerkeleyDB)</dt>101 <dt>DataSource: (Required for BerkeleyDB)</dt> 100 102 <dd><input name="dst_DataSource" type="text" value="$dst{DataSource}" /></dd> 101 103 <dt>ObjectDriver:</dt> … … 120 122 <p style="clear:both;"><input type="submit" value="Convert" /></p> 121 123 </form> 122 123 124 HTML 124 125 … … 132 133 if ($type) { 133 134 # set dst driver 134 for my $dbspec (@DBSPECS) { 135 $cfg->set($dbspec, $dst{$dbspec}); 136 } 135 $cfg->set($_, $dst{$_}) foreach (@DBSPECS); 137 136 MT::Object->set_driver($dst{ObjectDriver}) 138 137 or die MT::ObjectDriver->errstr; … … 162 161 163 162 # set source driver 164 for my $dbspec (@DBSPECS) { 165 $cfg->set($dbspec, $src{$dbspec}); 166 } 163 $cfg->set($_, $src{$_}) foreach (@DBSPECS); 167 164 MT::Object->set_driver($src{ObjectDriver}); 168 165 … … 171 168 172 169 my %names; 170 my %cat_parent; 173 171 174 172 # set dst driver 175 for my $dbspec (@DBSPECS) { 176 $cfg->set($dbspec, $dst{$dbspec}); 177 } 173 $cfg->set($_, $dst{$_}) foreach (@DBSPECS); 178 174 MT::Object->set_driver($dst{ObjectDriver}); 179 175 MT::Object->driver->{dbh}->begin_work if $type eq 'sqlite'; … … 214 210 print "'; renaming to '" . $obj->label . "'\n"; 215 211 } 212 # save the parent value for assignment at the end 213 if ($obj->parent) { 214 $cat_parent{$obj->id} = $obj->parent; 215 $obj->parent(0); 216 } 216 217 } elsif ($class eq 'MT::Trackback') { 217 218 $obj->entry_id(0) unless defined $obj->entry_id; … … 222 223 $obj->allow_comments(0) 223 224 if defined $obj->allow_comments && $obj->allow_comments eq ''; 225 } elsif ($class eq 'MT::Blog') { 226 $obj->touch(); # for updating children_modified_on field 224 227 } 225 228 … … 230 233 $i % 10 or print " "; 231 234 $i % 100 or print "<br />\n"; 232 } 235 } 236 237 # fix up the category parents 238 foreach my $id (keys %cat_parent) { 239 my $cat = MT::Category->load($id); 240 $cat->parent( $cat_parent{$id} ); 241 $cat->save; 242 } 243 233 244 print "</p>\n\n"; 234 245 MT::Object->driver->{dbh}->commit if $type eq 'sqlite'; … … 260 271 } 261 272 262 print <<HTML; 263 </body> 264 </html> 265 HTML 273 print "</body>\n</html>\n";
