Changeset 1957

Show
Ignore:
Timestamp:
04/17/08 22:43:48 (19 months ago)
Author:
bchoate
Message:

Fixes for propogation of build_type from template to templatemaps. BugId:79370

Location:
branches/release-35/lib/MT
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • branches/release-35/lib/MT/CMS/Blog.pm

    r1951 r1957  
    18361836} 
    18371837 
    1838 sub _switch_publish_options { 
    1839     my ( $blog, $current, $new, $dcty ) = @_; 
    1840     require MT::Template; 
    1841     require MT::TemplateMap; 
    1842     my @tmpl = MT::Template->load( { blog_id => $blog->id } ); 
    1843     my $pref_at = $blog->archive_type_preferred || ''; 
    1844     for my $tmpl (@tmpl) { 
    1845         # FIXME: enumeration of types 
    1846         next 
    1847           if !( $tmpl->type =~ m/^(individual|page|category|archive)$/ ); 
    1848         # if ( $tmpl->build_type == $current ) { 
    1849         #     $tmpl->build_type($new); 
    1850         #     $tmpl->save; 
    1851         # } 
    1852         my @tmpl_maps = MT::TemplateMap->load( { template_id => $tmpl->id } ); 
    1853         foreach my $tmpl_map (@tmpl_maps) { 
    1854             if ($dcty eq 'async_partial') { 
    1855                 # build the preferred individual/page archives synchronously 
    1856                 if (($tmpl_map->archive_type =~ m/^(Individual|Page)$/) && 
    1857                     ($tmpl_map->is_preferred)) { 
    1858                     $tmpl_map->build_type(MT::PublishOption::ONDEMAND()); 
    1859                     $tmpl_map->save; 
    1860                     next; 
    1861                 } 
    1862             } 
    1863             if ( $tmpl_map->build_type != $new ) { 
    1864                 $tmpl_map->build_type($new); 
    1865                 $tmpl_map->save; 
    1866             } 
    1867         } 
    1868     } 
    1869     1; 
    1870 } 
    1871  
    18721838sub cfg_archives_save { 
    18731839    my $app = shift; 
     
    18951861        $app->translate( "Saving blog failed: [_1]", $blog->errstr ) ); 
    18961862 
    1897     require MT::PublishOption; 
    1898     if ($pq) { 
    1899         _switch_publish_options( 
    1900             $blog, 
    1901             MT::PublishOption::ONDEMAND(), 
    1902             MT::PublishOption::ASYNC(), 
    1903             $dcty, 
    1904         ); 
    1905     } 
    1906     else { 
    1907         _switch_publish_options( 
    1908             $blog, 
    1909             MT::PublishOption::ASYNC(), 
    1910             MT::PublishOption::ONDEMAND(), 
    1911             $dcty, 
    1912         ); 
    1913     } 
    1914  
    19151863    1; 
    19161864} 
    19171865 
     1866# FIXME: Faulty, since it doesn't take into account module includes 
    19181867sub RegistrationAffectsArchives { 
    19191868    my ( $blog_id, $archive_type ) = @_; 
     
    19661915                $tmpl->build_type(MT::PublishOption::ONDEMAND()); 
    19671916            } 
    1968             $tmpl->build_dynamic(0); 
    19691917            $tmpl->save(); 
    19701918        } 
     
    19791927        for my $tmpl (@templates) { 
    19801928            $tmpl->build_type( $tmpl->type ne 'index' ? MT::PublishOption::DYNAMIC() : MT::PublishOption::ONDEMAND() ); 
    1981             $tmpl->build_dynamic( $tmpl->type ne 'index' ? 1 : 0 ); 
    19821929            $tmpl->save(); 
    19831930        } 
     
    19951942        for my $tmpl (@templates) { 
    19961943            $tmpl->build_type( MT::PublishOption::DYNAMIC() ); 
    1997             $tmpl->build_dynamic(1); 
    19981944            $tmpl->save(); 
    19991945        } 
  • branches/release-35/lib/MT/Template.pm

    r1949 r1957  
    291291        return $tmpl->error(MT->translate('Template with the same name already exists in this blog.')); 
    292292    } 
     293 
     294    if ($tmpl->id && ($tmpl->is_changed('build_type'))) { 
     295        # check for templatemaps, and update them appropriately 
     296        require MT::TemplateMap; 
     297        require MT::PublishOption; 
     298        my @maps = MT::TemplateMap->load({ template_id => $tmpl->id }); 
     299        foreach my $map (@maps) { 
     300            $map->build_type($tmpl->build_type); 
     301            $map->save or die $map->errstr; 
     302        } 
     303    } 
     304 
    293305    if ($tmpl->linked_file) { 
    294306        $tmpl->_sync_to_disk($tmpl->SUPER::text) or return; 
    295307    } 
    296308    $tmpl->{needs_db_sync} = 0; 
    297     if ((!$tmpl->id) && (my $blog = $tmpl->blog)) { 
    298         my $dcty = $blog->custom_dynamic_templates; 
    299         if ($dcty eq 'all') { 
    300             if (('index' eq $tmpl->type) || ('archive' eq $tmpl->type) || 
    301                 ('individual' eq $tmpl->type) || ('page' eq $tmpl->type) || 
    302                     ('category' eq $tmpl->type)) { 
    303                 $tmpl->build_dynamic(1); 
    304             } 
    305         } elsif ($dcty eq 'archives') { 
    306             if (('archive' eq $tmpl->type) || ('page' eq $tmpl->type) || 
    307                 ('individual' eq $tmpl->type) || ('category' eq $tmpl->type)) { 
    308                 $tmpl->build_dynamic(1); 
    309             } 
    310         } 
    311     } 
     309 
     310    # if ((!$tmpl->id) && (my $blog = $tmpl->blog)) { 
     311    #     my $dcty = $blog->custom_dynamic_templates; 
     312    #     if ($dcty eq 'all') { 
     313    #         if (('index' eq $tmpl->type) || ('archive' eq $tmpl->type) || 
     314    #             ('individual' eq $tmpl->type) || ('page' eq $tmpl->type) || 
     315    #                 ('category' eq $tmpl->type)) { 
     316    #             $tmpl->build_dynamic(1); 
     317    #         } 
     318    #     } elsif ($dcty eq 'archives') { 
     319    #         if (('archive' eq $tmpl->type) || ('page' eq $tmpl->type) || 
     320    #             ('individual' eq $tmpl->type) || ('category' eq $tmpl->type)) { 
     321    #             $tmpl->build_dynamic(1); 
     322    #         } 
     323    #     } 
     324    # } 
     325 
    312326    $tmpl->SUPER::save; 
     327} 
     328 
     329sub build_dynamic { 
     330    my $tmpl = shift; 
     331    require MT::PublishOption; 
     332    if (@_) { 
     333        $tmpl->build_type($_[0] ? MT::PublishOption::DYNAMIC() : MT::PublishOption::ONDEMAND()); 
     334    } 
     335    return 1 if $tmpl->build_type == MT::PublishOption::DYNAMIC(); 
    313336} 
    314337 
  • branches/release-35/lib/MT/TemplateMap.pm

    r1873 r1957  
    4646sub save { 
    4747    my $map = shift; 
    48     $map->SUPER::save(); 
     48    my $res = $map->SUPER::save(); 
     49    return $res unless $res; 
     50 
    4951    my $at   = $map->archive_type; 
    5052    my $blog = MT->model('blog')->load($map->blog_id) 
     
    5658                if $blog_at ne 'None'; 
    5759    push @ats, $map->archive_type; 
    58     $blog->archive_type(join ',', @ats); 
    59     $blog->save; 
     60    my $new_at = join ',', @ats; 
     61    if ($new_at ne $blog_at) { 
     62        $blog->archive_type($new_at); 
     63        $blog->save; 
     64    } 
     65    return 1; 
    6066} 
    6167