Changeset 2500

Show
Ignore:
Timestamp:
06/04/08 01:21:49 (21 months ago)
Author:
fumiakiy
Message:

Modernized how sort argument is specified in group_by query. BugId:79977. The legacy way of specifying it is still allowed but discouraged.

Location:
branches/release-39
Files:
15 modified

Legend:

Unmodified
Added
Removed
  • branches/release-39/lib/MT/ArchiveType/AuthorDaily.pm

    r2401 r2500  
    130130                    "extract(day from authored_on)" 
    131131                ], 
    132                 'sort' => "extract(year from authored_on) $order, 
    133                          extract(month from authored_on) $order, 
    134                          extract(day from authored_on) $order" 
     132                'sort' => [ 
     133                    { column => 'extract(year from authored_on)', desc => $order }, 
     134                    { column => 'extract(month from authored_on)', desc => $order }, 
     135                    { column => 'extract(day from authored_on)', desc => $order } 
     136                ], 
    135137            } 
    136138        ) or return $ctx->error("Couldn't get monthly archive list"); 
  • branches/release-39/lib/MT/ArchiveType/AuthorMonthly.pm

    r2399 r2500  
    130130                    "extract(month from authored_on)" 
    131131                ], 
    132                 'sort' => "extract(year from authored_on) $order, 
    133                          extract(month from authored_on) $order" 
     132                'sort' => [ 
     133                    { column => "extract(year from authored_on)", desc => $order }, 
     134                    { column => "extract(month from authored_on)", desc => $order } 
     135                ], 
    134136            } 
    135137        ) or return $ctx->error("Couldn't get monthly archive list"); 
  • branches/release-39/lib/MT/ArchiveType/AuthorWeekly.pm

    r2399 r2500  
    130130                ( $ts && $tsend ? ( range_incl => { authored_on => 1 } ) : () ), 
    131131                group  => ["week_number"], 
    132                 'sort' => "week_number $order" 
     132                'sort' => [ { column => "week_number", desc => $order } ] 
    133133            } 
    134134        ) or return $ctx->error("Couldn't get weekly archive list"); 
  • branches/release-39/lib/MT/ArchiveType/AuthorYearly.pm

    r2401 r2500  
    123123            { 
    124124                group  => ["extract(year from authored_on)"], 
    125                 'sort' => "extract(year from authored_on) $order" 
     125                'sort' => [ { column => "extract(year from authored_on)", desc => $order } ] 
    126126            } 
    127127        ) or return $ctx->error("Couldn't get monthly archive list"); 
  • branches/release-39/lib/MT/ArchiveType/CategoryDaily.pm

    r2399 r2500  
    127127                    "extract(day from authored_on)" 
    128128                ], 
    129                 sort => "extract(year from authored_on) $order, 
    130                               extract(month from authored_on) $order, 
    131                               extract(day from authored_on) $order", 
     129                sort => [ 
     130                    { column => "extract(year from authored_on)", desc => $order }, 
     131                    { column => "extract(month from authored_on)", desc => $order }, 
     132                    { column => "extract(day from authored_on)", desc => $order }, 
     133                ], 
    132134                'join' => 
    133135                  [ 'MT::Placement', 'entry_id', { category_id => $c->id } ] 
  • branches/release-39/lib/MT/ArchiveType/CategoryMonthly.pm

    r2399 r2500  
    127127                    "extract(month from authored_on)" 
    128128                ], 
    129                 sort => "extract(year from authored_on) $order, 
    130                               extract(month from authored_on) $order", 
     129                sort => [ 
     130                    { column => "extract(year from authored_on)", desc => $order }, 
     131                    { column => "extract(month from authored_on)", desc => $order }, 
     132                ], 
    131133                'join' => 
    132134                  [ 'MT::Placement', 'entry_id', { category_id => $c->id } ] 
  • branches/release-39/lib/MT/ArchiveType/CategoryWeekly.pm

    r2399 r2500  
    128128                ( $ts && $tsend ? ( range_incl => { authored_on => 1 } ) : () ), 
    129129                group => ["week_number"], 
    130                 sort  => "week_number $order", 
     130                sort  => [ { column => "week_number", desc => $order } ], 
    131131                'join' => 
    132132                  [ 'MT::Placement', 'entry_id', { category_id => $c->id } ] 
  • branches/release-39/lib/MT/ArchiveType/CategoryYearly.pm

    r2399 r2500  
    120120            { 
    121121                group => ["extract(year from authored_on)"], 
    122                 sort  => "extract(year from authored_on) $order", 
     122                sort  => [ { column => "extract(year from authored_on)", desc => $order } ], 
    123123                'join' => 
    124124                  [ 'MT::Placement', 'entry_id', { category_id => $c->id } ] 
  • branches/release-39/lib/MT/ArchiveType/Daily.pm

    r1741 r2500  
    103103            ], 
    104104            $args->{lastn} ? ( limit => $args->{lastn} ) : (), 
    105             sort => "extract(year from authored_on) $order, 
    106                         extract(month from authored_on) $order, 
    107                         extract(day from authored_on) $order" 
     105            sort => [ 
     106                { column => "extract(year from authored_on)", desc => $order }, 
     107                { column => "extract(month from authored_on)", desc => $order }, 
     108                { column => "extract(day from authored_on)", desc => $order } 
     109            ], 
    108110        } 
    109111    ) or return $ctx->error("Couldn't get daily archive list"); 
  • branches/release-39/lib/MT/ArchiveType/Monthly.pm

    r1741 r2500  
    105105            ], 
    106106            $args->{lastn} ? ( limit => $args->{lastn} ) : (), 
    107             sort => "extract(year from authored_on) $order, 
    108                        extract(month from authored_on) $order" 
     107            sort => [ 
     108                { column => "extract(year from authored_on)", desc => $order }, 
     109                { column => "extract(month from authored_on)", desc => $order } 
     110            ], 
    109111        } 
    110112    ) or return $ctx->error("Couldn't get monthly archive list"); 
  • branches/release-39/lib/MT/ArchiveType/Weekly.pm

    r1741 r2500  
    101101            group => [ "week_number" ], 
    102102            $args->{lastn} ? ( limit => $args->{lastn} ) : (), 
    103             sort => "week_number $order" 
     103            sort => [ { column => "week_number", desc => $order } ], 
    104104        } 
    105105    ) or return $ctx->error("Couldn't get weekly archive list"); 
  • branches/release-39/lib/MT/ArchiveType/Yearly.pm

    r1741 r2500  
    103103            group => ["extract(year from authored_on)"], 
    104104            $args->{lastn} ? ( limit => $args->{lastn} ) : (), 
    105             sort => "extract(year from authored_on) $order" 
     105            sort => [ { column => "extract(year from authored_on)", desc => $order } ], 
    106106        } 
    107107    ) or return $ctx->error("Couldn't get yearly archive list"); 
  • branches/release-39/lib/MT/Object.pm

    r2483 r2500  
    17811781 
    17821782    sort => [ 
    1783         { column => "column_1", desc => "descend" }, 
     1783        { column => "column_1", desc => "DESC" }, 
    17841784        { column => "column_2", }   # default direction is 'ascend' 
    17851785    ] 
  • branches/release-39/lib/MT/ObjectDriver/Driver/DBI.pm

    r2475 r2500  
    137137    my $order = delete $args->{sort}; 
    138138    my $direction = delete $args->{direction}; 
     139    if ( $order =~ /\sdesc|asc/i ) { 
     140        my @new_order; 
     141        while ($order =~ /(?:\s*([\w\s\(\)]+?)\s(desc|asc))/ig) { 
     142            push @new_order, { column => $1, desc => $2 }; 
     143        } 
     144        $order = \@new_order if @new_order; 
     145    } 
    139146    my $limit = exists $args->{limit} ? delete $args->{limit} : undef; 
    140147    my $offset = exists $args->{offset} ? delete $args->{offset} : undef; 
  • branches/release-39/t/driver-tests.pl

    r2475 r2500  
    3333} 
    3434 
    35 plan tests => 184; 
     35plan tests => 197; 
    3636 
    3737package Zot; 
     
    400400sleep(2);  ## Sleep to ensure created_on timestamps are unique 
    401401 
     402# legacy way of specifying sort direction 
    402403my $cgb_iter = Bar->count_group_by({ 
    403404        status => '0', 
    404405    }, { 
    405406        group => [ 'foo_id' ], 
    406         sort => 'foo_id', 
    407         direction => 'descend', 
     407        sort => 'foo_id desc', 
    408408    }); 
    409409my ($count, $bfid, $month); 
     
    417417ok(!$cgb_iter->(), 'no $iter'); 
    418418 
    419 $cgb_iter = Bar->count_group_by(undef, { 
     419# new way of specifying sort direction 
     420my $cgb_iter2 = Bar->count_group_by({ 
     421        status => '0', 
     422    }, { 
     423        group => [ 'foo_id' ], 
     424        sort => 'foo_id', 
     425        direction => 'descend' 
     426    }); 
     427 
     428isa_ok($cgb_iter2, 'CODE'); 
     429ok(($count, $bfid) = $cgb_iter2->(), 'set'); 
     430is($bfid, $bar[1]->id, 'id'); 
     431is($count, 1, 'count4'); 
     432ok(($count, $bfid) = $cgb_iter2->(), 'set'); 
     433is($bfid, $bar[0]->id, 'id'); 
     434is($count, 1, 'count5'); 
     435ok(!$cgb_iter2->(), 'no $iter'); 
     436 
     437# legacy way of specifying sort direction 
     438my $cgb_iter3 = Bar->count_group_by(undef, { 
    420439        group => [ 'extract(month from created_on)' ], 
    421         sort => 'extract(month from created_on)', 
    422         direction => 'descend', 
     440        sort => 'extract(month from created_on) desc', 
    423441    }); 
    424 isa_ok($cgb_iter, 'CODE'); 
    425 ok(($count, $month) = $cgb_iter->(), 'set'); 
     442isa_ok($cgb_iter3, 'CODE'); 
     443ok(($count, $month) = $cgb_iter3->(), 'set'); 
    426444use POSIX qw(strftime); 
    427445is(int($month), int(strftime("%m", localtime)), 'month'); 
    428446is($count, 3, 'count6'); 
    429 ok(!$cgb_iter->(), 'no $iter'); 
     447ok(!$cgb_iter3->(), 'no $iter'); 
     448 
     449# new way of specifying sort direction 
     450my $cgb_iter4 = Bar->count_group_by(undef, { 
     451        group => [ 'extract(month from created_on)' ], 
     452        sort => [{ column => 'extract(month from created_on)', 
     453            desc => 'desc' }] 
     454    }); 
     455isa_ok($cgb_iter4, 'CODE'); 
     456ok(($count, $month) = $cgb_iter4->(), 'set'); 
     457is(int($month), int(strftime("%m", localtime)), 'month'); 
     458is($count, 3, 'count6'); 
     459ok(!$cgb_iter4->(), 'no $iter'); 
    430460 
    431461## Get a count of all Foo objects in order of most recently