root/branches/release-33/lib/MT/CMS/Export.pm @ 1782

Revision 1782, 1.6 kB (checked in by bchoate, 20 months ago)

Fix for 500 error from export. BugId:69902

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