root/branches/release-30/lib/MT/CMS/Export.pm @ 1369

Revision 1369, 1.6 kB (checked in by bchoate, 22 months ago)

Broke CMS into smaller parts to reduce memory footprint and group code into logical parts. BugId:58666

  • Property svn:keywords set to Id Revision
Line 
1package MT::CMS::Export;
2
3use strict;
4
5sub start_export {
6    my $app = shift;
7    my %param;
8    my $blog_id = $app->param('blog_id');
9
10    my $perms = $app->permissions;
11    return $app->return_to_dashboard( permission => 1 )
12      if ( $perms && !$perms->can_administer_blog );
13
14    $param{blog_id} = $blog_id;
15    $app->load_tmpl( 'export.tmpl', \%param );
16}
17
18sub export {
19    my $app = shift;
20    $app->{no_print_body} = 1;
21    local $| = 1;
22    my $charset = $app->charset;
23    require MT::Blog;
24    my $blog_id = $app->param('blog_id')
25      or return $app->error( $app->translate("Please select a blog.") );
26    my $blog = MT::Blog->load($blog_id)
27      or return $app->error(
28        $app->translate(
29            "Load of blog '[_1]' failed: [_2]",
30            $blog_id, MT::Blog->errstr
31        )
32      );
33    my $perms = $app->permissions;
34    return $app->error( $app->translate("You do not have export permissions") )
35      unless $perms && $perms->can_edit_config;
36    $app->validate_magic() or return;
37    my $file = dirify( $blog->name ) . ".txt";
38
39    if ( $file eq ".txt" ) {
40        my @ts = localtime(time);
41        $file = sprintf "export-%06d-%04d%02d%02d%02d%02d%02d.txt",
42          $app->param('blog_id'), $ts[5] + 1900, $ts[4] + 1, @ts[ 3, 2, 1, 0 ];
43    }
44
45    $app->set_header( "Content-Disposition" => "attachment; filename=$file" );
46    $app->send_http_header(
47        $charset
48        ? "text/plain; charset=$charset"
49        : 'text/plain'
50    );
51    require MT::ImportExport;
52    MT::ImportExport->export( $blog, sub { $app->print(@_) } )
53      or return $app->error( MT::ImportExport->errstr );
54    1;
55}
56
571;
Note: See TracBrowser for help on using the browser.