Changeset 847
- Timestamp:
- 12/06/06 18:28:48 (2 years ago)
- Files:
-
- branches/wheeljack/lib/MT/App/CMS.pm (modified) (7 diffs)
- branches/wheeljack/lib/MT/BackupRestore.pm (modified) (10 diffs)
- branches/wheeljack/lib/MT/Blog.pm (modified) (1 diff)
- branches/wheeljack/lib/MT/Category.pm (modified) (3 diffs)
- branches/wheeljack/lib/MT/Entry.pm (modified) (2 diffs)
- branches/wheeljack/lib/MT/FileInfo.pm (modified) (1 diff)
- branches/wheeljack/lib/MT/Template.pm (modified) (1 diff)
- branches/wheeljack/lib/MT/Trackback.pm (modified) (1 diff)
- branches/wheeljack/tmpl/cms/backup_restore.tmpl (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/wheeljack/lib/MT/App/CMS.pm
r843 r847 10853 10853 return $app->errtrans("You must select what you want to backup.") if !$what; 10854 10854 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+$/; 10858 10858 10859 10859 my $blog_ids = $q->param('selected_blog_ids') if $what eq 'custom'; … … 10906 10906 my $fname; 10907 10907 my $arc_buf; 10908 if (!($ number|| $num_assets)) {10908 if (!($size || $num_assets)) { 10909 10909 $splitter = sub {}; 10910 10910 … … 10912 10912 ($fh, my $filepath) = File::Temp::tempfile('xml.XXXXXXXX', DIR => $temp_dir); 10913 10913 (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); }; 10915 10915 $finisher = sub { 10916 10916 my ($asset_files) = @_; … … 10921 10921 require Archive::Tar; 10922 10922 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); }; 10924 10924 $finisher = sub { 10925 10925 my ($asset_files) = @_; … … 10962 10962 open $fh, ">$filename"; 10963 10963 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); }; 10965 10965 $splitter = sub { 10966 10966 my ($findex) = @_; … … 11044 11044 11045 11045 MT::BackupRestore->backup( 11046 \@blog_ids, $printer, $splitter, $finisher, $ number, $enc);11046 \@blog_ids, $printer, $splitter, $finisher, $size * 1024, $enc); 11047 11047 } 11048 11048 … … 11403 11403 {author => 'MT::Author'}, 11404 11404 {blog => 'MT::Blog'}, 11405 {template => 'MT::Template'}, 11405 11406 {role => 'MT::Role'}, 11406 11407 {category => 'MT::Category'}, 11407 11408 {asset => 'MT::Asset'}, 11408 11409 {entry => 'MT::Entry'}, 11410 {trackback => 'MT::Trackback'}, 11411 {comment => 'MT::Comment'}, 11409 11412 ); 11410 11413 11411 11414 $app->{no_print_body} = 1; 11412 11415 branches/wheeljack/lib/MT/BackupRestore.pm
r838 r847 19 19 sub backup { 20 20 my $class = shift; 21 my ($blog_ids, $printer, $splitter, $finisher, $ number, $enc) = @_;21 my ($blog_ids, $printer, $splitter, $finisher, $size, $enc) = @_; 22 22 my $obj_to_backup = []; 23 23 … … 43 43 args => undef 44 44 }}; 45 push @$obj_to_backup, {'MT::Template' => { 46 term => { 'id' => $blog_ids }, 47 args => undef 48 }}; 45 49 push @$obj_to_backup, {'MT::Role' => { 46 50 term => undef, … … 60 64 args => undef 61 65 }}; 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 }}; 62 74 } else { 63 75 push @$obj_to_backup, {'MT::Tag' => { term => undef, args => undef }}; 64 76 push @$obj_to_backup, {'MT::Author' => { term => undef, args => undef }}; 65 77 push @$obj_to_backup, {'MT::Blog' => { term => undef, args => undef }}; 78 push @$obj_to_backup, {'MT::Template' => { term => undef, args => undef }}; 66 79 push @$obj_to_backup, {'MT::Role' => { term => undef, args => undef }}; 67 80 push @$obj_to_backup, {'MT::Category' => { term => undef, args => undef }}; 68 81 push @$obj_to_backup, {'MT::Asset' => { term => undef, args => undef }}; 69 82 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 }}; 70 85 } 71 86 … … 76 91 my $files = {}; 77 92 _loop_through_objects( 78 $printer, $splitter, $finisher, $ number, $obj_to_backup, $files);93 $printer, $splitter, $finisher, $size, $obj_to_backup, $files); 79 94 80 95 my $else_xml = MT->run_callbacks('Backup.else'); … … 86 101 87 102 sub _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; 91 107 my %author_ids_seen; 92 108 for my $class_hash (@$obj_to_backup) { … … 113 129 for my $object (@objects) { 114 130 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", 120 132 MT->translate('[_1]#[_2] has been backed up.', $class, $object->id) . "\n") 121 133 if $object->to_backup; 134 if ($size && ($bytes >= $size)) { 135 $splitter->(++$counter); 136 $bytes = 0; 137 } 122 138 if ($class eq 'MT::Author') { 123 139 # MT::Author may be duplicated because of how terms and args are created. … … 145 161 {author => 'MT::Author'}, 146 162 {blog => 'MT::Blog'}, 163 {template => 'MT::Template'}, 147 164 {role => 'MT::Role'}, 148 165 {category => 'MT::Category'}, 149 166 {asset => 'MT::Asset'}, 150 167 {entry => 'MT::Entry'}, 168 {trackback => 'MT::Trackback'}, 169 {comment => 'MT::Comment'}, 151 170 ); 152 171 my %objects; … … 260 279 {author => 'MT::Author'}, 261 280 {blog => 'MT::Blog'}, 281 {template => 'MT::Template'}, 262 282 {role => 'MT::Role'}, 263 283 {category => 'MT::Category'}, 264 284 {asset => 'MT::Asset'}, 265 285 {entry => 'MT::Entry'}, 286 {trackback => 'MT::Trackback'}, 287 {comment => 'MT::Comment'}, 266 288 ); 267 289 my %objects; … … 383 405 384 406 if (!defined($file_next)) { 385 if (scalar(@$assets) ) {407 if (scalar(@$assets) > 0) { 386 408 my $asset = shift @$assets; 387 409 $file_next = $asset->{name}; … … 391 413 require JSON; 392 414 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; 394 416 $param->{files} = join(',', @$files); 395 417 $param->{assets} = $assets_json; branches/wheeljack/lib/MT/Blog.pm
r818 r847 672 672 permission => 'MT::Permission', 673 673 notification => 'MT::Notification', 674 template => 'MT::Template',675 674 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>. 679 681 }; 680 682 $children; branches/wheeljack/lib/MT/Category.pm
r822 r847 402 402 my $xml = ''; 403 403 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 #} 421 421 422 422 my $offset = 0; … … 444 444 my $obj = shift; 445 445 my $children = { 446 tbping => 'MT::TBPing',446 #tbping => 'MT::TBPing', 447 447 category => 'MT::Category', 448 448 placement => 'MT::Placement', 449 fileinfo => 'MT::FileInfo', 449 450 }; 450 451 $children; … … 453 454 sub parent_names { 454 455 my $obj = shift; 455 my $ children= {456 my $parents = { 456 457 blog => 'MT::Blog', 457 458 author => 'MT::Author', 458 459 }; 459 $ children;460 $parents; 460 461 } 461 462 branches/wheeljack/lib/MT/Entry.pm
r822 r847 694 694 } 695 695 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 #} 713 713 714 $xml .= $obj->_entry_child_to_xml('MT:: Comment', $namespace, $args);714 $xml .= $obj->_entry_child_to_xml('MT::FileInfo', $namespace, $args); 715 715 716 716 $xml; … … 745 745 my $children = { 746 746 objecttag => 'MT::ObjectTag', 747 comment => 'MT::Comment',748 tbping => 'MT::TBPing',749 747 placement => 'MT::Placement', 748 fileinfo => 'MT::FileInfo', 750 749 }; 751 750 $children; branches/wheeljack/lib/MT/FileInfo.pm
r752 r847 110 110 } 111 111 112 sub 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 112 123 1; branches/wheeljack/lib/MT/Template.pm
r770 r847 276 276 my $obj = shift; 277 277 my $children = { 278 fileinfo => 'MT::FileInfo', 278 279 templatemap => 'MT::TemplateMap', 279 280 }; branches/wheeljack/lib/MT/Trackback.pm
r717 r847 60 60 } 61 61 62 sub children_names { 63 my $obj = shift; 64 my $children = { 65 tbping => 'MT::TBPing', 66 }; 67 $children; 68 } 69 70 sub 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 102 sub parent_names { 103 my $obj = shift; 104 my $parents = { 105 entry => 'MT::Entry', 106 category => 'MT::Category', 107 }; 108 $parents; 109 } 110 111 sub 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 62 132 1; 63 133 __END__ branches/wheeljack/tmpl/cms/backup_restore.tmpl
r828 r847 63 63 </div> 64 64 <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> 66 66 <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> 68 74 <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> 69 75 </div>
