Changeset 2825

Show
Ignore:
Timestamp:
07/21/08 20:50:30 (4 months ago)
Author:
mpaschal
Message:

Really (re)move and replace the existing global templates when the user picks "Reset to factory defaults"
label loops
(apply the rest of Jay Allen's patch; thanks, Jay!)
BugzID: 80010

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/release-41/lib/MT/CMS/Template.pm

    r2824 r2825  
    17061706    my $refreshed; 
    17071707    my $can_refresh_system = $user->is_superuser() ? 1 : 0; 
    1708     foreach my $blog_id (@id) { 
     1708    BLOG: for my $blog_id (@id) { 
    17091709        my $blog; 
    17101710        if ($blog_id) { 
    17111711            $blog = MT::Blog->load($blog_id); 
    1712             next unless $blog; 
     1712            next BLOG unless $blog; 
    17131713        } 
    17141714 
     
    17231723            if (!$can_refresh_blog) { 
    17241724                push @blogs_not_refreshed, $blog->id; 
    1725                 next
     1725                next BLOG
    17261726            } 
    17271727        } 
    17281728 
    17291729        my $tmpl_list; 
    1730         if ($blog_id) { 
    1731  
    1732             if ($refresh_type eq 'clean') { 
    1733                 # the user wants to back up all templates and 
    1734                 # install the new ones 
    1735  
    1736                 my @ts = MT::Util::offset_time_list( $t, $blog_id ); 
    1737                 my $ts = sprintf "%04d-%02d-%02d %02d:%02d:%02d", 
    1738                     $ts[5] + 1900, $ts[4] + 1, @ts[ 3, 2, 1, 0 ]; 
    1739  
    1740                 my $tmpl_iter = MT::Template->load_iter({ 
    1741                     blog_id => $blog_id, 
    1742                     type => { not => 'backup' }, 
    1743                 }); 
    1744  
    1745                 while (my $tmpl = $tmpl_iter->()) { 
    1746                     if ($backup) { 
    1747                         # zap all template maps 
    1748                         require MT::TemplateMap; 
    1749                         MT::TemplateMap->remove({ 
    1750                             template_id => $tmpl->id, 
    1751                         }); 
    1752                         $tmpl->type('backup'); 
    1753                         $tmpl->name( 
    1754                             $tmpl->name . ' (Backup from ' . $ts . ')' ); 
    1755                         $tmpl->identifier(undef); 
    1756                         $tmpl->rebuild_me(0); 
    1757                         $tmpl->linked_file(undef); 
    1758                         $tmpl->outfile(''); 
    1759                         $tmpl->save; 
    1760                     } else { 
    1761                         $tmpl->remove; 
    1762                     } 
     1730 
     1731        if ($refresh_type eq 'clean') { 
     1732            # the user wants to back up all templates and 
     1733            # install the new ones 
     1734 
     1735            my @ts = MT::Util::offset_time_list( $t, $blog_id ); 
     1736            my $ts = sprintf "%04d-%02d-%02d %02d:%02d:%02d", 
     1737                $ts[5] + 1900, $ts[4] + 1, @ts[ 3, 2, 1, 0 ]; 
     1738 
     1739            # Backup/delete all the existing templates. 
     1740            my $tmpl_iter = MT::Template->load_iter({ 
     1741                blog_id => $blog_id, 
     1742                type => { not => 'backup' }, 
     1743            }); 
     1744            while (my $tmpl = $tmpl_iter->()) { 
     1745                if ($backup) { 
     1746                    # zap all template maps 
     1747                    require MT::TemplateMap; 
     1748                    MT::TemplateMap->remove({ 
     1749                        template_id => $tmpl->id, 
     1750                    }); 
     1751                    $tmpl->type('backup'); 
     1752                    $tmpl->name( 
     1753                        $tmpl->name . ' (Backup from ' . $ts . ')' ); 
     1754                    $tmpl->identifier(undef); 
     1755                    $tmpl->rebuild_me(0); 
     1756                    $tmpl->linked_file(undef); 
     1757                    $tmpl->outfile(''); 
     1758                    $tmpl->save; 
     1759                } else { 
     1760                    $tmpl->remove; 
    17631761                } 
    1764  
    1765                 # This also creates our template mappings 
     1762            } 
     1763 
     1764            if ($blog_id) { 
     1765                # Create the default templates and mappings for the selected 
     1766                # set here, instead of below. 
    17661767                $blog->create_default_templates( $template_set || 
    17671768                    $blog->template_set || 'mt_blog' ); 
     
    17731774                } 
    17741775 
    1775                 next; 
    1776             } 
    1777  
    1778             $tmpl_list = MT::DefaultTemplates->templates($template_set || $blog->template_set) || MT::DefaultTemplates->templates(); 
    1779         } 
    1780         else { 
    1781             $tmpl_list = MT::DefaultTemplates->templates(); 
    1782         } 
    1783  
    1784         foreach my $val (@$tmpl_list) { 
     1776                next BLOG; 
     1777            } 
     1778        } 
     1779 
     1780        # Load default templates for the given template set, if any. 
     1781        if ($blog_id) { 
     1782            $tmpl_list = MT::DefaultTemplates->templates($template_set || $blog->template_set);             
     1783        } 
     1784        $tmpl_list ||= MT::DefaultTemplates->templates(); 
     1785 
     1786        TEMPLATE: for my $val (@$tmpl_list) { 
    17851787            if ($blog_id) { 
    17861788                # when refreshing blog templates, 
    17871789                # skip over global templates which 
    17881790                # specify a blog_id of 0... 
    1789                 next if $val->{global}; 
     1791                next TEMPLATE if $val->{global}; 
    17901792            } 
    17911793            else { 
    1792                 next unless exists $val->{global}; 
     1794                next TEMPLATE unless exists $val->{global}; 
    17931795            } 
    17941796