Changeset 2390

Show
Ignore:
Timestamp:
05/19/08 15:02:36 (21 months ago)
Author:
bchoate
Message:

Support for removing objectscore records with static 'remove' call. BugId:79694

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/release-38/lib/MT/Object.pm

    r2389 r2390  
    698698    if (!ref $obj) { 
    699699        $obj->remove_meta( @args ) if $obj->has_meta; 
     700        $obj->remove_scores( @args ) if $obj->isa('MT::Scorable'); 
    700701        return $obj->driver->direct_remove($obj, @args); 
    701702    } else { 
     
    987988        my $meta_id = $obj->datasource . '_id'; 
    988989        my $offset = 0; 
     990        $args ||= {}; 
    989991        $args->{fetchonly} = [ 'id' ]; 
    990992        $args->{join} = [ $mpkg, $meta_id ]; 
     
    10051007            } 
    10061008        } 
    1007     } 
     1009        return 1; 
     1010    } 
     1011} 
     1012 
     1013sub remove_scores { 
     1014    my $class = shift; 
     1015    require MT::ObjectScore; 
     1016    my ($terms, $args) = @_; 
     1017    $args = { %$args } if $args; # copy so we can alter 
     1018    my $offset = 0; 
     1019    $args ||= {}; 
     1020    $args->{fetchonly} = [ 'id' ]; 
     1021    $args->{join} = [ 'MT::ObjectScore', 'object_id', { 
     1022        object_ds => $class->datasource } ]; 
     1023    $args->{no_triggers} = 1; 
     1024    $args->{limit} = 50; 
     1025    while ( $offset >= 0 ) { 
     1026        $args->{offset} = $offset; 
     1027        if (my @list = $class->load( $terms, $args )) { 
     1028            my @ids = map { $_->id } @list; 
     1029            MT::ObjectScore->driver->direct_remove( 'MT::ObjectScore', { 
     1030                object_ds => $class->datasource, 'object_id' => \@ids }); 
     1031            if ( scalar @list == 50 ) { 
     1032                $offset += 50; 
     1033            } else { 
     1034                $offset = -1; # break loop 
     1035            } 
     1036        } else { 
     1037            $offset = -1; 
     1038        } 
     1039    } 
     1040    return 1; 
    10081041} 
    10091042