Changeset 1980

Show
Ignore:
Timestamp:
04/18/08 08:00:45 (22 months ago)
Author:
fumiakiy
Message:

Create required files and directories for dynamic publishing according to the selected publishing profile.

Also "rebuild" the necessary files to rename those files and append .static to the file name. BugId:79364

Location:
branches/release-35
Files:
3 modified

Legend:

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

    r1978 r1980  
    232232                } 
    233233            } 
    234             require MT::Template; 
    235             $param->{dynamic_enabled} = MT::Template->exist( { blog_id => $obj->id, build_dynamic => 1 }); 
     234            require MT::PublishOption; 
     235            if ( $app->model('template')->exist( 
     236                    { blog_id => $blog->id, build_type => MT::PublishOption::DYNAMIC() }) 
     237              || $app->model('templatemap')->exist( 
     238                    { blog_id => $blog->id, build_type => MT::PublishOption::DYNAMIC() }) ) 
     239            { 
     240                $param->{dynamic_enabled} = 1; 
     241            } 
    236242            eval "require List::Util; require Scalar::Util;"; 
    237243            unless ($@) { 
     
    446452    $param{no_cachedir}         = $q->param('no_cachedir'); 
    447453    $param{no_writecache}       = $q->param('no_writecache'); 
    448     $param{dynamicity}          = $blog->custom_dynamic_templates || 'none'; 
    449454    $param{include_system}      = $blog->include_system || ''; 
    450455 
     
    798803            dynamic         => $dynamic, 
    799804            is_new          => scalar $q->param('is_new'), 
    800             old_status      => scalar $q->param('old_status') 
     805            old_status      => scalar $q->param('old_status'), 
     806            is_full_screen  => scalar $q->param('fs'), 
     807            return_args     => scalar $q->param('return_args') 
    801808        ); 
    802809        $app->load_tmpl( 'rebuilding.tmpl', \%param ); 
     
    846853            } 
    847854            if ( $q->param('fs') ) {    # full screen--go to a useful app page 
    848                 my $type = $q->param('type'); 
    849                 $type =~ /index-(\d+)/; 
    850                 my $tmpl_id = $1; 
    851                 $app->run_callbacks( 'rebuild', $blog ); 
    852                 return $app->redirect( 
    853                     $app->uri( 
    854                         'mode' => 'view', 
    855                         args   => { 
    856                             '_type'       => 'template', 
    857                             id            => $tmpl_id, 
    858                             blog_id       => $blog->id, 
    859                             saved_rebuild => 1 
    860                         } 
    861                     ) 
    862                 ); 
     855                if ( my $return_args = $q->param('return_args') ) { 
     856                    $app->call_return; 
     857                } 
     858                else { 
     859                    my $type = $q->param('type'); 
     860                    $type =~ /index-(\d+)/; 
     861                    my $tmpl_id = $1; 
     862                    $app->run_callbacks( 'rebuild', $blog ); 
     863                    return $app->redirect( 
     864                        $app->uri( 
     865                            'mode' => 'view', 
     866                            args   => { 
     867                                '_type'       => 'template', 
     868                                id            => $tmpl_id, 
     869                                blog_id       => $blog->id, 
     870                                saved_rebuild => 1 
     871                            } 
     872                        ) 
     873                    ); 
     874                } 
    863875            } 
    864876            else {    # popup--just go to cnfrmn. page 
     
    941953        complete        => 0, 
    942954        incomplete      => 100, 
    943         build_type_name => $archive_label 
     955        build_type_name => $archive_label, 
     956        return_args     => $app->return_args 
    944957    ); 
    945958 
     
    972985} 
    973986 
    974 sub rebuild_confirm { 
    975     my $app     = shift; 
    976     my $blog_id = $app->param('blog_id'); 
    977     require MT::Blog; 
    978     my $blog = MT::Blog->load($blog_id) 
    979         or return $app->error($app->translate('Can\'t load blog #[_1].', $blog_id)); 
     987sub _create_build_order { 
     988    my ( $app, $blog, $param ) = @_; 
     989 
    980990    my $at = $blog->archive_type || ''; 
    981991    my ( @blog_at, @at, @data ); 
     
    10041014        } 
    10051015    } 
    1006     my $order     = join ',', @at, 'index'; 
    1007     my $entry_pkg = $app->model('entry'); 
     1016    $param->{archive_type_loop} = \@data; 
     1017    $param->{build_order} = join ',', @at, 'index'; 
     1018    1; 
     1019} 
     1020 
     1021sub rebuild_confirm { 
     1022    my $app     = shift; 
     1023    my $blog_id = $app->param('blog_id'); 
     1024    require MT::Blog; 
     1025    my $blog = MT::Blog->load($blog_id) 
     1026        or return $app->error($app->translate('Can\'t load blog #[_1].', $blog_id)); 
     1027 
    10081028    my %param     = ( 
    1009         archive_type_loop => \@data, 
    1010         build_order       => $order, 
    10111029        build_next        => 0, 
    10121030    ); 
     1031    _create_build_order( $app, $blog, \%param ); 
     1032 
    10131033    $param{index_selected} = ( $app->param('prompt') || "" ) eq 'index'; 
    10141034 
     
    14801500    } 
    14811501    if ( $screen eq 'cfg_archives' ) { 
    1482         # update the dynamic publishing options if they changed 
    1483         update_dynamicity( 
    1484             $app, 
    1485             $obj 
    1486         ); 
    1487  
    14881502        # If either of the publishing paths changed, rebuild the fileinfos. 
    14891503        my $path_changed = 0; 
     
    18431857    $blog->archive_type_preferred($at); 
    18441858    $blog->include_cache( $app->param('include_cache') ? 1 : 0 ); 
     1859    require MT::PublishOption; 
     1860    if ( ( $blog->custom_dynamic_templates eq 'all' 
     1861        || $blog->custom_dynamic_templates eq 'archives' ) 
     1862      && ( $app->model('template')->exist( 
     1863            { blog_id => $blog->id, build_type => MT::PublishOption::DYNAMIC() }) 
     1864        || $app->model('templatemap')->exist( 
     1865            { blog_id => $blog->id, build_type => MT::PublishOption::DYNAMIC() }) ) ) 
     1866    { 
     1867        # dynamic enabled and caching option may have changed - update mtview 
     1868        my $cache       = $app->param('dynamic_cache')       ? 1 : 0; 
     1869        my $conditional = $app->param('dynamic_conditional') ? 1 : 0; 
     1870        _create_mtview( $blog, $blog->site_path, $cache, $conditional ); 
     1871        _create_dynamiccache_dir( $blog, $blog->site_path ) if $cache; 
     1872        if ( $blog->archive_path ) { 
     1873            _create_mtview( $blog, $blog->archive_path, $cache, $conditional ); 
     1874            _create_dynamiccache_dir( $blog, $blog->archive_path ) if $cache; 
     1875        } 
     1876    } 
    18451877    $blog->save 
    18461878      or return $app->error( 
     
    18571889    my $pq = $dcty =~ m/^async/ ? 1 : 0; 
    18581890    $blog->publish_queue( $pq ); 
     1891    if ( $dcty eq 'all' || $dcty eq 'archives' ) { 
     1892        # update the dynamic publishing options if they changed 
     1893        update_dynamicity( 
     1894            $app, 
     1895            $blog 
     1896        ); 
     1897    } 
    18591898    $blog->save 
    18601899      or return $app->error( 
     
    19832022    my $conditional = $app->param('dynamic_conditional') ? 1 : 0; 
    19842023 
    1985     require MT::Template; 
    1986     my $dynamic_enabled = MT::Template->exist( { blog_id => $blog->id, 
    1987         build_dynamic => 1 }); 
    1988  
    1989     # dynamic publishing enabled 
    1990     if ( $dynamic_enabled ) { 
     2024    require MT::PublishOption; 
     2025    if ( $app->model('template')->exist( 
     2026            { blog_id => $blog->id, build_type => MT::PublishOption::DYNAMIC() }) 
     2027      || $app->model('templatemap')->exist( 
     2028            { blog_id => $blog->id, build_type => MT::PublishOption::DYNAMIC() }) ) 
     2029    { 
     2030        # dynamic publishing enabled 
    19912031        prepare_dynamic_publishing($app, $blog, $cache, $conditional, $blog->site_path, $blog->site_url); 
    19922032        if ( $blog->archive_path ) { 
     
    20162056            } 
    20172057        } 
     2058    } 
     2059} 
     2060 
     2061sub _create_mtview { 
     2062    my ( $blog, $site_path, $cache, $conditional ) = @_; 
     2063 
     2064    my $mtview_path = File::Spec->catfile( $site_path, "mtview.php" ); 
     2065    eval { 
     2066        my $mv_contents = ''; 
     2067        if ( -f $mtview_path ) { 
     2068            open( my $mv, "<$mtview_path" ); 
     2069            while ( my $line = <$mv> ) { 
     2070                $mv_contents .= $line if ( $line !~ m!^//|<\?(?:php)?|\?>! ); 
     2071            } 
     2072            close $mv; 
     2073        } 
     2074        my $cgi_path = MT->instance->server_path() || ""; 
     2075        $cgi_path =~ s!/*$!!; 
     2076        my $mtphp_path = File::Spec->canonpath("$cgi_path/php/mt.php"); 
     2077        my $blog_id    = $blog->id; 
     2078        my $config     = MT->instance->{cfg_file}; 
     2079        my $cache_code = $cache ? "\n    \$mt->caching = true;" : ''; 
     2080        my $conditional_code = 
     2081          $conditional ? "\n    \$mt->conditional = true;" : ''; 
     2082        my $new_mtview = <<NEW_MTVIEW; 
     2083 
     2084    include('$mtphp_path'); 
     2085    \$mt = new MT($blog_id, '$config');$cache_code$conditional_code 
     2086    \$mt->view(); 
     2087NEW_MTVIEW 
     2088 
     2089        if ( $new_mtview ne substr( $mv_contents, 0, length($new_mtview) ) ) { 
     2090            $mv_contents =~ s!\n!\n//!gs; 
     2091            my $mtview = <<MTVIEW; 
     2092<?php 
     2093$new_mtview 
     2094$mv_contents 
     2095?> 
     2096MTVIEW 
     2097 
     2098            $blog->file_mgr->mkpath( $site_path ); 
     2099            open( my $mv, ">$mtview_path" ) 
     2100              || die "Couldn't open $mtview_path for appending"; 
     2101            print $mv $mtview || die "Couldn't write to $mtview_path"; 
     2102            close $mv; 
     2103        } 
     2104    }; 
     2105    if ($@) { print STDERR $@; } 
     2106} 
     2107 
     2108sub _create_dynamiccache_dir { 
     2109    my ( $blog, $site_path ) = @_; 
     2110 
     2111    # FIXME: use FileMgr 
     2112    my $cache_path = File::Spec->catfile( $site_path, 'cache' ); 
     2113    my $fmgr = $blog->file_mgr; 
     2114    my $saved_umask = MT->config->DirUmask; 
     2115    MT->config->DirUmask('0000'); 
     2116    $fmgr->mkpath($cache_path); 
     2117    MT->config->DirUmask($saved_umask); 
     2118    my $message; 
     2119    if ( -d $cache_path ) { 
     2120        $message = MT->translate( 
     2121'ErrMovable Type cannot write to the template cache directory. Please check the permissions for the directory called <code>[_1]</code> underneath your blog directory.', 
     2122            'cache' 
     2123        ) unless ( -w $cache_path ); 
     2124    } 
     2125    else { 
     2126        $message = MT->translate( 
     2127'ErrMovable Type was not able to create a directory to cache your dynamic templates. You should create a directory called <code>[_1]</code> underneath your blog directory.', 
     2128            'cache' 
     2129        ) unless ( -d $cache_path ); 
     2130    } 
     2131    if ( $message ) { 
     2132        MT->log( 
     2133            { 
     2134                message => $message, 
     2135                level   => MT::Log::ERROR(), 
     2136                class   => 'system', 
     2137            } 
     2138        ); 
    20182139    } 
    20192140} 
     
    20322153      && ( -f $htaccess_path ) 
    20332154      && ( -f $mtview_path ); 
    2034     return 1 if ( 'none' eq $blog->custom_dynamic_templates ); 
     2155    return 1  
     2156        if 'all' ne $blog->custom_dynamic_templates 
     2157        && 'archives' ne $blog->custom_dynamic_templates; 
    20352158 
    20362159    # IIS itself does not handle .htaccess, 
     
    21072230    } 
    21082231 
    2109     eval { 
    2110         my $mv_contents = ''; 
    2111         if ( -f $mtview_path ) { 
    2112             open( my $mv, "<$mtview_path" ); 
    2113             while ( my $line = <$mv> ) { 
    2114                 $mv_contents .= $line if ( $line !~ m!^//|<\?(?:php)?|\?>! ); 
    2115             } 
    2116             close $mv; 
    2117         } 
    2118         my $cgi_path = MT->instance->server_path() || ""; 
    2119         $cgi_path =~ s!/*$!!; 
    2120         my $mtphp_path = File::Spec->canonpath("$cgi_path/php/mt.php"); 
    2121         my $blog_id    = $blog->id; 
    2122         my $config     = MT->instance->{cfg_file}; 
    2123         my $cache_code = $cache ? "\n    \$mt->caching = true;" : ''; 
    2124         my $conditional_code = 
    2125           $conditional ? "\n    \$mt->conditional = true;" : ''; 
    2126         my $new_mtview = <<NEW_MTVIEW; 
    2127  
    2128     include('$mtphp_path'); 
    2129     \$mt = new MT($blog_id, '$config');$cache_code$conditional_code 
    2130     \$mt->view(); 
    2131 NEW_MTVIEW 
    2132  
    2133         if ( $new_mtview ne substr( $mv_contents, 0, length($new_mtview) ) ) { 
    2134             $mv_contents =~ s!\n!\n//!gs; 
    2135             my $mtview = <<MTVIEW; 
    2136 <?php 
    2137 $new_mtview 
    2138 $mv_contents 
    2139 ?> 
    2140 MTVIEW 
    2141  
    2142             $blog->file_mgr->mkpath( $site_path ); 
    2143             open( my $mv, ">$mtview_path" ) 
    2144               || die "Couldn't open $mtview_path for appending"; 
    2145             print $mv $mtview || die "Couldn't write to $mtview_path"; 
    2146             close $mv; 
    2147         } 
    2148     }; 
    2149     if ($@) { print STDERR $@; } 
     2232    _create_mtview( $blog, $site_path, $cache, $conditional ); 
    21502233 
    21512234    my $compiled_template_path = 
     
    21722255    } 
    21732256 
    2174     # FIXME: use FileMgr 
    21752257    if ($cache) { 
    2176         my $cache_path = File::Spec->catfile( $blog->site_path(), 'cache' ); 
    2177         $cfg->DirUmask('0000'); 
    2178         $fmgr->mkpath($cache_path); 
    2179         $cfg->DirUmask($saved_umask); 
    2180         if ( -d $cache_path ) { 
    2181             $message = MT->translate( 
    2182 'Error: Movable Type cannot write to the template cache directory. Please check the permissions for the directory called <code>[_1]</code> underneath your blog directory.', 
    2183                 'cache' 
    2184             ) unless ( -w $cache_path ); 
    2185         } 
    2186         else { 
    2187             $message = MT->translate( 
    2188 'Error: Movable Type was not able to create a directory to cache your dynamic templates. You should create a directory called <code>[_1]</code> underneath your blog directory.', 
    2189                 'cache' 
    2190             ) unless ( -d $cache_path ); 
    2191         } 
    2192     } 
    2193     MT->log( 
    2194         { 
    2195             message => $message, 
    2196             level   => MT::Log::ERROR(), 
    2197             class   => 'system', 
    2198         } 
    2199     ); 
     2258        _create_dynamiccache_dir( $blog, $site_path ); 
     2259    } 
    22002260} 
    22012261 
  • branches/release-35/lib/MT/CMS/Common.pm

    r1823 r1980  
    329329    } 
    330330    elsif ( my $cfg_screen = $q->param('cfg_screen') ) { 
     331        if ( $cfg_screen eq 'cfg_publish_profile' ) { 
     332            my $dcty = $obj->custom_dynamic_templates || 'none'; 
     333            if ( ( $dcty eq 'all' ) || ( $dcty eq 'archives' ) ) { 
     334                require MT::CMS::Blog; 
     335                my %param = (); 
     336                MT::CMS::Blog::_create_build_order( $app, $obj, \%param ); 
     337                $q->param( 'single_template', 1 ); # to show tmpl full-screen 
     338                if ( $dcty eq 'all' ) { 
     339                    $q->param( 'type', $param{build_order} ); 
     340                } 
     341                elsif ( $dcty eq 'archives' ) { 
     342                    my @ats = map { $_->{archive_type} } @{ $param{archive_type_loop} }; 
     343                    $q->param( 'type', join( ',', @ats ) ); 
     344                } 
     345                return MT::CMS::Blog::start_rebuild_pages($app); 
     346            } 
     347        } 
    331348        if ( $cfg_screen eq 'cfg_templatemaps' ) { 
    332349            $cfg_screen = 'cfg_archives'; 
  • branches/release-35/tmpl/cms/rebuilding.tmpl

    r1778 r1980  
    66    window.location='<mt:var name="redirect_target">'; 
    77<mt:else> 
    8     window.location='<mt:var name="script_url">?__mode=rebuild&blog_id=<mt:var name="blog_id">&type=<mt:var name="build_type">&next=<mt:var name="build_next">&offset=<mt:var name="offset">&limit=<mt:var name="limit">&total=<mt:var name="total">&start_time=<mt:var name="start_time">&entry_id=<mt:var name="entry_id">&is_new=<mt:var name="is_new">&old_status=<mt:var name="old_status">&old_previous=<mt:var name="old_previous">&old_next=<mt:var name="old_next"><mt:if name="is_full_screen">&fs=1</mt:if>'; 
     8    window.location='<mt:var name="script_url">?__mode=rebuild&blog_id=<mt:var name="blog_id">&type=<mt:var name="build_type">&next=<mt:var name="build_next">&offset=<mt:var name="offset">&limit=<mt:var name="limit">&total=<mt:var name="total">&start_time=<mt:var name="start_time">&entry_id=<mt:var name="entry_id">&is_new=<mt:var name="is_new">&old_status=<mt:var name="old_status">&old_previous=<mt:var name="old_previous">&old_next=<mt:var name="old_next"><mt:if name="is_full_screen">&fs=1</mt:if><mt:if name="return_args">&return_args=<mt:var name="return_args" escape="url"></mt:if>'; 
    99</mt:if> 
    1010}