Changeset 1877 for branches/release-34/lib/MT/CMS/Blog.pm
- Timestamp:
- 04/14/08 02:38:34 (20 months ago)
- Files:
-
- 1 modified
-
branches/release-34/lib/MT/CMS/Blog.pm (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/release-34/lib/MT/CMS/Blog.pm
r1866 r1877 13 13 14 14 if ($id) { 15 require MT::IPBanList;16 15 my $output = $param->{output} ||= 'cfg_prefs.tmpl'; 17 16 $param->{need_full_rebuild} = 1 if $q->param('need_full_rebuild'); … … 233 232 } 234 233 } 234 require MT::Template; 235 $param->{dynamic_enabled} = MT::Template->exist( { blog_id => $obj->id, build_dynamic => 1 }); 235 236 eval "require List::Util; require Scalar::Util;"; 236 237 unless ($@) { … … 1201 1202 } 1202 1203 elsif ( $screen eq 'cfg_archives' ) { 1203 @fields = qw( file_extension );1204 1204 } 1205 1205 elsif ( $screen eq 'cfg_templatemaps' ) { … … 1385 1385 } 1386 1386 if ( $screen eq 'cfg_archives' ) { 1387 if ( my $dcty = $app->param('dynamicity') ) {1388 $obj->custom_dynamic_templates($dcty);1389 }1390 1387 $obj->include_system( $app->param('include_system') || '' ); 1391 1388 if ( !$app->param('enable_archive_paths') ) { 1392 1389 $obj->archive_url(''); 1393 1390 $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); 1394 1396 } 1395 1397 } … … 1446 1448 1447 1449 my $screen = $app->param('cfg_screen') || ''; 1448 if ( $screen eq 'cfg_ archives' ) {1450 if ( $screen eq 'cfg_publish_profile' ) { 1449 1451 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/)) { 1486 1467 _update_finfos($app, 0); 1487 1468 } … … 1494 1475 _update_finfos($app, 0, { templatemap_id => \'is null' }); 1495 1476 } 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(); 1508 1498 } 1509 1499 … … 1847 1837 1848 1838 sub _switch_publish_options { 1849 my ( $blog, $current, $new ) = @_;1839 my ( $blog, $current, $new, $dcty ) = @_; 1850 1840 require MT::Template; 1851 1841 require MT::TemplateMap; 1852 1842 my @tmpl = MT::Template->load( { blog_id => $blog->id } ); 1843 my $pref_at = $blog->archive_type_preferred || ''; 1853 1844 for my $tmpl (@tmpl) { 1845 # FIXME: enumeration of types 1854 1846 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 # } 1860 1852 my @tmpl_maps = MT::TemplateMap->load( { template_id => $tmpl->id } ); 1861 1853 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 ) { 1863 1864 $tmpl_map->build_type($new); 1864 1865 $tmpl_map->save; … … 1875 1876 my $at = $app->param('preferred_archive_type'); 1876 1877 $blog->archive_type_preferred($at); 1877 my $pq = $app->param('publish_queue');1878 $blog->publish_queue( $pq ? 1 : 0 );1879 1878 $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 1886 sub 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 ); 1880 1893 $blog->save 1881 1894 or return $app->error( … … 1887 1900 $blog, 1888 1901 MT::PublishOption::ONDEMAND(), 1889 MT::PublishOption::ASYNC() 1902 MT::PublishOption::ASYNC(), 1903 $dcty, 1890 1904 ); 1891 1905 } … … 1894 1908 $blog, 1895 1909 MT::PublishOption::ASYNC(), 1896 MT::PublishOption::ONDEMAND() 1910 MT::PublishOption::ONDEMAND(), 1911 $dcty, 1897 1912 ); 1898 1913 } 1914 1915 1; 1899 1916 } 1900 1917 … … 1905 1922 my @tms = MT::TemplateMap->load( 1906 1923 { 1907 archive_type => $archive_type,1908 blog_id => $blog_id1924 archive_type => $archive_type, 1925 blog_id => $blog_id 1909 1926 } 1910 1927 ); 1911 grep { $_->text =~ /<MT:?IfRegistration/i}1928 grep { !$_->build_dynamic && ($_->text =~ /<MT:?IfRegistration/i) } 1912 1929 map { MT::Template->load( $_->template_id ) } @tms; 1913 1930 } 1914 1931 1915 sub update_ dynamicity{1932 sub update_publishing_profile { 1916 1933 my $app = shift; 1917 my ( $blog, $cache, $conditional ) = @_; 1934 my ( $blog ) = @_; 1935 1918 1936 my $dcty = $blog->custom_dynamic_templates; 1919 1937 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 } ); 1928 1948 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 } 1929 1968 $tmpl->build_dynamic(0); 1930 1969 $tmpl->save(); … … 1932 1971 } 1933 1972 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 } ); 1936 1979 for my $tmpl (@templates) { 1980 $tmpl->build_type( $tmpl->type ne 'index' ? MT::PublishOption::DYNAMIC() : MT::PublishOption::ONDEMAND() ); 1937 1981 $tmpl->build_dynamic( $tmpl->type ne 'index' ? 1 : 0 ); 1938 1982 $tmpl->save(); 1939 1983 } 1940 1984 } 1941 elsif ( $dcty eq 'custom' ) {1942 }1943 1985 elsif ( $dcty eq 'all' ) { 1944 require MT::Template;1945 1986 my @templates = MT::Template->load( 1946 1987 { … … 1953 1994 ); 1954 1995 for my $tmpl (@templates) { 1996 $tmpl->build_type( MT::PublishOption::DYNAMIC() ); 1955 1997 $tmpl->build_dynamic(1); 1956 1998 $tmpl->save(); 1957 1999 } 1958 2000 } 1959 1960 if ( $dcty ne 'none' ) { 1961 prepare_dynamic_publishing($app, @_, $blog->site_path, $blog->site_url); 2001 return 1; 2002 } 2003 2004 sub 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); 1962 2018 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); 1964 2020 } 1965 2021 my $compiled_template_path = … … 1987 2043 } 1988 2044 } 1989 $app->add_return_arg( dynamic_set => 1 );1990 2045 } 1991 2046 … … 2004 2059 && ( -f $mtview_path ); 2005 2060 return 1 if ( 'none' eq $blog->custom_dynamic_templates ); 2006 2007 require File::Spec;2008 2061 2009 2062 # IIS itself does not handle .htaccess,
