Index: /branches/release-41/lib/MT/ArchiveType/Category.pm
===================================================================
--- /branches/release-41/lib/MT/ArchiveType/Category.pm (revision 2335)
+++ /branches/release-41/lib/MT/ArchiveType/Category.pm (revision 2737)
@@ -143,7 +143,7 @@
 sub archive_entries_count {
     my $obj = shift;
-    my ( $blog, $at, $entry ) = @_;
+    my ( $blog, $at, $entry, $cat ) = @_;
     return $obj->SUPER::archive_entries_count(@_) unless $entry;
-    my $cat = $entry->category;
+    $cat = $entry->category unless $cat;
     return 0 unless $cat;
     return $obj->SUPER::archive_entries_count(
Index: /branches/release-41/lib/MT/ArchiveType/CategoryMonthly.pm
===================================================================
--- /branches/release-41/lib/MT/ArchiveType/CategoryMonthly.pm (revision 2500)
+++ /branches/release-41/lib/MT/ArchiveType/CategoryMonthly.pm (revision 2737)
@@ -202,6 +202,6 @@
 sub archive_entries_count {
     my $obj = shift;
-    my ( $blog, $at, $entry ) = @_;
-    my $cat = $entry->category;
+    my ( $blog, $at, $entry, $cat ) = @_;
+    $cat = $entry->category unless $cat;
     return 0 unless $cat;
     return $obj->SUPER::archive_entries_count(
Index: /branches/release-41/lib/MT/ArchiveType/CategoryWeekly.pm
===================================================================
--- /branches/release-41/lib/MT/ArchiveType/CategoryWeekly.pm (revision 2500)
+++ /branches/release-41/lib/MT/ArchiveType/CategoryWeekly.pm (revision 2737)
@@ -198,6 +198,6 @@
 sub archive_entries_count {
     my $obj = shift;
-    my ( $blog, $at, $entry ) = @_;
-    my $cat = $entry->category;
+    my ( $blog, $at, $entry, $cat ) = @_;
+    $cat = $entry->category unless $cat;
     return 0 unless $cat;
     return $obj->SUPER::archive_entries_count(
Index: /branches/release-41/lib/MT/ArchiveType/CategoryDaily.pm
===================================================================
--- /branches/release-41/lib/MT/ArchiveType/CategoryDaily.pm (revision 2500)
+++ /branches/release-41/lib/MT/ArchiveType/CategoryDaily.pm (revision 2737)
@@ -207,6 +207,6 @@
 sub archive_entries_count {
     my $obj = shift;
-    my ( $blog, $at, $entry ) = @_;
-    my $cat = $entry->category;
+    my ( $blog, $at, $entry, $cat ) = @_;
+    $cat = $entry->category unless $cat;
     return 0 unless $cat;
     return $obj->SUPER::archive_entries_count(
Index: /branches/release-41/lib/MT/ArchiveType/CategoryYearly.pm
===================================================================
--- /branches/release-41/lib/MT/ArchiveType/CategoryYearly.pm (revision 2500)
+++ /branches/release-41/lib/MT/ArchiveType/CategoryYearly.pm (revision 2737)
@@ -187,6 +187,6 @@
 sub archive_entries_count {
     my $obj = shift;
-    my ( $blog, $at, $entry ) = @_;
-    my $cat = $entry->category;
+    my ( $blog, $at, $entry, $cat ) = @_;
+    $cat = $entry->category unless $cat;
     return 0 unless $cat;
     return $obj->SUPER::archive_entries_count(
Index: /branches/release-41/lib/MT/CMS/Entry.pm
===================================================================
--- /branches/release-41/lib/MT/CMS/Entry.pm (revision 2548)
+++ /branches/release-41/lib/MT/CMS/Entry.pm (revision 2737)
@@ -2126,5 +2126,4 @@
     my $app = shift;
     $app->validate_magic() or return;
-
     require MT::Blog;
     my $q       = $app->param;
@@ -2138,11 +2137,4 @@
 
     my %rebuild_recip;
-    my $at = $blog->archive_type;
-    my @at;
-    if ( $at && $at ne 'None' ) {
-        my @at_orig = split( /,/, $at );
-        @at = grep { $_ ne 'Individual' && $_ ne 'Page' } @at_orig;
-    }
-
     for my $id ( $q->param('id') ) {
         my $class = $app->model("entry");
@@ -2154,94 +2146,7 @@
             $app->translate( "Permission denied: [_1]", $app->errstr() ) );
 
-        # Remove Individual archive file.
-        if ( $app->config('DeleteFilesAtRebuild') ) {
-            $app->publisher->remove_entry_archive_file( Entry => $obj, );
-        }
-        if (   $app->config('RebuildAtDelete')
-            || $app->config('DeleteFilesAtRebuild') )
-        {
-            for my $at (@at) {
-                my $archiver = $app->publisher->archiver($at);
-                next unless $archiver;
-
-                # Remove archive file if archive file has not entries.
-                my $to_delete =
-                    ( $archiver->archive_entries_count( $blog, $at, $obj ) == 1 ) ? 1 : 0
-                    if $archiver->can('archive_entries_count');
-                if ( $to_delete && $app->config('DeleteFilesAtRebuild') ) {
-                     $app->publisher->remove_entry_archive_file(
-                         Entry       => $obj,
-                         ArchiveType => $at
-                     );
-                }
-                next if $to_delete;
-
-                # Make rebuild recip
-                if ( $app->config('RebuildAtDelete') ) {
-                    my ( $start, $end ) = $archiver->date_range( $obj->authored_on )
-                        if $archiver->date_based() && $archiver->can('date_range');
-
-                    if ( $archiver->category_based() ) {
-                        my $categories = $obj->categories();
-                        for my $cat (@$categories) {
-                            if ( $archiver->date_based() ) {
-                                $rebuild_recip{$at}{ $cat->id }{ $start . $end }
-                                  {'Start'} = $start;
-                                $rebuild_recip{$at}{ $cat->id }{ $start . $end }
-                                  {'End'} = $end;
-                                $rebuild_recip{$at}{ $cat->id }{ $start . $end }
-                                  {'File'} =
-                                  MT::Util::archive_file_for( $obj, $blog, $at,
-                                    $cat, undef, undef, undef );
-                            }
-                            else {
-                                $rebuild_recip{$at}{ $cat->id }{id} = $cat->id;
-                                $rebuild_recip{$at}{ $cat->id }{'File'} =
-                                  MT::Util::archive_file_for( $obj, $blog, $at,
-                                    $cat, undef, undef, undef );
-                            }
-                        }
-                    }
-                    elsif ( $archiver->author_based() ) {
-                        if ( $archiver->date_based() ) {
-                            $rebuild_recip{$at}{ $obj->author->id }{ $start . $end }
-                              {'Start'} = $start;
-                            $rebuild_recip{$at}{ $obj->author->id }{ $start . $end }
-                              {'End'} = $end;
-                            $rebuild_recip{$at}{ $obj->author->id }{ $start . $end }
-                              {'File'} =
-                              MT::Util::archive_file_for( $obj, $blog, $at, undef,
-                                undef, undef, $obj->author );
-                        }
-                        else {
-                            $rebuild_recip{$at}{ $obj->author->id }{id} =
-                              $obj->author->id;
-                            $rebuild_recip{$at}{ $obj->author->id }{'File'} =
-                              MT::Util::archive_file_for( $obj, $blog, $at, undef,
-                                undef, undef, $obj->author );
-                        }
-                    }
-                    elsif ( $archiver->date_based() ) {
-                        $rebuild_recip{$at}{ $start . $end }{'Start'} = $start;
-                        $rebuild_recip{$at}{ $start . $end }{'End'}   = $end;
-                        $rebuild_recip{$at}{ $start . $end }{'File'} =
-                          MT::Util::archive_file_for( $obj, $blog, $at, undef,
-                            undef, undef, undef );
-                    }
-                    if ( my $prev = $obj->previous(1) ) {
-                        $rebuild_recip{Individual}{ $prev->id }{id} = $prev->id;
-                        $rebuild_recip{Individual}{ $prev->id }{'File'} =
-                          MT::Util::archive_file_for( $prev, $blog, 'Individual',
-                            undef, undef, undef, undef );
-                    }
-                    if ( my $next = $obj->next(1) ) {
-                        $rebuild_recip{Individual}{ $next->id }{id} = $next->id;
-                        $rebuild_recip{Individual}{ $next->id }{'File'} =
-                          MT::Util::archive_file_for( $next, $blog, 'Individual',
-                            undef, undef, undef, undef );
-                    }
-                }
-            }
-        }
+        my %recip = $app->publisher->rebuild_deleted_entry(
+            Entry => $obj,
+            Blog  => $blog);
 
         # Remove object from database
Index: /branches/release-41/lib/MT/AtomServer.pm
===================================================================
--- /branches/release-41/lib/MT/AtomServer.pm (revision 2434)
+++ /branches/release-41/lib/MT/AtomServer.pm (revision 2737)
@@ -786,7 +786,20 @@
     return $app->error(403, "Access denied")
         unless $app->{perms}->can_edit_entry($entry, $app->{user});
+
+    # Delete archive file
+    my $blog = MT::Blog->load($entry->blog_id);
+    my %recip = $app->publisher->rebuild_deleted_entry(
+        Entry => $entry,
+        Blog  => $blog);
+
+    # Rebuild archives
+    $app->rebuild_archives(
+        Blog             => $blog,
+        Recip            => \%recip,
+    ) or die _fault($app->errstr);
+
+    # Remove object
     $entry->remove
         or return $app->error(500, $entry->errstr);
-    $app->publish($entry, 1) or return $app->error(500, $app->errstr);
     '';
 }
Index: /branches/release-41/lib/MT/XMLRPCServer.pm
===================================================================
--- /branches/release-41/lib/MT/XMLRPCServer.pm (revision 2709)
+++ /branches/release-41/lib/MT/XMLRPCServer.pm (revision 2737)
@@ -687,4 +687,18 @@
     die _fault(MT->translate("Permission denied."))
         unless $perms && $perms->can_edit_entry($entry, $author);
+
+    # Delete archive file
+    my $blog = MT::Blog->load($entry->blog_id);
+    my %recip = $mt->publisher->rebuild_deleted_entry(
+        Entry => $entry,
+        Blog  => $blog);
+
+    # Rebuild archives
+    $mt->rebuild_archives(
+        Blog             => $blog,
+        Recip            => \%recip,
+    ) or die _fault($class->errstr);
+
+    # Remove object
     $entry->remove;
 
@@ -696,7 +710,4 @@
     });
 
-    if ($publish) {
-        $class->_publish($mt, $entry, 1) or die _fault($class->errstr);
-    }
     SOAP::Data->type(boolean => 1);
 }
Index: /branches/release-41/lib/MT/WeblogPublisher.pm
===================================================================
--- /branches/release-41/lib/MT/WeblogPublisher.pm (revision 2727)
+++ /branches/release-41/lib/MT/WeblogPublisher.pm (revision 2737)
@@ -349,4 +349,219 @@
     }
     1;
+}
+
+sub remove_fileinfo {
+    my $mt    = shift;
+    my %param = @_;
+    my $at    = $param{ArchiveType}
+      or return $mt->error(
+        MT->translate( "Parameter '[_1]' is required", 'ArchiveType' ) );
+    my $blog_id = $param{Blog}
+      or return $mt->error(
+        MT->translate( "Parameter '[_1]' is required", 'Blog' ) );
+    my $entry_id = $param{Entry}, my $author_id = $param{Author};
+    my $start    = $param{StartDate};
+    my $cat_id   = $param{Category};
+
+    require MT::FileInfo;
+    my @finfo = MT::FileInfo->load(
+        {
+            archive_type => $at,
+            blog_id      => $blog_id,
+            ( $entry_id ? ( entry_id    => $entry_id ) : () ),
+            ( $cat_id   ? ( category_id => $cat_id )   : () ),
+            ( $start    ? ( startdate   => $start )    : () ),
+        }
+    );
+
+    for my $f (@finfo) {
+        $f->remove;
+    }
+    1;
+}
+
+# rebuild_deleted_entry
+#
+# $mt->rebuild_deleted_entry(
+#                    Entry => $entry | $entry_id,
+#                    Blog => [ $blog | $blog_id ],
+#                    );
+sub rebuild_deleted_entry {
+    my $mt    = shift;
+    my $app   = MT->instance;
+    my %param = @_;
+    my $entry = $param{Entry}
+      or return $mt->error(
+        MT->translate( "Parameter '[_1]' is required", 'Entry' ) );
+    require MT::Entry;
+    $entry = MT::Entry->load($entry) unless ref $entry;
+    return unless $entry;
+
+    my $blog;
+    unless ( $blog = $param{Blog} ) {
+        require MT::Blog;
+        my $blog_id = $entry->blog_id;
+        $blog = MT::Blog->load($blog_id)
+          or return $mt->error(
+            MT->translate(
+                "Load of blog '[_1]' failed: [_2]", $blog_id,
+                MT::Blog->errstr
+            )
+          );
+    }
+
+    my %rebuild_recip;
+    my $at = $blog->archive_type;
+    my @at;
+    if ( $at && $at ne 'None' ) {
+        my @at_orig = split( /,/, $at );
+        @at = grep { $_ ne 'Individual' && $_ ne 'Page' } @at_orig;
+    }
+
+    # Remove Individual archive file.
+    if ( $app->config('DeleteFilesAtRebuild') ) {
+        $mt->remove_entry_archive_file( Entry => $entry, );
+    }
+
+    # Remove Individual fileinfo records.
+    $mt->remove_fileinfo(
+        ArchiveType => 'Individual',
+        Blog        => $blog->id,
+        Entry       => $entry->id
+    );
+
+    require MT::Util;
+    for my $at (@at) {
+        my $archiver = $mt->archiver($at);
+        next unless $archiver;
+
+        my ( $start, $end ) = $archiver->date_range( $entry->authored_on )
+          if $archiver->date_based() && $archiver->can('date_range');
+
+        # Remove archive file if archive file has not entries.
+        if ( $archiver->category_based() ) {
+            my $categories = $entry->categories();
+            for my $cat (@$categories) {
+                if (
+                    ( $archiver->can('archive_entries_count') )
+                    && (
+                        $archiver->archive_entries_count( $blog, $at, $entry,
+                            $cat ) == 1
+                    )
+                  )
+                {
+                    $mt->remove_fileinfo(
+                        ArchiveType => $at,
+                        Blog        => $blog->id,
+                        Category    => $cat->id,
+                        (
+                            $archiver->date_based()
+                            ? ( startdate => $start )
+                            : ()
+                        ),
+                    );
+                    if ( $app->config('DeleteFilesAtRebuild') ) {
+                        $mt->remove_entry_archive_file(
+                            Entry       => $entry,
+                            ArchiveType => $at,
+                            Category    => $cat,
+                        );
+                    }
+                }
+                else {
+                    if ( $app->config('RebuildAtDelete') ) {
+                        if ( $archiver->date_based() ) {
+                            $rebuild_recip{$at}{ $cat->id }{ $start . $end }
+                              {'Start'} = $start;
+                            $rebuild_recip{$at}{ $cat->id }{ $start . $end }
+                              {'End'} = $end;
+                            $rebuild_recip{$at}{ $cat->id }{ $start . $end }
+                              {'File'} = MT::Util::archive_file_for(
+                                $entry, $blog, $at, $cat,
+                                undef,  undef, undef
+                              );
+                        }
+                        else {
+                            $rebuild_recip{$at}{ $cat->id }{id} = $cat->id;
+                            $rebuild_recip{$at}{ $cat->id }{'File'} =
+                              MT::Util::archive_file_for(
+                                $entry, $blog, $at, $cat,
+                                undef,  undef, undef
+                              );
+                        }
+                    }
+                }
+            }
+        }
+        else {
+            if ( ( $archiver->can('archive_entries_count') )
+                && ( $archiver->archive_entries_count( $blog, $at, $entry ) ==
+                    1 ) )
+            {
+
+                # Remove archives fileinfo records.
+                $mt->remove_fileinfo(
+                    ArchiveType => $at,
+                    Blog        => $blog->id,
+                    (
+                        $archiver->author_based()
+                        ? ( author_id => $entry->author->id )
+                        : ()
+                    ),
+                    ( $archiver->date_based() ? ( startdate => $start ) : () ),
+                );
+                if ( $app->config('DeleteFilesAtRebuild') ) {
+                    $mt->remove_entry_archive_file(
+                        Entry       => $entry,
+                        ArchiveType => $at
+                    );
+                }
+            }
+            else {
+                if ( $app->config('RebuildAtDelete') ) {
+                    if ( $archiver->author_based() ) {
+                        if ( $archiver->date_based() ) {
+                            $rebuild_recip{$at}{ $entry->author->id }
+                              { $start . $end }{'Start'} = $start;
+                            $rebuild_recip{$at}{ $entry->author->id }
+                              { $start . $end }{'End'} = $end;
+                            $rebuild_recip{$at}{ $entry->author->id }
+                              { $start . $end }{'File'} =
+                              MT::Util::archive_file_for( $entry, $blog, $at,
+                                undef, undef, undef, $entry->author );
+                        }
+                        else {
+                            $rebuild_recip{$at}{ $entry->author->id }{id} =
+                              $entry->author->id;
+                            $rebuild_recip{$at}{ $entry->author->id }{'File'} =
+                              MT::Util::archive_file_for( $entry, $blog, $at,
+                                undef, undef, undef, $entry->author );
+                        }
+                    }
+                    elsif ( $archiver->date_based() ) {
+                        $rebuild_recip{$at}{ $start . $end }{'Start'} = $start;
+                        $rebuild_recip{$at}{ $start . $end }{'End'}   = $end;
+                        $rebuild_recip{$at}{ $start . $end }{'File'} =
+                          MT::Util::archive_file_for( $entry, $blog, $at, undef,
+                            undef, undef, undef );
+                    }
+                    if ( my $prev = $entry->previous(1) ) {
+                        $rebuild_recip{Individual}{ $prev->id }{id} = $prev->id;
+                        $rebuild_recip{Individual}{ $prev->id }{'File'} =
+                          MT::Util::archive_file_for( $prev, $blog,
+                            'Individual', undef, undef, undef, undef );
+                    }
+                    if ( my $next = $entry->next(1) ) {
+                        $rebuild_recip{Individual}{ $next->id }{id} = $next->id;
+                        $rebuild_recip{Individual}{ $next->id }{'File'} =
+                          MT::Util::archive_file_for( $next, $blog,
+                            'Individual', undef, undef, undef, undef );
+                    }
+                }
+            }
+        }
+    }
+
+    return %rebuild_recip;
 }
 
@@ -552,15 +767,17 @@
 
 ### Recip hash
-### {ArchiveType - {Category-id} - {Date key} - {Start}
-###                                           - {End}
-###                                           - {File}
-###                              - {File}
-###              - {Author-id}   - {Date key} - {Start}
-###                                           - {End}
-###                                           - {File}
-###                              - {File}
-###              - {Date key}    - {Start}
-###                              - {End}
-###                              - {File}
+### {ArchiveType} - {Category-id} - {Date key} - {Start}
+###                                            - {End}
+###                                            - {File}
+###                               - {File}
+###               - {Author-id}   - {Date key} - {Start}
+###                                            - {End}
+###                                            - {File}
+###                               - {File}
+###               - {Date key}    - {Start}
+###                               - {End}
+###                               - {File}
+###               - {entry-id}    - {id}
+###                               - {File}
 ###
 sub rebuild_archives {
