Changeset 2737

Show
Ignore:
Timestamp:
07/09/08 02:47:30 (5 months ago)
Author:
takayama
Message:

Fixed BugId:80382
* Changed to removes fileinfo records when entry was deleted.

  • CMS, Atom and XMLRPC
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/release-41/lib/MT/ArchiveType/Category.pm

    r2335 r2737  
    143143sub archive_entries_count { 
    144144    my $obj = shift; 
    145     my ( $blog, $at, $entry ) = @_; 
     145    my ( $blog, $at, $entry, $cat ) = @_; 
    146146    return $obj->SUPER::archive_entries_count(@_) unless $entry; 
    147     my $cat = $entry->category
     147    $cat = $entry->category unless $cat
    148148    return 0 unless $cat; 
    149149    return $obj->SUPER::archive_entries_count( 
  • branches/release-41/lib/MT/ArchiveType/CategoryDaily.pm

    r2500 r2737  
    207207sub archive_entries_count { 
    208208    my $obj = shift; 
    209     my ( $blog, $at, $entry ) = @_; 
    210     my $cat = $entry->category
     209    my ( $blog, $at, $entry, $cat ) = @_; 
     210    $cat = $entry->category unless $cat
    211211    return 0 unless $cat; 
    212212    return $obj->SUPER::archive_entries_count( 
  • branches/release-41/lib/MT/ArchiveType/CategoryMonthly.pm

    r2500 r2737  
    202202sub archive_entries_count { 
    203203    my $obj = shift; 
    204     my ( $blog, $at, $entry ) = @_; 
    205     my $cat = $entry->category
     204    my ( $blog, $at, $entry, $cat ) = @_; 
     205    $cat = $entry->category unless $cat
    206206    return 0 unless $cat; 
    207207    return $obj->SUPER::archive_entries_count( 
  • branches/release-41/lib/MT/ArchiveType/CategoryWeekly.pm

    r2500 r2737  
    198198sub archive_entries_count { 
    199199    my $obj = shift; 
    200     my ( $blog, $at, $entry ) = @_; 
    201     my $cat = $entry->category
     200    my ( $blog, $at, $entry, $cat ) = @_; 
     201    $cat = $entry->category unless $cat
    202202    return 0 unless $cat; 
    203203    return $obj->SUPER::archive_entries_count( 
  • branches/release-41/lib/MT/ArchiveType/CategoryYearly.pm

    r2500 r2737  
    187187sub archive_entries_count { 
    188188    my $obj = shift; 
    189     my ( $blog, $at, $entry ) = @_; 
    190     my $cat = $entry->category
     189    my ( $blog, $at, $entry, $cat ) = @_; 
     190    $cat = $entry->category unless $cat
    191191    return 0 unless $cat; 
    192192    return $obj->SUPER::archive_entries_count( 
  • branches/release-41/lib/MT/AtomServer.pm

    r2434 r2737  
    786786    return $app->error(403, "Access denied") 
    787787        unless $app->{perms}->can_edit_entry($entry, $app->{user}); 
     788 
     789    # Delete archive file 
     790    my $blog = MT::Blog->load($entry->blog_id); 
     791    my %recip = $app->publisher->rebuild_deleted_entry( 
     792        Entry => $entry, 
     793        Blog  => $blog); 
     794 
     795    # Rebuild archives 
     796    $app->rebuild_archives( 
     797        Blog             => $blog, 
     798        Recip            => \%recip, 
     799    ) or die _fault($app->errstr); 
     800 
     801    # Remove object 
    788802    $entry->remove 
    789803        or return $app->error(500, $entry->errstr); 
    790     $app->publish($entry, 1) or return $app->error(500, $app->errstr); 
    791804    ''; 
    792805} 
  • branches/release-41/lib/MT/CMS/Entry.pm

    r2548 r2737  
    21262126    my $app = shift; 
    21272127    $app->validate_magic() or return; 
    2128  
    21292128    require MT::Blog; 
    21302129    my $q       = $app->param; 
     
    21382137 
    21392138    my %rebuild_recip; 
    2140     my $at = $blog->archive_type; 
    2141     my @at; 
    2142     if ( $at && $at ne 'None' ) { 
    2143         my @at_orig = split( /,/, $at ); 
    2144         @at = grep { $_ ne 'Individual' && $_ ne 'Page' } @at_orig; 
    2145     } 
    2146  
    21472139    for my $id ( $q->param('id') ) { 
    21482140        my $class = $app->model("entry"); 
     
    21542146            $app->translate( "Permission denied: [_1]", $app->errstr() ) ); 
    21552147 
    2156         # Remove Individual archive file. 
    2157         if ( $app->config('DeleteFilesAtRebuild') ) { 
    2158             $app->publisher->remove_entry_archive_file( Entry => $obj, ); 
    2159         } 
    2160         if (   $app->config('RebuildAtDelete') 
    2161             || $app->config('DeleteFilesAtRebuild') ) 
    2162         { 
    2163             for my $at (@at) { 
    2164                 my $archiver = $app->publisher->archiver($at); 
    2165                 next unless $archiver; 
    2166  
    2167                 # Remove archive file if archive file has not entries. 
    2168                 my $to_delete = 
    2169                     ( $archiver->archive_entries_count( $blog, $at, $obj ) == 1 ) ? 1 : 0 
    2170                     if $archiver->can('archive_entries_count'); 
    2171                 if ( $to_delete && $app->config('DeleteFilesAtRebuild') ) { 
    2172                      $app->publisher->remove_entry_archive_file( 
    2173                          Entry       => $obj, 
    2174                          ArchiveType => $at 
    2175                      ); 
    2176                 } 
    2177                 next if $to_delete; 
    2178  
    2179                 # Make rebuild recip 
    2180                 if ( $app->config('RebuildAtDelete') ) { 
    2181                     my ( $start, $end ) = $archiver->date_range( $obj->authored_on ) 
    2182                         if $archiver->date_based() && $archiver->can('date_range'); 
    2183  
    2184                     if ( $archiver->category_based() ) { 
    2185                         my $categories = $obj->categories(); 
    2186                         for my $cat (@$categories) { 
    2187                             if ( $archiver->date_based() ) { 
    2188                                 $rebuild_recip{$at}{ $cat->id }{ $start . $end } 
    2189                                   {'Start'} = $start; 
    2190                                 $rebuild_recip{$at}{ $cat->id }{ $start . $end } 
    2191                                   {'End'} = $end; 
    2192                                 $rebuild_recip{$at}{ $cat->id }{ $start . $end } 
    2193                                   {'File'} = 
    2194                                   MT::Util::archive_file_for( $obj, $blog, $at, 
    2195                                     $cat, undef, undef, undef ); 
    2196                             } 
    2197                             else { 
    2198                                 $rebuild_recip{$at}{ $cat->id }{id} = $cat->id; 
    2199                                 $rebuild_recip{$at}{ $cat->id }{'File'} = 
    2200                                   MT::Util::archive_file_for( $obj, $blog, $at, 
    2201                                     $cat, undef, undef, undef ); 
    2202                             } 
    2203                         } 
    2204                     } 
    2205                     elsif ( $archiver->author_based() ) { 
    2206                         if ( $archiver->date_based() ) { 
    2207                             $rebuild_recip{$at}{ $obj->author->id }{ $start . $end } 
    2208                               {'Start'} = $start; 
    2209                             $rebuild_recip{$at}{ $obj->author->id }{ $start . $end } 
    2210                               {'End'} = $end; 
    2211                             $rebuild_recip{$at}{ $obj->author->id }{ $start . $end } 
    2212                               {'File'} = 
    2213                               MT::Util::archive_file_for( $obj, $blog, $at, undef, 
    2214                                 undef, undef, $obj->author ); 
    2215                         } 
    2216                         else { 
    2217                             $rebuild_recip{$at}{ $obj->author->id }{id} = 
    2218                               $obj->author->id; 
    2219                             $rebuild_recip{$at}{ $obj->author->id }{'File'} = 
    2220                               MT::Util::archive_file_for( $obj, $blog, $at, undef, 
    2221                                 undef, undef, $obj->author ); 
    2222                         } 
    2223                     } 
    2224                     elsif ( $archiver->date_based() ) { 
    2225                         $rebuild_recip{$at}{ $start . $end }{'Start'} = $start; 
    2226                         $rebuild_recip{$at}{ $start . $end }{'End'}   = $end; 
    2227                         $rebuild_recip{$at}{ $start . $end }{'File'} = 
    2228                           MT::Util::archive_file_for( $obj, $blog, $at, undef, 
    2229                             undef, undef, undef ); 
    2230                     } 
    2231                     if ( my $prev = $obj->previous(1) ) { 
    2232                         $rebuild_recip{Individual}{ $prev->id }{id} = $prev->id; 
    2233                         $rebuild_recip{Individual}{ $prev->id }{'File'} = 
    2234                           MT::Util::archive_file_for( $prev, $blog, 'Individual', 
    2235                             undef, undef, undef, undef ); 
    2236                     } 
    2237                     if ( my $next = $obj->next(1) ) { 
    2238                         $rebuild_recip{Individual}{ $next->id }{id} = $next->id; 
    2239                         $rebuild_recip{Individual}{ $next->id }{'File'} = 
    2240                           MT::Util::archive_file_for( $next, $blog, 'Individual', 
    2241                             undef, undef, undef, undef ); 
    2242                     } 
    2243                 } 
    2244             } 
    2245         } 
     2148        my %recip = $app->publisher->rebuild_deleted_entry( 
     2149            Entry => $obj, 
     2150            Blog  => $blog); 
    22462151 
    22472152        # Remove object from database 
  • branches/release-41/lib/MT/WeblogPublisher.pm

    r2727 r2737  
    349349    } 
    350350    1; 
     351} 
     352 
     353sub remove_fileinfo { 
     354    my $mt    = shift; 
     355    my %param = @_; 
     356    my $at    = $param{ArchiveType} 
     357      or return $mt->error( 
     358        MT->translate( "Parameter '[_1]' is required", 'ArchiveType' ) ); 
     359    my $blog_id = $param{Blog} 
     360      or return $mt->error( 
     361        MT->translate( "Parameter '[_1]' is required", 'Blog' ) ); 
     362    my $entry_id = $param{Entry}, my $author_id = $param{Author}; 
     363    my $start    = $param{StartDate}; 
     364    my $cat_id   = $param{Category}; 
     365 
     366    require MT::FileInfo; 
     367    my @finfo = MT::FileInfo->load( 
     368        { 
     369            archive_type => $at, 
     370            blog_id      => $blog_id, 
     371            ( $entry_id ? ( entry_id    => $entry_id ) : () ), 
     372            ( $cat_id   ? ( category_id => $cat_id )   : () ), 
     373            ( $start    ? ( startdate   => $start )    : () ), 
     374        } 
     375    ); 
     376 
     377    for my $f (@finfo) { 
     378        $f->remove; 
     379    } 
     380    1; 
     381} 
     382 
     383# rebuild_deleted_entry 
     384# 
     385# $mt->rebuild_deleted_entry( 
     386#                    Entry => $entry | $entry_id, 
     387#                    Blog => [ $blog | $blog_id ], 
     388#                    ); 
     389sub rebuild_deleted_entry { 
     390    my $mt    = shift; 
     391    my $app   = MT->instance; 
     392    my %param = @_; 
     393    my $entry = $param{Entry} 
     394      or return $mt->error( 
     395        MT->translate( "Parameter '[_1]' is required", 'Entry' ) ); 
     396    require MT::Entry; 
     397    $entry = MT::Entry->load($entry) unless ref $entry; 
     398    return unless $entry; 
     399 
     400    my $blog; 
     401    unless ( $blog = $param{Blog} ) { 
     402        require MT::Blog; 
     403        my $blog_id = $entry->blog_id; 
     404        $blog = MT::Blog->load($blog_id) 
     405          or return $mt->error( 
     406            MT->translate( 
     407                "Load of blog '[_1]' failed: [_2]", $blog_id, 
     408                MT::Blog->errstr 
     409            ) 
     410          ); 
     411    } 
     412 
     413    my %rebuild_recip; 
     414    my $at = $blog->archive_type; 
     415    my @at; 
     416    if ( $at && $at ne 'None' ) { 
     417        my @at_orig = split( /,/, $at ); 
     418        @at = grep { $_ ne 'Individual' && $_ ne 'Page' } @at_orig; 
     419    } 
     420 
     421    # Remove Individual archive file. 
     422    if ( $app->config('DeleteFilesAtRebuild') ) { 
     423        $mt->remove_entry_archive_file( Entry => $entry, ); 
     424    } 
     425 
     426    # Remove Individual fileinfo records. 
     427    $mt->remove_fileinfo( 
     428        ArchiveType => 'Individual', 
     429        Blog        => $blog->id, 
     430        Entry       => $entry->id 
     431    ); 
     432 
     433    require MT::Util; 
     434    for my $at (@at) { 
     435        my $archiver = $mt->archiver($at); 
     436        next unless $archiver; 
     437 
     438        my ( $start, $end ) = $archiver->date_range( $entry->authored_on ) 
     439          if $archiver->date_based() && $archiver->can('date_range'); 
     440 
     441        # Remove archive file if archive file has not entries. 
     442        if ( $archiver->category_based() ) { 
     443            my $categories = $entry->categories(); 
     444            for my $cat (@$categories) { 
     445                if ( 
     446                    ( $archiver->can('archive_entries_count') ) 
     447                    && ( 
     448                        $archiver->archive_entries_count( $blog, $at, $entry, 
     449                            $cat ) == 1 
     450                    ) 
     451                  ) 
     452                { 
     453                    $mt->remove_fileinfo( 
     454                        ArchiveType => $at, 
     455                        Blog        => $blog->id, 
     456                        Category    => $cat->id, 
     457                        ( 
     458                            $archiver->date_based() 
     459                            ? ( startdate => $start ) 
     460                            : () 
     461                        ), 
     462                    ); 
     463                    if ( $app->config('DeleteFilesAtRebuild') ) { 
     464                        $mt->remove_entry_archive_file( 
     465                            Entry       => $entry, 
     466                            ArchiveType => $at, 
     467                            Category    => $cat, 
     468                        ); 
     469                    } 
     470                } 
     471                else { 
     472                    if ( $app->config('RebuildAtDelete') ) { 
     473                        if ( $archiver->date_based() ) { 
     474                            $rebuild_recip{$at}{ $cat->id }{ $start . $end } 
     475                              {'Start'} = $start; 
     476                            $rebuild_recip{$at}{ $cat->id }{ $start . $end } 
     477                              {'End'} = $end; 
     478                            $rebuild_recip{$at}{ $cat->id }{ $start . $end } 
     479                              {'File'} = MT::Util::archive_file_for( 
     480                                $entry, $blog, $at, $cat, 
     481                                undef,  undef, undef 
     482                              ); 
     483                        } 
     484                        else { 
     485                            $rebuild_recip{$at}{ $cat->id }{id} = $cat->id; 
     486                            $rebuild_recip{$at}{ $cat->id }{'File'} = 
     487                              MT::Util::archive_file_for( 
     488                                $entry, $blog, $at, $cat, 
     489                                undef,  undef, undef 
     490                              ); 
     491                        } 
     492                    } 
     493                } 
     494            } 
     495        } 
     496        else { 
     497            if ( ( $archiver->can('archive_entries_count') ) 
     498                && ( $archiver->archive_entries_count( $blog, $at, $entry ) == 
     499                    1 ) ) 
     500            { 
     501 
     502                # Remove archives fileinfo records. 
     503                $mt->remove_fileinfo( 
     504                    ArchiveType => $at, 
     505                    Blog        => $blog->id, 
     506                    ( 
     507                        $archiver->author_based() 
     508                        ? ( author_id => $entry->author->id ) 
     509                        : () 
     510                    ), 
     511                    ( $archiver->date_based() ? ( startdate => $start ) : () ), 
     512                ); 
     513                if ( $app->config('DeleteFilesAtRebuild') ) { 
     514                    $mt->remove_entry_archive_file( 
     515                        Entry       => $entry, 
     516                        ArchiveType => $at 
     517                    ); 
     518                } 
     519            } 
     520            else { 
     521                if ( $app->config('RebuildAtDelete') ) { 
     522                    if ( $archiver->author_based() ) { 
     523                        if ( $archiver->date_based() ) { 
     524                            $rebuild_recip{$at}{ $entry->author->id } 
     525                              { $start . $end }{'Start'} = $start; 
     526                            $rebuild_recip{$at}{ $entry->author->id } 
     527                              { $start . $end }{'End'} = $end; 
     528                            $rebuild_recip{$at}{ $entry->author->id } 
     529                              { $start . $end }{'File'} = 
     530                              MT::Util::archive_file_for( $entry, $blog, $at, 
     531                                undef, undef, undef, $entry->author ); 
     532                        } 
     533                        else { 
     534                            $rebuild_recip{$at}{ $entry->author->id }{id} = 
     535                              $entry->author->id; 
     536                            $rebuild_recip{$at}{ $entry->author->id }{'File'} = 
     537                              MT::Util::archive_file_for( $entry, $blog, $at, 
     538                                undef, undef, undef, $entry->author ); 
     539                        } 
     540                    } 
     541                    elsif ( $archiver->date_based() ) { 
     542                        $rebuild_recip{$at}{ $start . $end }{'Start'} = $start; 
     543                        $rebuild_recip{$at}{ $start . $end }{'End'}   = $end; 
     544                        $rebuild_recip{$at}{ $start . $end }{'File'} = 
     545                          MT::Util::archive_file_for( $entry, $blog, $at, undef, 
     546                            undef, undef, undef ); 
     547                    } 
     548                    if ( my $prev = $entry->previous(1) ) { 
     549                        $rebuild_recip{Individual}{ $prev->id }{id} = $prev->id; 
     550                        $rebuild_recip{Individual}{ $prev->id }{'File'} = 
     551                          MT::Util::archive_file_for( $prev, $blog, 
     552                            'Individual', undef, undef, undef, undef ); 
     553                    } 
     554                    if ( my $next = $entry->next(1) ) { 
     555                        $rebuild_recip{Individual}{ $next->id }{id} = $next->id; 
     556                        $rebuild_recip{Individual}{ $next->id }{'File'} = 
     557                          MT::Util::archive_file_for( $next, $blog, 
     558                            'Individual', undef, undef, undef, undef ); 
     559                    } 
     560                } 
     561            } 
     562        } 
     563    } 
     564 
     565    return %rebuild_recip; 
    351566} 
    352567 
     
    552767 
    553768### Recip hash 
    554 ### {ArchiveType - {Category-id} - {Date key} - {Start} 
    555 ###                                           - {End} 
    556 ###                                           - {File} 
    557 ###                              - {File} 
    558 ###              - {Author-id}   - {Date key} - {Start} 
    559 ###                                           - {End} 
    560 ###                                           - {File} 
    561 ###                              - {File} 
    562 ###              - {Date key}    - {Start} 
    563 ###                              - {End} 
    564 ###                              - {File} 
     769### {ArchiveType} - {Category-id} - {Date key} - {Start} 
     770###                                            - {End} 
     771###                                            - {File} 
     772###                               - {File} 
     773###               - {Author-id}   - {Date key} - {Start} 
     774###                                            - {End} 
     775###                                            - {File} 
     776###                               - {File} 
     777###               - {Date key}    - {Start} 
     778###                               - {End} 
     779###                               - {File} 
     780###               - {entry-id}    - {id} 
     781###                               - {File} 
    565782### 
    566783sub rebuild_archives { 
  • branches/release-41/lib/MT/XMLRPCServer.pm

    r2709 r2737  
    687687    die _fault(MT->translate("Permission denied.")) 
    688688        unless $perms && $perms->can_edit_entry($entry, $author); 
     689 
     690    # Delete archive file 
     691    my $blog = MT::Blog->load($entry->blog_id); 
     692    my %recip = $mt->publisher->rebuild_deleted_entry( 
     693        Entry => $entry, 
     694        Blog  => $blog); 
     695 
     696    # Rebuild archives 
     697    $mt->rebuild_archives( 
     698        Blog             => $blog, 
     699        Recip            => \%recip, 
     700    ) or die _fault($class->errstr); 
     701 
     702    # Remove object 
    689703    $entry->remove; 
    690704 
     
    696710    }); 
    697711 
    698     if ($publish) { 
    699         $class->_publish($mt, $entry, 1) or die _fault($class->errstr); 
    700     } 
    701712    SOAP::Data->type(boolean => 1); 
    702713}