Changeset 847

Show
Ignore:
Timestamp:
12/06/06 18:28:48 (2 years ago)
Author:
fumiakiy
Message:

Modified the algorithm of dividing backups into multiple files to specify size of a file instead of items per file. BugId: 45331

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/wheeljack/lib/MT/App/CMS.pm

    r843 r847  
    1085310853    return $app->errtrans("You must select what you want to backup.") if !$what; 
    1085410854 
    10855     my $number = $q->param('num_items') || 0; 
    10856     return $app->errtrans('[_1] is not a number.', $number
    10857         if $number !~ /^\d+$/; 
     10855    my $size = $q->param('size_limit') || 0; 
     10856    return $app->errtrans('[_1] is not a number.', $size
     10857        if $size !~ /^\d+$/; 
    1085810858 
    1085910859    my $blog_ids = $q->param('selected_blog_ids') if $what eq 'custom'; 
     
    1090610906    my $fname; 
    1090710907    my $arc_buf; 
    10908     if (!($number || $num_assets)) { 
     10908    if (!($size || $num_assets)) { 
    1090910909        $splitter = sub {}; 
    1091010910 
     
    1091210912            ($fh, my $filepath) = File::Temp::tempfile('xml.XXXXXXXX', DIR => $temp_dir); 
    1091310913            (my $vol, my $dir, $fname) = File::Spec->splitpath($filepath); 
    10914             $printer = sub { my ($data, $message) = @_; print $fh $data; $app->print($message); }; 
     10914            $printer = sub { my ($data, $message) = @_; print $fh $data; $app->print($message); return length($data); }; 
    1091510915            $finisher = sub {  
    1091610916                my ($asset_files) = @_; 
     
    1092110921            require Archive::Tar; 
    1092210922            require Compress::Zlib; 
    10923             $printer = sub { my ($data, $message) = @_; $arc_buf .= $data; $app->print($message); }; 
     10923            $printer = sub { my ($data, $message) = @_; $arc_buf .= $data; $app->print($message); return length($data); }; 
    1092410924            $finisher = sub { 
    1092510925                my ($asset_files) = @_; 
     
    1096210962        open $fh, ">$filename"; 
    1096310963        push @files, { filename => $file . "-1.xml" }; 
    10964         $printer = sub { my ($data, $message) = @_; print $fh $data; $app->print($message); }; 
     10964        $printer = sub { my ($data, $message) = @_; print $fh $data; $app->print($message); return length($data); }; 
    1096510965        $splitter = sub { 
    1096610966            my ($findex) = @_; 
     
    1104411044 
    1104511045    MT::BackupRestore->backup( 
    11046         \@blog_ids, $printer, $splitter, $finisher, $number, $enc); 
     11046        \@blog_ids, $printer, $splitter, $finisher, $size * 1024, $enc); 
    1104711047} 
    1104811048 
     
    1140311403        {author => 'MT::Author'}, 
    1140411404        {blog => 'MT::Blog'}, 
     11405        {template => 'MT::Template'}, 
    1140511406        {role => 'MT::Role'}, 
    1140611407        {category => 'MT::Category'}, 
    1140711408        {asset => 'MT::Asset'}, 
    1140811409        {entry => 'MT::Entry'}, 
     11410        {trackback => 'MT::Trackback'}, 
     11411        {comment => 'MT::Comment'}, 
    1140911412    ); 
    11410  
     11413  
    1141111414    $app->{no_print_body} = 1; 
    1141211415 
  • branches/wheeljack/lib/MT/BackupRestore.pm

    r838 r847  
    1919sub backup { 
    2020    my $class = shift; 
    21     my ($blog_ids, $printer, $splitter, $finisher, $number, $enc) = @_; 
     21    my ($blog_ids, $printer, $splitter, $finisher, $size, $enc) = @_; 
    2222    my $obj_to_backup = []; 
    2323 
     
    4343            args => undef 
    4444            }}; 
     45        push @$obj_to_backup, {'MT::Template' => {  
     46            term => { 'id' => $blog_ids },  
     47            args => undef 
     48            }}; 
    4549        push @$obj_to_backup, {'MT::Role' => { 
    4650            term => undef, 
     
    6064            args => undef 
    6165            }}; 
     66        push @$obj_to_backup, {'MT::Trackback' => { 
     67            term => { 'blog_id' => $blog_ids },  
     68            args => undef 
     69            }}; 
     70        push @$obj_to_backup, {'MT::Comment' => { 
     71            term => { 'blog_id' => $blog_ids },  
     72            args => undef 
     73            }}; 
    6274    } else { 
    6375        push @$obj_to_backup, {'MT::Tag' => { term => undef, args => undef }}; 
    6476        push @$obj_to_backup, {'MT::Author' => { term => undef, args => undef }}; 
    6577        push @$obj_to_backup, {'MT::Blog' => { term => undef, args => undef }}; 
     78        push @$obj_to_backup, {'MT::Template' => { term => undef, args => undef }}; 
    6679        push @$obj_to_backup, {'MT::Role' => { term => undef, args => undef }}; 
    6780        push @$obj_to_backup, {'MT::Category' => { term => undef, args => undef }}; 
    6881        push @$obj_to_backup, {'MT::Asset' => { term => undef, args => undef }}; 
    6982        push @$obj_to_backup, {'MT::Entry' => { term => undef, args => undef }}; 
     83        push @$obj_to_backup, {'MT::Trackback' => { term => undef, args => undef }}; 
     84        push @$obj_to_backup, {'MT::Comment' => { term => undef, args => undef }}; 
    7085    } 
    7186 
     
    7691    my $files = {}; 
    7792    _loop_through_objects( 
    78         $printer, $splitter, $finisher, $number, $obj_to_backup, $files); 
     93        $printer, $splitter, $finisher, $size, $obj_to_backup, $files); 
    7994 
    8095    my $else_xml = MT->run_callbacks('Backup.else'); 
     
    86101 
    87102sub _loop_through_objects { 
    88     my ($printer, $splitter, $finisher, $number, $obj_to_backup, $files) = @_; 
    89  
    90     my $counter = 0; 
     103    my ($printer, $splitter, $finisher, $size, $obj_to_backup, $files) = @_; 
     104 
     105    my $counter = 1; 
     106    my $bytes = 0; 
    91107    my %author_ids_seen; 
    92108    for my $class_hash (@$obj_to_backup) { 
     
    113129            for my $object (@objects) { 
    114130                next if ($class eq 'MT::Author') && exists($author_ids_seen{$object->id}); 
    115                 $counter++; 
    116                 if ($number && ($counter % $number == 0)) { 
    117                     $splitter->(int($counter / $number + 1)); 
    118                 } 
    119                 $printer->($object->to_xml(undef, $args) . "\n",  
     131                $bytes += $printer->($object->to_xml(undef, $args) . "\n",  
    120132                    MT->translate('[_1]#[_2] has been backed up.', $class, $object->id) . "\n") 
    121133                        if $object->to_backup; 
     134                if ($size && ($bytes >= $size)) { 
     135                    $splitter->(++$counter); 
     136                    $bytes = 0; 
     137                } 
    122138                if ($class eq 'MT::Author') { 
    123139                    # MT::Author may be duplicated because of how terms and args are created. 
     
    145161        {author => 'MT::Author'}, 
    146162        {blog => 'MT::Blog'}, 
     163        {template => 'MT::Template'}, 
    147164        {role => 'MT::Role'}, 
    148165        {category => 'MT::Category'}, 
    149166        {asset => 'MT::Asset'}, 
    150167        {entry => 'MT::Entry'}, 
     168        {trackback => 'MT::Trackback'}, 
     169        {comment => 'MT::Comment'}, 
    151170    ); 
    152171    my %objects; 
     
    260279        {author => 'MT::Author'}, 
    261280        {blog => 'MT::Blog'}, 
     281        {template => 'MT::Template'}, 
    262282        {role => 'MT::Role'}, 
    263283        {category => 'MT::Category'}, 
    264284        {asset => 'MT::Asset'}, 
    265285        {entry => 'MT::Entry'}, 
     286        {trackback => 'MT::Trackback'}, 
     287        {comment => 'MT::Comment'}, 
    266288    ); 
    267289    my %objects; 
     
    383405 
    384406    if (!defined($file_next)) { 
    385         if (scalar(@$assets)) { 
     407        if (scalar(@$assets) > 0) { 
    386408            my $asset = shift @$assets; 
    387409            $file_next = $asset->{name}; 
     
    391413    require JSON; 
    392414    require MT::Util; 
    393     $assets_json = MT::Util::encode_html(JSON::objToJson($assets)) if scalar(@$assets)
     415    $assets_json = MT::Util::encode_html(JSON::objToJson($assets)) if scalar(@$assets) > 0
    394416    $param->{files} = join(',', @$files); 
    395417    $param->{assets} = $assets_json; 
  • branches/wheeljack/lib/MT/Blog.pm

    r818 r847  
    672672        permission => 'MT::Permission', 
    673673        notification => 'MT::Notification', 
    674         template => 'MT::Template', 
    675674        association => 'MT::Association', 
    676         #entry => 'MT::Entry',  ## A blog is a parent of an entry but an entry is not a child of a blog 
    677                                 ## otherwise entries duplicate in restore operation. 
    678                                 ## Also, <blog> must come before <entry>. 
     675        fileinfo => 'MT::FileInfo', 
     676        #template => 'MT::Template', 
     677        #entry => 'MT::Entry',  ## A blog is a parent of an entry/a template but  
     678                                ## they are not a child of a blog 
     679                                ## otherwise they duplicate in restore operation. 
     680                                ## Also, <blog> must come before <entry> and <template>. 
    679681    }; 
    680682    $children; 
  • branches/wheeljack/lib/MT/Category.pm

    r822 r847  
    402402    my $xml = ''; 
    403403 
    404     require MT::Trackback; 
    405     my $tb = MT::Trackback->load({ category_id => $obj->id }); 
    406     if ($tb) { 
    407         require MT::TBPing; 
    408         my $offset = 0; 
    409         while (1) { 
    410             my @pings = MT::TBPing->load( 
    411                 { tb_id => $tb->id, }, 
    412                 { offset => $offset, limit => 50, } 
    413             ); 
    414             last unless @pings; 
    415             $offset += scalar @pings; 
    416             for my $ping (@pings) { 
    417                 $xml .= $ping->to_xml($namespace, $args) . "\n" if $ping->to_backup; 
    418             } 
    419         } 
    420    
     404    #require MT::Trackback; 
     405    #my $tb = MT::Trackback->load({ category_id => $obj->id }); 
     406    #if ($tb) { 
     407    #    require MT::TBPing; 
     408    #    my $offset = 0; 
     409    #    while (1) { 
     410    #        my @pings = MT::TBPing->load( 
     411    #            { tb_id => $tb->id, }, 
     412    #            { offset => $offset, limit => 50, } 
     413    #        ); 
     414    #        last unless @pings; 
     415    #        $offset += scalar @pings; 
     416    #        for my $ping (@pings) { 
     417    #            $xml .= $ping->to_xml($namespace, $args) . "\n" if $ping->to_backup; 
     418    #        } 
     419    #    } 
     420    #
    421421 
    422422    my $offset = 0; 
     
    444444    my $obj = shift; 
    445445    my $children = { 
    446         tbping => 'MT::TBPing', 
     446        #tbping => 'MT::TBPing', 
    447447        category => 'MT::Category', 
    448448        placement => 'MT::Placement', 
     449        fileinfo => 'MT::FileInfo', 
    449450    }; 
    450451    $children; 
     
    453454sub parent_names { 
    454455    my $obj = shift; 
    455     my $children = { 
     456    my $parents = { 
    456457        blog => 'MT::Blog', 
    457458        author => 'MT::Author', 
    458459    }; 
    459     $children
     460    $parents
    460461} 
    461462 
  • branches/wheeljack/lib/MT/Entry.pm

    r822 r847  
    694694    } 
    695695     
    696     require MT::Trackback; 
    697     my $tb = MT::Trackback->load({ entry_id => $obj->id }); 
    698     if ($tb) { 
    699         require MT::TBPing; 
    700         my $offset = 0; 
    701         while (1) { 
    702             my @pings = MT::TBPing->load( 
    703                 { tb_id => $tb->id, }, 
    704                 { offset => $offset, limit => 50, } 
    705             ); 
    706             last unless @pings; 
    707             $offset += scalar @pings; 
    708             for my $ping (@pings) { 
    709                 $xml .= $ping->to_xml($namespace, $args) . "\n" if $ping->to_backup; 
    710             } 
    711         } 
    712    
     696    #require MT::Trackback; 
     697    #my $tb = MT::Trackback->load({ entry_id => $obj->id }); 
     698    #if ($tb) { 
     699    #    require MT::TBPing; 
     700    #    my $offset = 0; 
     701    #    while (1) { 
     702    #        my @pings = MT::TBPing->load( 
     703    #            { tb_id => $tb->id, }, 
     704    #            { offset => $offset, limit => 50, } 
     705    #        ); 
     706    #        last unless @pings; 
     707    #        $offset += scalar @pings; 
     708    #        for my $ping (@pings) { 
     709    #            $xml .= $ping->to_xml($namespace, $args) . "\n" if $ping->to_backup; 
     710    #        } 
     711    #    } 
     712    #
    713713     
    714     $xml .= $obj->_entry_child_to_xml('MT::Comment', $namespace, $args); 
     714    $xml .= $obj->_entry_child_to_xml('MT::FileInfo', $namespace, $args); 
    715715     
    716716    $xml; 
     
    745745    my $children = { 
    746746        objecttag => 'MT::ObjectTag', 
    747         comment => 'MT::Comment', 
    748         tbping => 'MT::TBPing', 
    749747        placement => 'MT::Placement', 
     748        fileinfo => 'MT::FileInfo', 
    750749    }; 
    751750    $children; 
  • branches/wheeljack/lib/MT/FileInfo.pm

    r752 r847  
    110110} 
    111111 
     112sub parent_names { 
     113    my $obj = shift; 
     114    my $parents = { 
     115        blog => 'MT::Blog', 
     116        template => 'MT::Template', 
     117        category => 'MT::Category', 
     118        entry => 'MT::Entry', 
     119    }; 
     120    $parents; 
     121} 
     122 
    1121231; 
  • branches/wheeljack/lib/MT/Template.pm

    r770 r847  
    276276    my $obj = shift; 
    277277    my $children = { 
     278        fileinfo => 'MT::FileInfo', 
    278279        templatemap => 'MT::TemplateMap', 
    279280    }; 
  • branches/wheeljack/lib/MT/Trackback.pm

    r717 r847  
    6060} 
    6161 
     62sub children_names { 
     63    my $obj = shift; 
     64    my $children = { 
     65        tbping => 'MT::TBPing', 
     66    }; 
     67    $children; 
     68} 
     69 
     70sub children_to_xml { 
     71    my $obj = shift; 
     72    my ($namespace, $args) = @_; 
     73 
     74    my $t = {}; 
     75    if (defined($args)) { 
     76        my $j = $args->{'join'}; 
     77        $t = $j->[2] if defined($j); 
     78    } 
     79 
     80    my $xml = ''; 
     81 
     82    my $terms = {  
     83        'tb_id' => $obj->id, 
     84        %$t, 
     85    }; 
     86     
     87    my $offset = 0; 
     88    while (1) { 
     89        my @objects = MT::TBPing->load( 
     90            $terms, 
     91            { offset => $offset, limit => 50, } 
     92        ); 
     93        last unless @objects; 
     94        $offset += scalar @objects; 
     95        for my $object (@objects) { 
     96            $xml .= $object->to_xml($namespace) . "\n" if $object->to_backup; 
     97        } 
     98    } 
     99    $xml; 
     100} 
     101 
     102sub parent_names { 
     103    my $obj = shift; 
     104    my $parents = { 
     105        entry => 'MT::Entry', 
     106        category => 'MT::Category', 
     107    }; 
     108    $parents; 
     109} 
     110 
     111sub restore_parent_ids { 
     112    my $obj = shift; 
     113    my ($data, $objects) = @_; 
     114 
     115    my $result = 0; 
     116    if ($data->{category_id}) { 
     117        my $new_obj = $objects->{'MT::Category#' . $data->{category_id}}; 
     118        if ($new_obj) { 
     119            $data->{category_id} = $new_obj->id; 
     120            $result = 1; 
     121        } 
     122    } elsif ($data->{entry_id}) { 
     123        my $new_obj = $objects->{'MT::Entry#' . $data->{entry_id}}; 
     124        if ($new_obj) { 
     125            $data->{entry_id} = $new_obj->id; 
     126            $result = 1; 
     127        } 
     128    } 
     129    $result; 
     130} 
     131 
    621321; 
    63133__END__ 
  • branches/wheeljack/tmpl/cms/backup_restore.tmpl

    r828 r847  
    6363</div> 
    6464<div class="setting"> 
    65 <div class="label"><label for="num_items"><MT_TRANS phrase="Number of Items per file">:</label></div> 
     65<div class="label"><label for="num_items"><MT_TRANS phrase="Number of megabytes per file">:</label></div> 
    6666<div class="field"> 
    67 <input name="num_items" id="num_items" value="<TMPL_VAR NAME=NAME ESCAPE=HTML>" size="30" /> 
     67<select name="size_limit" id="size_limit"> 
     68<option value="0" selected="selected">Don't Divide</option> 
     69<option value="1024">1MB</option> 
     70<option value="2048">2MB</option> 
     71<option value="4096">4MB</option> 
     72<option value="8192">8MB</option> 
     73</select> 
    6874<p><MT_TRANS phrase="How many items are in a single file."> <a href="#" onclick="return openManual('backup_restore', 'backup_num_items')" class="help">?</a></p> 
    6975</div>