Index: branches/release-35/lib/MT/TemplateMap.pm
===================================================================
--- branches/release-35/lib/MT/TemplateMap.pm (revision 1873)
+++ branches/release-35/lib/MT/TemplateMap.pm (revision 1957)
@@ -46,5 +46,7 @@
 sub save {
     my $map = shift;
-    $map->SUPER::save();
+    my $res = $map->SUPER::save();
+    return $res unless $res;
+
     my $at   = $map->archive_type;
     my $blog = MT->model('blog')->load($map->blog_id)
@@ -56,6 +58,10 @@
                 if $blog_at ne 'None';
     push @ats, $map->archive_type;
-    $blog->archive_type(join ',', @ats);
-    $blog->save;
+    my $new_at = join ',', @ats;
+    if ($new_at ne $blog_at) {
+        $blog->archive_type($new_at);
+        $blog->save;
+    }
+    return 1;
 }
 
Index: branches/release-35/lib/MT/CMS/Blog.pm
===================================================================
--- branches/release-35/lib/MT/CMS/Blog.pm (revision 1951)
+++ branches/release-35/lib/MT/CMS/Blog.pm (revision 1957)
@@ -1836,38 +1836,4 @@
 }
 
-sub _switch_publish_options {
-    my ( $blog, $current, $new, $dcty ) = @_;
-    require MT::Template;
-    require MT::TemplateMap;
-    my @tmpl = MT::Template->load( { blog_id => $blog->id } );
-    my $pref_at = $blog->archive_type_preferred || '';
-    for my $tmpl (@tmpl) {
-        # FIXME: enumeration of types
-        next
-          if !( $tmpl->type =~ m/^(individual|page|category|archive)$/ );
-        # if ( $tmpl->build_type == $current ) {
-        #     $tmpl->build_type($new);
-        #     $tmpl->save;
-        # }
-        my @tmpl_maps = MT::TemplateMap->load( { template_id => $tmpl->id } );
-        foreach my $tmpl_map (@tmpl_maps) {
-            if ($dcty eq 'async_partial') {
-                # build the preferred individual/page archives synchronously
-                if (($tmpl_map->archive_type =~ m/^(Individual|Page)$/) &&
-                    ($tmpl_map->is_preferred)) {
-                    $tmpl_map->build_type(MT::PublishOption::ONDEMAND());
-                    $tmpl_map->save;
-                    next;
-                }
-            }
-            if ( $tmpl_map->build_type != $new ) {
-                $tmpl_map->build_type($new);
-                $tmpl_map->save;
-            }
-        }
-    }
-    1;
-}
-
 sub cfg_archives_save {
     my $app = shift;
@@ -1895,25 +1861,8 @@
         $app->translate( "Saving blog failed: [_1]", $blog->errstr ) );
 
-    require MT::PublishOption;
-    if ($pq) {
-        _switch_publish_options(
-            $blog,
-            MT::PublishOption::ONDEMAND(),
-            MT::PublishOption::ASYNC(),
-            $dcty,
-        );
-    }
-    else {
-        _switch_publish_options(
-            $blog,
-            MT::PublishOption::ASYNC(),
-            MT::PublishOption::ONDEMAND(),
-            $dcty,
-        );
-    }
-
     1;
 }
 
+# FIXME: Faulty, since it doesn't take into account module includes
 sub RegistrationAffectsArchives {
     my ( $blog_id, $archive_type ) = @_;
@@ -1966,5 +1915,4 @@
                 $tmpl->build_type(MT::PublishOption::ONDEMAND());
             }
-            $tmpl->build_dynamic(0);
             $tmpl->save();
         }
@@ -1979,5 +1927,4 @@
         for my $tmpl (@templates) {
             $tmpl->build_type( $tmpl->type ne 'index' ? MT::PublishOption::DYNAMIC() : MT::PublishOption::ONDEMAND() );
-            $tmpl->build_dynamic( $tmpl->type ne 'index' ? 1 : 0 );
             $tmpl->save();
         }
@@ -1995,5 +1942,4 @@
         for my $tmpl (@templates) {
             $tmpl->build_type( MT::PublishOption::DYNAMIC() );
-            $tmpl->build_dynamic(1);
             $tmpl->save();
         }
Index: branches/release-35/lib/MT/Template.pm
===================================================================
--- branches/release-35/lib/MT/Template.pm (revision 1949)
+++ branches/release-35/lib/MT/Template.pm (revision 1957)
@@ -291,24 +291,47 @@
         return $tmpl->error(MT->translate('Template with the same name already exists in this blog.'));
     }
+
+    if ($tmpl->id && ($tmpl->is_changed('build_type'))) {
+        # check for templatemaps, and update them appropriately
+        require MT::TemplateMap;
+        require MT::PublishOption;
+        my @maps = MT::TemplateMap->load({ template_id => $tmpl->id });
+        foreach my $map (@maps) {
+            $map->build_type($tmpl->build_type);
+            $map->save or die $map->errstr;
+        }
+    }
+
     if ($tmpl->linked_file) {
         $tmpl->_sync_to_disk($tmpl->SUPER::text) or return;
     }
     $tmpl->{needs_db_sync} = 0;
-    if ((!$tmpl->id) && (my $blog = $tmpl->blog)) {
-        my $dcty = $blog->custom_dynamic_templates;
-        if ($dcty eq 'all') {
-            if (('index' eq $tmpl->type) || ('archive' eq $tmpl->type) ||
-                ('individual' eq $tmpl->type) || ('page' eq $tmpl->type) ||
-                    ('category' eq $tmpl->type)) {
-                $tmpl->build_dynamic(1);
-            }
-        } elsif ($dcty eq 'archives') {
-            if (('archive' eq $tmpl->type) || ('page' eq $tmpl->type) ||
-                ('individual' eq $tmpl->type) || ('category' eq $tmpl->type)) {
-                $tmpl->build_dynamic(1);
-            }
-        }
-    }
+
+    # if ((!$tmpl->id) && (my $blog = $tmpl->blog)) {
+    #     my $dcty = $blog->custom_dynamic_templates;
+    #     if ($dcty eq 'all') {
+    #         if (('index' eq $tmpl->type) || ('archive' eq $tmpl->type) ||
+    #             ('individual' eq $tmpl->type) || ('page' eq $tmpl->type) ||
+    #                 ('category' eq $tmpl->type)) {
+    #             $tmpl->build_dynamic(1);
+    #         }
+    #     } elsif ($dcty eq 'archives') {
+    #         if (('archive' eq $tmpl->type) || ('page' eq $tmpl->type) ||
+    #             ('individual' eq $tmpl->type) || ('category' eq $tmpl->type)) {
+    #             $tmpl->build_dynamic(1);
+    #         }
+    #     }
+    # }
+
     $tmpl->SUPER::save;
+}
+
+sub build_dynamic {
+    my $tmpl = shift;
+    require MT::PublishOption;
+    if (@_) {
+        $tmpl->build_type($_[0] ? MT::PublishOption::DYNAMIC() : MT::PublishOption::ONDEMAND());
+    }
+    return 1 if $tmpl->build_type == MT::PublishOption::DYNAMIC();
 }
 
