Changeset 109

Show
Ignore:
Timestamp:
07/16/05 02:51:35 (3 years ago)
Author:
ogawa
Message:

Fix for subcategory bug.
Fix for stopping warnings for saving MT::Blog objects.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • mt-db-convert/trunk/mt-db-convert.cgi

    r12 r109  
    33# This is a derived work from the following: 
    44# 
    5 # Copyright 2001-2004 Six Apart. This code cannot be redistributed without 
     5# Copyright 2001-2005 Six Apart. This code cannot be redistributed without 
    66# permission from www.movabletype.org. 
    77# 
    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
    99use strict; 
     10 
     11my $VERSION = '0.11'; 
    1012 
    1113my($MT_DIR); 
     
    2426print <<HTML; 
    2527<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> 
    2729<body> 
    28 <p><strong>MT-DB-CONVERT: Coverting your MT data between multiple db engines</strong></p> 
     30<p><strong>mt-db-convert $VERSION: Coverting your MT data between DB engines</strong></p> 
    2931HTML 
    3032 
     
    4749 
    4850my (%src, %dst); 
    49  
    50 for my $dbspec (@DBSPECS) { 
    51   $src{$dbspec} = $q->param('src_' . $dbspec) || ''; 
    52   $dst{$dbspec} = $q->param('dst_' . $dbspec) || ''; 
     51foreach (@DBSPECS) { 
     52    $src{$_} = $q->param('src_' . $_) || ''; 
     53    $dst{$_} = $q->param('dst_' . $_) || ''; 
    5354} 
    5455 
     
    5758    !$dst{ObjectDriver} || ($dst{ObjectDriver} eq 'DBM' && $dst{DataSource})) { 
    5859 
    59     for my $dbspec (@DBSPECS) { 
    60         $src{$dbspec} ||= $cfg->$dbspec(); 
    61     } 
     60    $src{$_} ||= $cfg->$_() foreach (@DBSPECS); 
    6261 
    6362    my %src_selected = ('DBM' => '', 'DBI::mysql' => '', 'DBI::postgres' => '', 'DBI::sqlite' => ''); 
     
    6665    $dst_selected{$dst{ObjectDriver}} = 'selected' if $dst{ObjectDriver}; 
    6766 
     67    my $script_name = ($0 =~ m![/\\]([^/\\]+)$!) ? $1 : 'mt-db-convert.cgi'; 
     68 
    6869    print <<HTML; 
    6970<p>Please fill the following:</p> 
    7071 
    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> 
    7375<legend>Source DB Configuration</legend> 
    7476<dl> 
    75 <dt>DataSource: (mandatory if using BerkeleyDB)</dt> 
     77<dt>DataSource: (Required for BerkeleyDB)</dt> 
    7678<dd><input name="src_DataSource" type="text" value="$src{DataSource}" /></dd> 
    7779<dt>ObjectDriver:</dt> 
     
    9496</fieldset> 
    9597 
    96 <fieldset style="float:left; width:40%"
     98<fieldset
    9799<legend>Destination DB Configuration</legend> 
    98100<dl> 
    99 <dt>DataSource: (mandatory if using BerkeleyDB)</dt> 
     101<dt>DataSource: (Required for BerkeleyDB)</dt> 
    100102<dd><input name="dst_DataSource" type="text" value="$dst{DataSource}" /></dd> 
    101103<dt>ObjectDriver:</dt> 
     
    120122<p style="clear:both;"><input type="submit" value="Convert" /></p> 
    121123</form> 
    122  
    123124HTML 
    124125 
     
    132133    if ($type) { 
    133134    # set dst driver 
    134     for my $dbspec (@DBSPECS) { 
    135         $cfg->set($dbspec, $dst{$dbspec}); 
    136     } 
     135    $cfg->set($_, $dst{$_}) foreach (@DBSPECS); 
    137136    MT::Object->set_driver($dst{ObjectDriver}) 
    138137        or die MT::ObjectDriver->errstr; 
     
    162161 
    163162        # set source driver 
    164         for my $dbspec (@DBSPECS) { 
    165             $cfg->set($dbspec, $src{$dbspec}); 
    166         } 
     163        $cfg->set($_, $src{$_}) foreach (@DBSPECS); 
    167164        MT::Object->set_driver($src{ObjectDriver}); 
    168165 
     
    171168 
    172169        my %names; 
     170        my %cat_parent; 
    173171 
    174172        # set dst driver 
    175         for my $dbspec (@DBSPECS) { 
    176             $cfg->set($dbspec, $dst{$dbspec}); 
    177         } 
     173        $cfg->set($_, $dst{$_}) foreach (@DBSPECS); 
    178174        MT::Object->set_driver($dst{ObjectDriver}); 
    179175        MT::Object->driver->{dbh}->begin_work if $type eq 'sqlite'; 
     
    214210                    print "'; renaming to '" . $obj->label . "'\n"; 
    215211                } 
     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                } 
    216217            } elsif ($class eq 'MT::Trackback') { 
    217218                $obj->entry_id(0) unless defined $obj->entry_id; 
     
    222223                $obj->allow_comments(0) 
    223224                    if defined $obj->allow_comments && $obj->allow_comments eq ''; 
     225            } elsif ($class eq 'MT::Blog') { 
     226                $obj->touch(); # for updating children_modified_on field 
    224227            } 
    225228 
     
    230233            $i % 10 or print " "; 
    231234            $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 
    233244        print "</p>\n\n"; 
    234245        MT::Object->driver->{dbh}->commit if $type eq 'sqlite'; 
     
    260271} 
    261272 
    262 print <<HTML; 
    263 </body> 
    264 </html> 
    265 HTML 
     273print "</body>\n</html>\n";