Skip to content

Commit

Permalink
Fixed MTEntryAssets/MTPageAssets bug with lastn="N" and sort_order="a…
Browse files Browse the repository at this point in the history
…scend" which did not work properly on static. bugid:114272
  • Loading branch information
hidekanazawa committed Sep 22, 2017
1 parent 8a5762e commit 3e01418
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/MT/Template/Tags/Asset.pm
Expand Up @@ -449,7 +449,11 @@ sub _hdlr_assets {
}
if ( my $last = $args->{lastn} || $args->{limit} ) {
if ( scalar @assets > $last ) {
@assets = @assets[ 0 .. $last - 1 ];
if( $args->{lastn} && $args->{sort_order} eq 'ascend' ){
@assets = @assets[ $#assets - $last + 1 .. $#assets ];
}else{
@assets = @assets[ 0 .. $last - 1 ];
}
}
}
}
Expand Down

4 comments on commit 3e01418

@yuji
Copy link
Contributor

@yuji yuji commented on 3e01418 Nov 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ちょっとこのコミットの意味がわからない・・・。

MTAssets は lastn="5" で Find the newest 5 assets sorted by descend and ascend. が取れてるけど、
MT(Entry|Page)Assets だとFind the oldest 5 assets sorted by descend and latest 5 assets sorted by ascend.

というところが問題だと言っているのだと思ったので @assets のソートに問題が有るんじゃないかと思ったけどそういうことでは無かったということですか?

@hidekanazawa
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<mt:PageAssets sort_order="ascend" lastn="N">を実行すると、Staticのときはlastnではなくlimitの結果になってしまっていました。

@yuji
Copy link
Contributor

@yuji yuji commented on 3e01418 Nov 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@assets = @assets[ $#assets - $last + 1 .. $#assets ];

これはどういう意味ですか?

@hidekanazawa
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@assetsの後ろ$last個の部分配列を@assetsに入れています。

Please sign in to comment.