Show
Ignore:
Timestamp:
04/14/08 02:38:34 (20 months ago)
Author:
bchoate
Message:

Updates to support publish profile dialog operation. BugId:76495

Files:
1 modified

Legend:

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

    r1866 r1877  
    1313 
    1414    if ($id) { 
    15         require MT::IPBanList; 
    1615        my $output = $param->{output} ||= 'cfg_prefs.tmpl'; 
    1716        $param->{need_full_rebuild}  = 1 if $q->param('need_full_rebuild'); 
     
    233232                } 
    234233            } 
     234            require MT::Template; 
     235            $param->{dynamic_enabled} = MT::Template->exist( { blog_id => $obj->id, build_dynamic => 1 }); 
    235236            eval "require List::Util; require Scalar::Util;"; 
    236237            unless ($@) { 
     
    12011202        } 
    12021203        elsif ( $screen eq 'cfg_archives' ) { 
    1203             @fields = qw( file_extension ); 
    12041204        } 
    12051205        elsif ( $screen eq 'cfg_templatemaps' ) { 
     
    13851385        } 
    13861386        if ( $screen eq 'cfg_archives' ) { 
    1387             if ( my $dcty = $app->param('dynamicity') ) { 
    1388                 $obj->custom_dynamic_templates($dcty); 
    1389             } 
    13901387            $obj->include_system( $app->param('include_system') || '' ); 
    13911388            if ( !$app->param('enable_archive_paths') ) { 
    13921389                $obj->archive_url(''); 
    13931390                $obj->archive_path(''); 
     1391            } 
     1392        } 
     1393        if ( $screen eq 'cfg_publish_profile' ) { 
     1394            if ( my $dcty = $app->param('dynamicity') ) { 
     1395                $obj->custom_dynamic_templates($dcty); 
    13941396            } 
    13951397        } 
     
    14461448 
    14471449    my $screen = $app->param('cfg_screen') || ''; 
    1448     if ( $screen eq 'cfg_archives' ) { 
     1450    if ( $screen eq 'cfg_publish_profile' ) { 
    14491451        if ( my $dcty = $app->param('dynamicity') ) { 
    1450             my $dcty_changed = $dcty ne $original->custom_dynamic_templates ? 1 : 0; 
    1451  
    1452             if ($dcty_changed) { 
    1453  
    1454                 # Apply publishing rules for templates based on 
    1455                 # publishing method selected: 
    1456                 #     none (0% publish queue, all static) 
    1457                 #     async_all (100% publish queue) 
    1458                 #     async_partial (high-priority templates publish synchronously (main index, preferred indiv. archives, feed templates)) 
    1459                 #     all (100% dynamic) 
    1460                 #     archives (archives dynamic, static indexes) 
    1461                 #     custom (custom configuration) 
    1462  
    1463                 if ( $dcty eq 'none' ) { 
    1464                     require MT::Template; 
    1465                     my @tmpls = MT::Template->load({ 
    1466                         blog_id       => $obj->id, 
    1467                         build_dynamic => 1, 
    1468                     }); 
    1469                     for my $tmpl (@tmpls) { 
    1470                         $tmpl->build_dynamic(0); 
    1471                         $tmpl->save; 
    1472                     } 
    1473                 } 
    1474                 update_dynamicity( 
    1475                     $app, 
    1476                     $obj, 
    1477                     $app->param('dynamic_cache')       ? 1 : 0, 
    1478                     $app->param('dynamic_conditional') ? 1 : 0 
    1479                 ); 
    1480             } 
    1481  
    1482             if (!$dcty_changed || $dcty eq 'custom') { 
    1483                 # do nothing 
    1484             } 
    1485             elsif ($dcty eq 'none') { 
     1452            # Apply publishing rules for templates based on 
     1453            # publishing method selected: 
     1454            #     none (0% publish queue, all static) 
     1455            #     async_all (100% publish queue) 
     1456            #     async_partial (high-priority templates publish synchronously (main index, preferred indiv. archives, feed templates)) 
     1457            #     all (100% dynamic) 
     1458            #     archives (archives dynamic, static indexes) 
     1459            #     custom (custom configuration) 
     1460 
     1461            update_publishing_profile( 
     1462                $app, 
     1463                $obj 
     1464            ); 
     1465 
     1466            if (($dcty eq 'none') || ($dcty =~ m/^async/)) { 
    14861467                _update_finfos($app, 0); 
    14871468            } 
     
    14941475                _update_finfos($app, 0, { templatemap_id => \'is null' }); 
    14951476            } 
    1496  
    1497             # If either of the publishing paths changed, rebuild the fileinfos. 
    1498             my $path_changed = 0; 
    1499             for my $path_field (qw( site_path archive_path site_url archive_url )) { 
    1500                 $path_changed = 1 && last if $app->param($path_field) 
    1501                     && $app->param($path_field) ne $original->$path_field(); 
    1502             } 
    1503  
    1504             if ($path_changed) { 
    1505                 $app->rebuild( BlogID => $obj->id, NoStatic => 1 ) 
    1506                     or return $app->publish_error(); 
    1507             } 
     1477        } 
     1478 
     1479        cfg_publish_profile_save($app, $obj) or return; 
     1480    } 
     1481    if ( $screen eq 'cfg_archives' ) { 
     1482        # update the dynamic publishing options if they changed 
     1483        update_dynamicity( 
     1484            $app, 
     1485            $obj 
     1486        ); 
     1487 
     1488        # If either of the publishing paths changed, rebuild the fileinfos. 
     1489        my $path_changed = 0; 
     1490        for my $path_field (qw( site_path archive_path site_url archive_url )) { 
     1491            $path_changed = 1 && last if $app->param($path_field) 
     1492                && $app->param($path_field) ne $original->$path_field(); 
     1493        } 
     1494 
     1495        if ($path_changed) { 
     1496            $app->rebuild( BlogID => $obj->id, NoStatic => 1 ) 
     1497                or return $app->publish_error(); 
    15081498        } 
    15091499 
     
    18471837 
    18481838sub _switch_publish_options { 
    1849     my ( $blog, $current, $new ) = @_; 
     1839    my ( $blog, $current, $new, $dcty ) = @_; 
    18501840    require MT::Template; 
    18511841    require MT::TemplateMap; 
    18521842    my @tmpl = MT::Template->load( { blog_id => $blog->id } ); 
     1843    my $pref_at = $blog->archive_type_preferred || ''; 
    18531844    for my $tmpl (@tmpl) { 
     1845        # FIXME: enumeration of types 
    18541846        next 
    1855           if !( $tmpl->type =~ m/^(individual|page|category|archive|index)$/ ); 
    1856         if ( $tmpl->build_type == $current ) { 
    1857             $tmpl->build_type($new); 
    1858             $tmpl->save; 
    1859         } 
     1847          if !( $tmpl->type =~ m/^(individual|page|category|archive)$/ ); 
     1848        # if ( $tmpl->build_type == $current ) { 
     1849        #     $tmpl->build_type($new); 
     1850        #     $tmpl->save; 
     1851        # } 
    18601852        my @tmpl_maps = MT::TemplateMap->load( { template_id => $tmpl->id } ); 
    18611853        foreach my $tmpl_map (@tmpl_maps) { 
    1862             if ( $tmpl_map->build_type == $current ) { 
     1854            if ($dcty eq 'async_partial') { 
     1855                # build the preferred archive type synchronously 
     1856                if (($tmpl_map->archive_type eq $pref_at) && 
     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 ) { 
    18631864                $tmpl_map->build_type($new); 
    18641865                $tmpl_map->save; 
     
    18751876    my $at = $app->param('preferred_archive_type'); 
    18761877    $blog->archive_type_preferred($at); 
    1877     my $pq = $app->param('publish_queue'); 
    1878     $blog->publish_queue( $pq ? 1 : 0 ); 
    18791878    $blog->include_cache( $app->param('include_cache') ? 1 : 0 ); 
     1879    $blog->save 
     1880      or return $app->error( 
     1881        $app->translate( "Saving blog failed: [_1]", $blog->errstr ) ); 
     1882 
     1883    1; 
     1884} 
     1885 
     1886sub cfg_publish_profile_save { 
     1887    my $app = shift; 
     1888    my ($blog) = @_; 
     1889 
     1890    my $dcty = $app->param('dynamicity') || 'none'; 
     1891    my $pq = $dcty =~ m/^async/ ? 1 : 0; 
     1892    $blog->publish_queue( $pq ); 
    18801893    $blog->save 
    18811894      or return $app->error( 
     
    18871900            $blog, 
    18881901            MT::PublishOption::ONDEMAND(), 
    1889             MT::PublishOption::ASYNC() 
     1902            MT::PublishOption::ASYNC(), 
     1903            $dcty, 
    18901904        ); 
    18911905    } 
     
    18941908            $blog, 
    18951909            MT::PublishOption::ASYNC(), 
    1896             MT::PublishOption::ONDEMAND() 
     1910            MT::PublishOption::ONDEMAND(), 
     1911            $dcty, 
    18971912        ); 
    18981913    } 
     1914 
     1915    1; 
    18991916} 
    19001917 
     
    19051922    my @tms = MT::TemplateMap->load( 
    19061923        { 
    1907             archive_type => $archive_type, 
    1908             blog_id      => $blog_id 
     1924            archive_type  => $archive_type, 
     1925            blog_id       => $blog_id 
    19091926        } 
    19101927    ); 
    1911     grep { $_->text =~ /<MT:?IfRegistration/i } 
     1928    grep { !$_->build_dynamic && ($_->text =~ /<MT:?IfRegistration/i) } 
    19121929      map { MT::Template->load( $_->template_id ) } @tms; 
    19131930} 
    19141931 
    1915 sub update_dynamicity { 
     1932sub update_publishing_profile { 
    19161933    my $app = shift; 
    1917     my ( $blog, $cache, $conditional ) = @_; 
     1934    my ( $blog ) = @_; 
     1935 
    19181936    my $dcty = $blog->custom_dynamic_templates; 
    19191937 
    1920     if ( ($dcty eq 'async_partial') || ($dcty eq 'async_all') ) { 
    1921         # these behave like static publishing 
    1922         $dcty = 'none'; 
    1923     } 
    1924  
    1925     if ( $dcty eq 'none' ) { 
    1926         require MT::Template; 
    1927         my @templates = MT::Template->load( { blog_id => $blog->id } ); 
     1938    require MT::PublishOption; 
     1939    require MT::Template; 
     1940 
     1941    if ( ($dcty eq 'none') || ($dcty =~ m/^async/) ) { 
     1942        my @templates = MT::Template->load( { 
     1943            blog_id => $blog->id, 
     1944            # FIXME: enumeration of types 
     1945            type => 
     1946              [ 'index', 'archive', 'individual', 'page', 'category' ], 
     1947          } ); 
    19281948        for my $tmpl (@templates) { 
     1949            my $bt = $tmpl->build_type || 0; 
     1950            # Do not make automatic modifications to templates with these 
     1951            # manually configured build types 
     1952            next if $bt == MT::PublishOption::DISABLED(); 
     1953            next if $bt == MT::PublishOption::MANUALLY(); 
     1954            next if $bt == MT::PublishOption::SCHEDULED(); 
     1955 
     1956            if ($dcty eq 'async_partial') { 
     1957                # these should be build synchronously 
     1958                if (($tmpl->identifier || '') =~ m/^(main_index|feed_recent)$/) { 
     1959                    $tmpl->build_type(MT::PublishOption::ONDEMAND()); 
     1960                } else { 
     1961                    $tmpl->build_type(MT::PublishOption::ASYNC()); 
     1962                } 
     1963            } elsif ($dcty eq 'async_all') { 
     1964                $tmpl->build_type(MT::PublishOption::ASYNC()); 
     1965            } else { 
     1966                $tmpl->build_type(MT::PublishOption::ONDEMAND()); 
     1967            } 
    19291968            $tmpl->build_dynamic(0); 
    19301969            $tmpl->save(); 
     
    19321971    } 
    19331972    elsif ( $dcty eq 'archives' ) { 
    1934         require MT::Template; 
    1935         my @templates = MT::Template->load( { blog_id => $blog->id } ); 
     1973        my @templates = MT::Template->load( { 
     1974            blog_id => $blog->id, 
     1975            # FIXME: enumeration of types 
     1976            type => 
     1977              [ 'index', 'archive', 'individual', 'page', 'category' ], 
     1978          } ); 
    19361979        for my $tmpl (@templates) { 
     1980            $tmpl->build_type( $tmpl->type ne 'index' ? MT::PublishOption::DYNAMIC() : MT::PublishOption::ONDEMAND() ); 
    19371981            $tmpl->build_dynamic( $tmpl->type ne 'index' ? 1 : 0 ); 
    19381982            $tmpl->save(); 
    19391983        } 
    19401984    } 
    1941     elsif ( $dcty eq 'custom' ) { 
    1942     } 
    19431985    elsif ( $dcty eq 'all' ) { 
    1944         require MT::Template; 
    19451986        my @templates = MT::Template->load( 
    19461987            { 
     
    19531994        ); 
    19541995        for my $tmpl (@templates) { 
     1996            $tmpl->build_type( MT::PublishOption::DYNAMIC() ); 
    19551997            $tmpl->build_dynamic(1); 
    19561998            $tmpl->save(); 
    19571999        } 
    19582000    } 
    1959  
    1960     if ( $dcty ne 'none' ) { 
    1961         prepare_dynamic_publishing($app, @_, $blog->site_path, $blog->site_url); 
     2001    return 1; 
     2002} 
     2003 
     2004sub update_dynamicity { 
     2005    my $app = shift; 
     2006    my ( $blog ) = @_; 
     2007 
     2008    my $cache       = $app->param('dynamic_cache')       ? 1 : 0; 
     2009    my $conditional = $app->param('dynamic_conditional') ? 1 : 0; 
     2010 
     2011    require MT::Template; 
     2012    my $dynamic_enabled = MT::Template->exist( { blog_id => $blog->id, 
     2013        build_dynamic => 1 }); 
     2014 
     2015    # dynamic publishing enabled 
     2016    if ( $dynamic_enabled ) { 
     2017        prepare_dynamic_publishing($app, $blog, $cache, $conditional, $blog->site_path, $blog->site_url); 
    19622018        if ( $blog->archive_path ) { 
    1963             prepare_dynamic_publishing($app, @_, $blog->archive_path, $blog->archive_url); 
     2019            prepare_dynamic_publishing($app, $blog, $cache, $conditional, $blog->archive_path, $blog->archive_url); 
    19642020        } 
    19652021        my $compiled_template_path = 
     
    19872043        } 
    19882044    } 
    1989     $app->add_return_arg( dynamic_set => 1 ); 
    19902045} 
    19912046 
     
    20042059      && ( -f $mtview_path ); 
    20052060    return 1 if ( 'none' eq $blog->custom_dynamic_templates ); 
    2006  
    2007     require File::Spec; 
    20082061 
    20092062    # IIS itself does not handle .htaccess,