Changeset 814
- Timestamp:
- 12/01/06 13:46:30 (2 years ago)
- Files:
-
- branches/wheeljack/lib/MT/App/CMS.pm (modified) (5 diffs)
- branches/wheeljack/lib/MT/BackupRestore.pm (modified) (4 diffs)
- branches/wheeljack/lib/MT/Object.pm (modified) (4 diffs)
- branches/wheeljack/tmpl/cms/backup_restore.tmpl (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/wheeljack/lib/MT/App/CMS.pm
r813 r814 144 144 'list_roles' => \&list_roles, 145 145 'dialog_select_weblog' => \&dialog_select_weblog, 146 'dialog_select_user' => \&dialog_select_user,147 146 'dialog_grant_role' => \&dialog_grant_role, 148 147 'grant_role' => \&grant_role, … … 10816 10815 return $app->errtrans("What to backup must be selected.") if !$what; 10817 10816 10818 my $meth = "backup_$what";10819 $app->$meth(@_);10820 }10821 10822 sub backup_everything {10823 my $app = shift;10824 my $user = $app->user;10825 10826 my $q = $app->param;10827 10817 my $number = $q->param('num_items') || 0; 10828 10818 return $app->errtrans('[_1] is not a number.', $number) 10829 10819 if $number !~ /^\d+$/; 10820 10821 my $blog_ids = $q->param('selected_blog_ids') if $what eq 'custom'; 10822 return $app->errtrans('Choose weblogs to backup.') if $what eq 'custom' && (!defined($blog_ids) || !$blog_ids); 10823 10824 my @blog_ids = split ',', $blog_ids; 10825 10830 10826 my $archive = $q->param('backup_archive_format'); 10831 10827 my $enc = $app->config('PublishCharset') || 'utf-8'; … … 11005 11001 }; 11006 11002 11007 MT::BackupRestore->backup_everything($printer, $splitter, $finisher, $callback, $number, $enc); 11008 } 11009 11010 sub backup_allentries { 11011 my $app = shift; 11012 my $user = $app->user; 11013 return $app->errtrans("Permission denied.") if !$user->is_superuser; 11014 $app->validate_magic() or return; 11015 11016 $app->errtrans("Not implemented yet"); 11017 } 11018 11019 sub backup_custom { 11020 my $app = shift; 11021 my $user = $app->user; 11022 return $app->errtrans("Permission denied.") if !$user->is_superuser; 11023 $app->validate_magic() or return; 11024 11025 $app->errtrans("Not implemented yet"); 11003 MT::BackupRestore->backup( 11004 \@blog_ids, $printer, $splitter, $finisher, $callback, $number, $enc); 11026 11005 } 11027 11006 … … 11490 11469 } 11491 11470 11471 sub dialog_select_weblog { 11472 my $app = shift; 11473 return $app->errtrans("Permission denied.") 11474 unless $app->user->is_superuser; 11475 11476 my $hasher = sub { 11477 my ($obj, $row) = @_; 11478 $row->{label} = $row->{name}; 11479 $row->{'link'} = $row->{site_url}; 11480 }; 11481 11482 $app->listing({ 11483 Type => 'blog', 11484 Code => $hasher, 11485 Template => 'dialog_select_weblog.tmpl', 11486 Params => { 11487 dialog_title => $app->translate("Select Weblog"), 11488 items_prompt => $app->translate("Selected Weblog"), 11489 search_prompt => $app->translate("Type a weblog name to filter the choices below."), 11490 panel_label => $app->translate("Weblog Name"), 11491 panel_description => $app->translate("Description"), 11492 panel_type => 'blog', 11493 panel_multi => 1, 11494 panel_searchable => 1, 11495 panel_first => 1, 11496 panel_last => 1, 11497 list_noncron => 1, 11498 }, 11499 }); 11500 } 11501 11492 11502 1; 11493 11503 __END__ … … 12366 12376 Handler for the system backup function. 12367 12377 12368 =item * backup_restore12369 12370 Handler for the system restorefunction.12378 =item * restore 12379 12380 Handler for the system backup function. 12371 12381 12372 12382 =back branches/wheeljack/lib/MT/BackupRestore.pm
r813 r814 17 17 use File::Copy; 18 18 19 sub backup_everything { 20 my $class = shift; 21 my ($printer, $splitter, $finisher, $callback, $number, $enc) = @_; 22 my @obj_to_backup = ( 23 'MT::Tag', 24 'MT::Author', 25 'MT::Blog', 26 'MT::Role', 27 'MT::Category', 28 'MT::Asset', 29 'MT::Entry', 30 ); 19 sub backup { 20 my $class = shift; 21 my ($blog_ids, $printer, $splitter, $finisher, $callback, $number, $enc) = @_; 22 my $obj_to_backup = []; 23 24 if (defined($blog_ids) && scalar(@$blog_ids)) { 25 push @$obj_to_backup, {'MT::Tag' => { 26 term => undef, 27 args => { 'join' => 28 [ 'MT::ObjectTag', 'tag_id', { blog_id => $blog_ids }, undef ] 29 }}}; 30 push @$obj_to_backup, {'MT::Author' => { 31 term => undef, 32 args => { 'join' => 33 [ 'MT::Association', 'author_id', { blog_id => $blog_ids }, undef ] 34 }}}; 35 ## Author has two different ways to associate to a weblog... 36 push @$obj_to_backup, {'MT::Author' => { 37 term => undef, 38 args => { 'join' => 39 [ 'MT::Permission', 'author_id', { blog_id => $blog_ids }, undef ] 40 }}}; 41 push @$obj_to_backup, {'MT::Blog' => { 42 term => { 'id' => $blog_ids }, 43 args => undef 44 }}; 45 push @$obj_to_backup, {'MT::Role' => { 46 term => undef, 47 args => { 'join' => 48 [ 'MT::Association', 'role_id', { blog_id => $blog_ids }, undef ] 49 }}}; 50 push @$obj_to_backup, {'MT::Category' => { 51 term => { 'blog_id' => $blog_ids }, 52 args => undef 53 }}; 54 push @$obj_to_backup, {'MT::Asset' => { 55 term => { 'blog_id' => $blog_ids }, 56 args => undef 57 }}; 58 push @$obj_to_backup, {'MT::Entry' => { 59 term => { 'blog_id' => $blog_ids }, 60 args => undef 61 }}; 62 } else { 63 push @$obj_to_backup, {'MT::Tag' => { term => undef, args => undef }}; 64 push @$obj_to_backup, {'MT::Author' => { term => undef, args => undef }}; 65 push @$obj_to_backup, {'MT::Blog' => { term => undef, args => undef }}; 66 push @$obj_to_backup, {'MT::Role' => { term => undef, args => undef }}; 67 push @$obj_to_backup, {'MT::Category' => { term => undef, args => undef }}; 68 push @$obj_to_backup, {'MT::Asset' => { term => undef, args => undef }}; 69 push @$obj_to_backup, {'MT::Entry' => { term => undef, args => undef }}; 70 } 31 71 32 72 my $header .= "<movabletype xmlns='" . NS_MOVABLETYPE . "'>\n"; … … 35 75 36 76 my $files = {}; 37 _loop_through_objects($printer, $splitter, $finisher, $callback, $number, \@obj_to_backup, $files); 77 _loop_through_objects( 78 $printer, $splitter, $finisher, $callback, $number, $obj_to_backup, $files); 38 79 39 80 $printer->('</movabletype>'); … … 45 86 46 87 my $counter = 0; 47 for my $class (@$obj_to_backup) { 48 eval "require $class; "; 88 my %author_ids_seen; 89 for my $class_hash (@$obj_to_backup) { 90 my ($class, $term_arg) = each(%$class_hash); 91 eval "require $class;"; 92 my $children = $class->children_names || {}; 93 for my $child_class (values %$children) { 94 eval "require $child_class;"; 95 } 49 96 my $err = $@; 50 97 if ($err) { … … 53 100 } 54 101 my $offset = 0; 102 my $term = $term_arg->{term} || {}; 103 my $args = $term_arg->{args}; 55 104 while (1) { 56 my @objects = $class->load(undef, { offset => $offset, limit => 50, }); 105 $args->{offset} = $offset; 106 $args->{limit} = 50; 107 my @objects = $class->load($term, $args); 57 108 last unless @objects; 58 109 $offset += scalar @objects; 59 110 for my $object (@objects) { 111 next if ($class eq 'MT::Author') && exists($author_ids_seen{$object->id}); 60 112 $counter++; 61 113 if ($number && ($counter % $number == 0)) { 62 114 $splitter->(int($counter / $number + 1)); 63 115 } 64 if ($class eq 'MT::Asset') { 65 $printer->($object->to_xml . "\n") if $object->to_backup; 116 $printer->($object->to_xml($args) . "\n") if $object->to_backup; 117 if ($class eq 'MT::Author') { 118 # MT::Author may be duplicated because of how terms and args are created. 119 $author_ids_seen{$object->id} = 1; 120 } elsif ($class eq 'MT::Asset') { 66 121 $files->{$object->id} = [$object->url, $object->file_path, $object->file_name]; 67 } else {68 $printer->($object->to_xml . "\n") if $object->to_backup;69 122 } 70 123 my $xml = $callback->($object) branches/wheeljack/lib/MT/Object.pm
r808 r814 386 386 sub children_to_xml { 387 387 my $obj = shift; 388 my ($args) = @_; 389 390 my $t = {}; 391 if (defined($args)) { 392 my $j = $args->{'join'}; 393 $t = $j->[2] if defined($j); 394 } 388 395 389 396 my $children = $obj->children_names; … … 396 403 return $err if defined($err) && $err; 397 404 405 my $terms = { 406 $obj->datasource . '_id' => $obj->id, 407 %$t, 408 }; 409 398 410 my $offset = 0; 399 411 while (1) { 400 412 my @objects = $child_class->load( 401 { $obj->datasource . '_id' => $obj->id, },413 $terms, 402 414 { offset => $offset, limit => 50, } 403 415 ); … … 414 426 sub to_xml { 415 427 my $obj = shift; 428 my ($args) = @_; 416 429 417 430 my $coldefs = $obj->column_defs; … … 438 451 $xml .= '>'; 439 452 $xml .= "<$_>" . MT::Util::encode_xml($obj->column($_), 1) . "</$_>" foreach @elements; 440 $xml .= $obj->children_to_xml ;453 $xml .= $obj->children_to_xml($args); 441 454 $xml .= '</' . $obj->datasource . '>'; 442 455 $xml; branches/wheeljack/tmpl/cms/backup_restore.tmpl
r795 r814 4 4 5 5 function highlightSwitch(selection) { 6 var customizePanel = getByID('customize-panel');7 6 var descriptionObject = getByID('backup-what-description'); 8 if ( customizePanel) {7 if (descriptionObject) { 9 8 if (selection.value == 'custom') { 10 customizePanel.style.display = '';9 openDialog(this.form, 'dialog_select_weblog'); 11 10 descriptionObject.innerHTML = '<MT_TRANS phrase="This option allows you to choose exactly what you want to backup.">'; 12 } else if (selection.value == 'allentries') {13 customizePanel.style.display = 'none';14 descriptionObject.innerHTML = '<MT_TRANS phrase="This option will backup Entries, Categories, and Templates as well as related objects such as Comments and Authors.">';15 11 } else { 16 customizePanel.style.display = 'none'; 12 var el_id = getByID('selected_blog_ids'); 13 if (el_id) el_id.value = ''; 14 var el_name = getByID('selected_blogs'); 15 if (el_name) el_name.innerHTML = '(<MT_TRANS phrase="None Selected.">)'; 17 16 descriptionObject.innerHTML = '<MT_TRANS phrase="This option will backup Users, Roles, Associations, Weblogs, Entries, Categories, Templates and Tags.">'; 18 17 } … … 47 46 <select name="backup_what" id="backup_what" onchange="highlightSwitch(this)"> 48 47 <option value="everything" selected="selected"><MT_TRANS phrase="Everything"></option> 49 <option value="allentries"><MT_TRANS phrase="All entries from all weblogs"></option> 50 <option value="custom"><MT_TRANS phrase="Choose what to backup"></option> 48 <option value="custom"><MT_TRANS phrase="Choose weblogs to backup"></option> 51 49 </select> 52 <p id="customize-panel" style="display:none;"> 53 <input type="radio" id="users" name="users" value="0"> <label for="users"><MT_TRANS phrase="Users"></label><br /> 54 <input type="radio" id="roles" name="roles" value="1"> <label for="roles"><MT_TRANS phrase="Roles"></label><br /> 55 <input type="radio" id="associations" name="associations" value="2"> <label for="associations"><MT_TRANS phrase="Associations"></label><br /> 56 <input type="radio" id="weblogs" name="weblogs" value="3"> <label for="weblogs"><MT_TRANS phrase="Weblogs"></label><br /> 57 <input type="radio" id="entries" name="entries" value="0"> <label for="entries"><MT_TRANS phrase="Entries"></label><br /> 58 <input type="radio" id="categories" name="categories" value="1"> <label for="categories"><MT_TRANS phrase="Categories"></label><br /> 59 <input type="radio" id="notifications" name="notifications" value="2"> <label for="notifications"><MT_TRANS phrase="Notifications"></label><br /> 60 <input type="radio" id="templates" name="templates" value="3"> <label for="templates"><MT_TRANS phrase="Templates"></label><br /> 61 <input type="radio" id="tags" name="tags" value="3"> <label for="tags"><MT_TRANS phrase="Tags"></label><br /> 62 </p> 50 <input type="hidden" id="selected_blog_ids" name="selected_blog_ids" value="" /> 51 <p><strong><span id="selected_blogs">(<MT_TRANS phrase="None selected.">)</span> 63 52 <p><span id="backup-what-description"><MT_TRANS phrase="This option will backup Users, Roles, Associations, Weblogs, Entries, Categories, Templates and Tags."></span> 64 53 <a href="#" onclick="return openManual('backup_restore', 'backup_what')" class="help">?</a></p>
