Changeset 2882

Show
Ignore:
Timestamp:
08/01/08 21:51:43 (4 months ago)
Author:
bchoate
Message:

Update parent widgetset(s) when widget is deleted (thanks, Hirotka!). BugId:80861

Files:

Legend:

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

    r2844 r2882  
    329329    my $string_tmpl = '<mt:include widget="%s">'; 
    330330    my $text = q(); 
     331    my @ids; 
    331332    foreach my $wid (@inst) { 
    332333        my ( $tmpl ) = grep { $_->id eq $wid } @widgets; 
    333334        next unless $tmpl; 
    334335        $text .= sprintf( $string_tmpl, $tmpl->name ); 
    335     } 
     336        push @ids, $wid; 
     337    } 
     338    $obj->modulesets( join ',', @ids ) 
     339        if scalar @ids != scalar @inst; 
    336340    $obj->text($text) if $text; 
    337341    return $obj->SUPER::save; 
     
    661665} 
    662666 
     667sub post_remove_widget { 
     668    my $tmpl = shift; 
     669    return unless $tmpl->type eq 'widget'; 
     670 
     671    my $iter = MT::Template->load_iter({ 
     672        blog_id => [ $tmpl->blog_id, 0 ], 
     673        type    => 'widgetset', 
     674    }); 
     675    my @resave; 
     676    while ( my $ws = $iter->() ) { 
     677        my @mods = split( ',', $ws->modulesets ); 
     678        if ( grep { $_ == $tmpl->id } @mods ) { 
     679            push @resave, $ws; 
     680        } 
     681    } 
     682    $_->save for @resave; 
     683} 
     684__PACKAGE__->add_trigger('post_remove' => \&post_remove_widget); 
     685 
    663686# Some DOM-inspired methods (replicating the interface, so it's more 
    664687# familiar to those who know DOM)