Changeset 967

Show
Ignore:
Timestamp:
12/21/06 00:44:41 (2 years ago)
Author:
bchoate
Message:

Fixed display of author when asset file can't be found. BugId: 45987. Updates to make rebuilding of multiple entries more efficient (when selecting to rebuild, or selecting entries to unpublish/publish). BugId: 39359. Fixed handling of MT::Asset objects when overwriting an existing file. BugId: 45617

Files:

Legend:

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

    r962 r967  
    254254                              label => "Unpublish TrackBack(s)", 
    255255                              code => \&unapprove_item, 
    256                               condition => sub { $_[0] ne 'junk' }, # param is tab name 
     256                              condition => sub { @_ && ($_[0] ne 'junk') }, # param is tab name 
    257257                          }, 1); 
    258258    $app->add_itemset_action({type => 'comment', 
     
    260260                              label => "Unpublish Comment(s)", 
    261261                              code => \&unapprove_item, 
    262                               condition => sub { $_[0] ne 'junk' }, 
     262                              condition => sub { @_ && ($_[0] ne 'junk') }, 
    263263                          }, 1); 
    264264    $app->add_itemset_action({type => 'comment', 
     
    936936                $row->{file_size_formatted} = sprintf("%.1f MB", $size / 1024000); 
    937937            } 
    938             my $ts = $obj->created_on; 
    939             unless ($ts) { 
    940                 $ts = $stat[10]; 
    941                 $ts = epoch2ts($blog, $ts); 
    942             } 
    943             if (my $by = $obj->created_by) { 
    944                 my $user = MT::Author->load($by, { cached_ok => 1 }); 
    945                 $row->{created_by} = $user ? $user->name : ''; 
    946             } 
    947             if ($ts) { 
    948                 $row->{created_on_formatted} = 
    949                     format_ts("%Y.%m.%d", $ts);  
    950                 $row->{created_on_time_formatted} = 
    951                     format_ts("%Y-%m-%d %H:%M:%S", $ts);  
    952                 $row->{created_on_relative} = 
    953                     relative_date($ts, time, $blog); 
    954             } 
    955938        } else { 
    956939            $row->{file_is_missing} = 1; 
     940        } 
     941        my $ts = $obj->created_on; 
     942        if (my $by = $obj->created_by) { 
     943            my $user = MT::Author->load($by, { cached_ok => 1 }); 
     944            $row->{created_by} = $user ? $user->name : ''; 
     945        } 
     946        if ($ts) { 
     947            $row->{created_on_formatted} = 
     948                format_ts("%Y.%m.%d", $ts);  
     949            $row->{created_on_time_formatted} = 
     950                format_ts("%Y-%m-%d %H:%M:%S", $ts);  
     951            $row->{created_on_relative} = 
     952                relative_date($ts, time, $blog); 
    957953        } 
    958954        $row->{metadata_json} = JSON::objToJson($meta); 
     
    56855681    $app->{goback} = "window.location='". $app->return_uri . "'"; 
    56865682    if ($type eq 'entry') { 
    5687         require MT::Entry; 
    5688         foreach (@ids) { 
    5689             my $entry = MT::Entry->load($_, {cached_ok=>1}); 
    5690             next unless $entry; 
    5691             if ($entry->status == MT::Entry::RELEASE()) { 
    5692                 $app->rebuild_entry(Entry => $entry, BuildDependencies => 1) 
    5693                     or return; 
    5694             } 
    5695         } 
     5683        my %ids = map { $_ => 1 } @ids; 
     5684        return $app->rebuild_these(\%ids); 
    56965685    } elsif ($type eq 'template') { 
    56975686        require MT::Template; 
     
    57065695 
    57075696sub draft_entries { 
     5697    my $app = shift; 
    57085698    require MT::Entry; 
    5709     $_[0]->update_entry_status(MT::Entry::HOLD(), $_[0]->param('id')); 
     5699    $app->update_entry_status(MT::Entry::HOLD(), $_[0]->param('id')); 
    57105700} 
    57115701 
    57125702sub publish_entries { 
     5703    my $app = shift; 
    57135704    require MT::Entry; 
    5714     $_[0]->update_entry_status(MT::Entry::RELEASE(), $_[0]->param('id')); 
     5705    $app->update_entry_status(MT::Entry::RELEASE(), $_[0]->param('id')); 
    57155706} 
    57165707 
     
    57185709    my $app = shift; 
    57195710    my ($new_status, @ids) = @_; 
    5720     return $app->errtrans("Need a status to update entries") unless $new_status; 
    5721     return $app->errtrans("Need entries to update status") unless @ids; 
     5711    return $app->errtrans("Need a status to update entries") 
     5712        unless $new_status; 
     5713    return $app->errtrans("Need entries to update status") 
     5714        unless @ids; 
    57225715    my @bad_ids; 
    57235716    my @rebuild_list; 
     5717    my %rebuild_these; 
    57245718    require MT::Entry; 
    57255719    foreach my $id (@ids) { 
    57265720        my $entry = MT::Entry->load($id, {cached_ok=>1}) or return $app->errtrans("One of the entries ([_1]) did not actually exist", $id); 
    5727         push @rebuild_list, $entry if $entry->status != $new_status; 
     5721        next if $entry->status != $new_status; 
    57285722        $entry->status($new_status); 
    5729         $entry->save() or (push @bad_ids, $id); 
    5730     } 
    5731     return $app->errtrans("Some entries failed to save") if (@bad_ids); # FIXME: we don't really want this 
    5732     $app->rebuild_entry(Entry => $_, BuildDependencies => 1)  
    5733         foreach @rebuild_list; # FIXME: optimize, phase out to another page. 
    5734     my $blog_id = $app->param('blog_id'); 
    5735     $app->add_return_arg('saved' => 1); 
    5736     $app->call_return; 
     5723        $entry->save() and $rebuild_these{$id} = 1; 
     5724    } 
     5725    $app->rebuild_these(\%rebuild_these, how => NEW_PHASE); 
    57375726} 
    57385727 
    57395728sub approve_item { 
    5740     $_[0]->param('approve', 1); 
    5741     $_[0]->set_item_visible; 
     5729    my $app = shift; 
     5730    $app->param('approve', 1); 
     5731    $app->set_item_visible; 
    57425732} 
    57435733 
    57445734sub unapprove_item { 
    5745     $_[0]->param('unapprove', 1); 
    5746     $_[0]->set_item_visible; 
     5735    my $app = shift; 
     5736    $app->param('unapprove', 1); 
     5737    $app->set_item_visible; 
    57475738} 
    57485739 
     
    92669257    my $ext = (File::Basename::fileparse($local_file, qr/[A-Za-z]+$/))[2]; 
    92679258 
    9268     # Does the file have dimensions with a recognized image extension? 
    9269     require MT::Asset::Image; 
    9270     my $is_image = defined($w) && defined($h) && MT::Asset::Image->can_handle($local_basename) 
    9271         ? 1 : 0; 
    9272  
    92739259    require MT::Asset; 
    9274     my $img_pkg = MT::Asset->class_handler($is_image ? 'image' : 'file'); 
    9275     my $asset = $img_pkg->new(); 
     9260    my $asset_pkg = MT::Asset->handler_for_file($local_basename); 
     9261    my $is_image = defined($w) && defined($h) 
     9262        && $asset_pkg->isa('MT::Asset::Image'); 
     9263    my $asset; 
     9264    if (!($asset = $asset_pkg->load({ file_path => $local_file, blog_id => $blog_id }))) { 
     9265        $asset = $asset_pkg->new(); 
     9266        $asset->file_path($local_file); 
     9267        $asset->file_name($local_basename); 
     9268        $asset->file_ext($ext); 
     9269        $asset->blog_id($blog_id); 
     9270        $asset->created_by($app->user->id); 
     9271    } else { 
     9272        $asset->modified_by($app->user->id); 
     9273    } 
    92769274    my $original = $asset->clone; 
    9277     $asset->blog_id($blog_id); 
    92789275    $asset->url($url); 
    9279     $asset->file_path($local_file); 
    9280     $asset->file_name($local_basename); 
    9281     $asset->file_ext($ext); 
    92829276    if ($is_image) { 
    92839277        $asset->image_width($w); 
    92849278        $asset->image_height($h); 
    92859279    } 
    9286     $asset->created_by($app->user->id); 
    92879280    $asset->save; 
    92889281    MT->run_callbacks('CMSPostSave.asset', $app, $asset, $original); 
     
    1034210335    # if there's nothing to rebuild, just return 
    1034310336    if (!keys %$rebuild_set) { 
     10337        # now, rebuild indexes for affected blogs 
     10338        my @blogs = $app->param('blog_ids'); 
     10339        foreach my $blog_id (@blogs) { 
     10340            my $blog = MT::Blog->load($blog_id) or next; 
     10341            $app->rebuild_indexes( Blog => $blog ); 
     10342        } 
    1034410343        return $app->call_return; 
    1034510344    } 
    1034610345 
    10347     if ($options{how} eq NEW_PHASE) { 
     10346    if (exists $options{how} && ($options{how} eq NEW_PHASE)) { 
    1034810347        my $params = { 
    1034910348            return_args => $app->return_args, 
     10349            blog_id => $app->param('blog_id') || 0, 
    1035010350            id => [ keys %$rebuild_set ] 
    1035110351        }; 
     
    1035410354                                                   args => $params)); 
    1035510355        return $app->build_page('rebuilding.tmpl', \%param); 
    10356  
    1035710356    } else { 
     10357        my @blogs = $app->param('blog_ids'); 
     10358        my %blogs = map { $_ => () } @blogs; 
     10359        my @set = keys %$rebuild_set; 
     10360        my @rest; 
     10361        my $entries_per_rebuild = $app->config('EntriesPerRebuild'); 
     10362        if (scalar @set > $entries_per_rebuild) { 
     10363            @rest = $set[$entries_per_rebuild..$#set]; 
     10364            @set = $set[0..$entries_per_rebuild-1]; 
     10365        } 
    1035810366        require MT::Entry; 
    10359         for my $id (keys %$rebuild_set) { 
    10360             my $e = ref $rebuild_set->{$id} ? 
    10361                 $rebuild_set->{$id} : MT::Entry->load($id, {cached_ok=>1}); 
    10362             $app->rebuild_entry(Entry => $e, BuildDependencies => 1); 
    10363         } 
     10367        for my $id (@set) { 
     10368            my $e = ref $id ? 
     10369                $id : MT::Entry->load($id, {cached_ok=>1}) or next; 
     10370            $blogs{$e->blog_id} = (); 
     10371            $app->rebuild_entry(Entry => $e, BuildDependencies => 1, 
     10372                BuildIndexes => 0); 
     10373        } 
     10374        if (@rest) { 
     10375            foreach (@rest) { 
     10376                $_ = $_->id if ref $_; 
     10377            } 
     10378        } 
     10379        my $params = { 
     10380            return_args => $app->param('return_args'), 
     10381            build_type_name => $app->translate("entry"), 
     10382            blog_id => $app->param('blog_id') || 0, 
     10383            blog_ids => [ keys %blogs ], 
     10384            id => \@rest, 
     10385        }; 
     10386        my %param = (is_full_screen => 1, 
     10387                     redirect_target => $app->uri( mode => 'rebuild_phase', 
     10388                                                   args => $params)); 
     10389        return $app->build_page('rebuilding.tmpl', \%param); 
    1036410390    } 
    1036510391}