[MTOS-dev] [movabletype] takayama, r1616: Fixed BugId:70976

Hirotaka Ogawa hirotaka.ogawa at gmail.com
Fri Mar 28 07:47:11 PDT 2008


This changset is no good. Because,
MT::ArchiveType::Category->get_adjacent_category_entry() and
MT::ArchiveType::Author->get_adjacent_author_entry() could be called
not only for category_based+date_based and author_based+date_based
archivers, but also for Category or Author archivers.

Please consult: http://pastie.org/172017

Part of my intention of this patch is to provide a set of common
interfaces to all date_based archivers, that is next_archive_entry()
and previous_archive_entry().  They are basically intended to pick up
one of entries included in the next or previous date_based archives.
And if the archiver is category_based or author_based, as well as
date_based, they'll pick up one of entries included in the next or
previous category_based+date_based or author_based+date_based
archives.

I think this is quote a reasonable interface design.



On Fri, Mar 28, 2008 at 9:12 PM,  <commits at code.sixapart.com> wrote:
> Fixed BugId:70976
>  * Applied ogawa-san's suggestion
>
>
>  U   branches/release-32/lib/MT/ArchiveType/Author.pm
>  U   branches/release-32/lib/MT/ArchiveType/Category.pm
>  U   branches/release-32/lib/MT/ArchiveType/Date.pm
>  U   branches/release-32/lib/MT/Page.pm
>  U   branches/release-32/lib/MT/Template/ContextHandlers.pm
>  U   branches/release-32/lib/MT/Util.pm
>  U   branches/release-32/lib/MT/WeblogPublisher.pm
>
>
>  Modified: branches/release-32/lib/MT/ArchiveType/Author.pm
>  ===================================================================
>  --- branches/release-32/lib/MT/ArchiveType/Author.pm    2008-03-28 05:00:17 UTC (rev 1615)
>  +++ branches/release-32/lib/MT/ArchiveType/Author.pm    2008-03-28 12:12:37 UTC (rev 1616)
>  @@ -209,4 +209,30 @@
>      \@entries;
>   }
>
>  +sub get_adjacent_author_entry {
>  +    my $self = shift;
>  +    my ( $ts, $blog_id, $author, $order ) = @_;
>  +    if ( $order eq 'previous' ) {
>  +        $order = 'descend';
>  +    }
>  +    else {
>  +        $order = 'ascend';
>  +    }
>  +    require MT::Entry;
>  +    my $entry = MT::Entry->load(
>  +        {
>  +            status    => MT::Entry::RELEASE(),
>  +            author_id => $author->id,
>  +            blog_id   => $blog_id
>  +        },
>  +        {
>  +            limit     => 1,
>  +            'sort'    => 'authored_on',
>  +            direction => $order,
>  +            start_val => $ts
>  +        }
>  +    );
>  +    $entry;
>  +}
>  +
>   1;
>
>  Modified: branches/release-32/lib/MT/ArchiveType/Category.pm
>  ===================================================================
>  --- branches/release-32/lib/MT/ArchiveType/Category.pm  2008-03-28 05:00:17 UTC (rev 1615)
>  +++ branches/release-32/lib/MT/ArchiveType/Category.pm  2008-03-28 12:12:37 UTC (rev 1616)
>  @@ -176,4 +176,29 @@
>      return 1;
>   }
>
>  +sub get_adjacent_category_entry {
>  +    my $self = shift;
>  +    my ( $ts, $cat, $order ) = @_;
>  +    if ( $order eq 'previous' ) {
>  +        $order = 'descend';
>  +    }
>  +    else {
>  +        $order = 'ascend';
>  +    }
>  +    require MT::Entry;
>  +    require MT::Placement;
>  +    my $entry = MT::Entry->load(
>  +        { status => MT::Entry::RELEASE() },
>  +        {
>  +            limit     => 1,
>  +            'sort'    => 'authored_on',
>  +            direction => $order,
>  +            start_val => $ts,
>  +            'join' =>
>  +              [ 'MT::Placement', 'entry_id', { category_id => $cat->id } ]
>  +        }
>  +    );
>  +    $entry;
>  +}
>  +
>   1;
>
>  Modified: branches/release-32/lib/MT/ArchiveType/Date.pm
>  ===================================================================
>  --- branches/release-32/lib/MT/ArchiveType/Date.pm      2008-03-28 05:00:17 UTC (rev 1615)
>  +++ branches/release-32/lib/MT/ArchiveType/Date.pm      2008-03-28 12:12:37 UTC (rev 1616)
>  @@ -101,4 +101,32 @@
>      \@entries;
>   }
>
>  +sub get_entry {
>  +    my $archiver = shift;
>  +    my ( $ts, $blog_id, $order ) = @_;
>  +    my ( $start, $end ) = $archiver->date_range($ts);
>  +    if ( $order eq 'previous' ) {
>  +        $order = 'descend';
>  +        $ts    = $start;
>  +    }
>  +    else {
>  +        $order = 'ascend';
>  +        $ts    = $end;
>  +    }
>  +
>  +    my $entry = MT->model('entry')->load(
>  +        {
>  +            blog_id => $blog_id,
>  +            status  => MT::Entry::RELEASE()
>  +        },
>  +        {
>  +            limit     => 1,
>  +            'sort'    => 'authored_on',
>  +            direction => $order,
>  +            start_val => $ts
>  +        }
>  +    );
>  +    $entry;
>  +}
>  +
>   1;
>
>  Modified: branches/release-32/lib/MT/Page.pm
>  ===================================================================
>  --- branches/release-32/lib/MT/Page.pm  2008-03-28 05:00:17 UTC (rev 1615)
>  +++ branches/release-32/lib/MT/Page.pm  2008-03-28 12:12:37 UTC (rev 1616)
>  @@ -64,10 +64,4 @@
>      return ($page->permalink(@_));
>   }
>
>  -# This routine is declared to avoid building 'previous'/'next' pages
>  -# by MT's rebuild process.
>  -sub get_entry {
>  -    return undef;
>  -}
>  -
>   1;
>
>  Modified: branches/release-32/lib/MT/Template/ContextHandlers.pm
>  ===================================================================
>  --- branches/release-32/lib/MT/Template/ContextHandlers.pm      2008-03-28 05:00:17 UTC (rev 1615)
>  +++ branches/release-32/lib/MT/Template/ContextHandlers.pm      2008-03-28 12:12:37 UTC (rev 1616)
>  @@ -5605,45 +5605,6 @@
>   }
>
>   ## Archives
>  -sub _get_adjacent_category_entry {
>  -    my($ts, $cat, $order) = @_;
>  -    if ($order eq 'previous') {
>  -        $order = 'descend';
>  -    } else {
>  -        $order = 'ascend';
>  -    }
>  -    require MT::Entry;
>  -    require MT::Placement;
>  -    my $entry = MT::Entry->load(
>  -        { status => MT::Entry::RELEASE() },
>  -        { limit => 1,
>  -          'sort' => 'authored_on',
>  -          direction => $order,
>  -          start_val => $ts,
>  -          'join' => [ 'MT::Placement', 'entry_id',
>  -            { category_id => $cat->id } ] });
>  -    $entry;
>  -}
>  -
>  -sub _get_adjacent_author_entry {
>  -    my($ts, $blog_id, $author, $order) = @_;
>  -    if ($order eq 'previous') {
>  -        $order = 'descend';
>  -    } else {
>  -        $order = 'ascend';
>  -    }
>  -    require MT::Entry;
>  -    my $entry = MT::Entry->load(
>  -        { status => MT::Entry::RELEASE(),
>  -          author_id => $author->id,
>  -          blog_id => $blog_id },
>  -        { limit => 1,
>  -          'sort' => 'authored_on',
>  -          direction => $order,
>  -          start_val => $ts});
>  -    $entry;
>  -}
>  -
>   sub _hdlr_archive_prev_next {
>      my($ctx, $args, $cond) = @_;
>      my $tag = lc $ctx->stash('tag');
>  @@ -5659,9 +5620,9 @@
>          $start = $ctx->{current_timestamp};
>          $end = $ctx->{current_timestamp_end};
>          if ($is_prev) {
>  -            $entry = _get_adjacent_category_entry( $start, $cat, 'previous' );
>  +            $entry = $arctype->get_adjacent_category_entry( $start, $cat, 'previous' );
>          } else {
>  -            $entry = _get_adjacent_category_entry( $end, $cat, 'next' );
>  +            $entry = $arctype->get_adjacent_category_entry( $end, $cat, 'next' );
>          }
>      } elsif ($arctype->date_based && $arctype->author_based) {
>          my $author = $ctx->stash('author');
>  @@ -5669,9 +5630,9 @@
>          $start = $ctx->{current_timestamp};
>          $end = $ctx->{current_timestamp_end};
>          if ($is_prev) {
>  -            $entry = _get_adjacent_author_entry( $start, $blog->id, $author, 'previous' );
>  +            $entry = $arctype->get_adjacent_author_entry( $start, $blog->id, $author, 'previous' );
>          } else {
>  -            $entry = _get_adjacent_author_entry( $end, $blog->id, $author, 'next' );
>  +            $entry = $arctype->get_adjacent_author_entry( $end, $blog->id, $author, 'next' );
>          }
>      } elsif ($arctype->category_based) {
>          return _hdlr_category_prevnext(@_);
>
>  Modified: branches/release-32/lib/MT/Util.pm
>  ===================================================================
>  --- branches/release-32/lib/MT/Util.pm  2008-03-28 05:00:17 UTC (rev 1615)
>  +++ branches/release-32/lib/MT/Util.pm  2008-03-28 12:12:37 UTC (rev 1616)
>  @@ -961,7 +961,15 @@
>   }
>
>   sub get_entry {
>  -    MT->instance->publisher->get_entry(@_);
>  +    my ( $ts, $blog_id, $at, $order ) = @_;
>  +    my $archiver = MT->instance->publisher->archiver($at)
>  +        or return;
>  +
>  +    if ($archiver->can('get_entry')) {
>  +        return $archiver->get_entry($ts, $blog_id, $order);
>  +    }
>  +
>  +    return;
>   }
>
>   sub is_valid_date {
>
>  Modified: branches/release-32/lib/MT/WeblogPublisher.pm
>  ===================================================================
>  --- branches/release-32/lib/MT/WeblogPublisher.pm       2008-03-28 05:00:17 UTC (rev 1615)
>  +++ branches/release-32/lib/MT/WeblogPublisher.pm       2008-03-28 12:12:37 UTC (rev 1616)
>  @@ -465,9 +465,9 @@
>          my @db_at = grep { my $archiver = $mt->archiver($_); $archiver && $archiver->date_based } $mt->archive_types;
>          for my $at (@db_at) {
>              if ( $at{$at} ) {
>  -                my @arg = ( $entry->authored_on, $entry->blog_id, $at );
>  +                my @arg = ( $entry->authored_on, $entry->blog_id );
>                  my $archiver = $mt->archiver($at);
>  -                if ( my $prev_arch = $mt->get_entry( @arg, 'previous' ) ) {
>  +                if ( my $prev_arch = $archiver->get_entry( @arg, 'previous' ) ) {
>                      if ( $archiver->category_based ) {
>                          my $cats = $prev_arch->categories;
>                          for my $cat (@$cats) {
>  @@ -496,7 +496,7 @@
>                          ) or return;
>                      }
>                  }
>  -                if ( my $next_arch = $mt->get_entry( @arg, 'next' ) ) {
>  +                if ( my $next_arch = $archiver->get_entry( @arg, 'next' ) ) {
>                      if ( $archiver->category_based ) {
>                          my $cats = $next_arch->categories;
>                          for my $cat (@$cats) {
>  @@ -1738,35 +1738,6 @@
>      $file;
>   }
>
>  -sub get_entry {
>  -    my $mt = shift;
>  -    my ( $ts, $blog_id, $at, $order ) = @_;
>  -    my $archiver = $mt->archiver($at);
>  -    my ( $start, $end ) = $archiver->date_range($ts);
>  -    if ( $order eq 'previous' ) {
>  -        $order = 'descend';
>  -        $ts    = $start;
>  -    }
>  -    else {
>  -        $order = 'ascend';
>  -        $ts    = $end;
>  -    }
>  -    require MT::Entry;
>  -    my $entry = MT::Entry->load(
>  -        {
>  -            blog_id => $blog_id,
>  -            status  => MT::Entry::RELEASE()
>  -        },
>  -        {
>  -            limit     => 1,
>  -            'sort'    => 'authored_on',
>  -            direction => $order,
>  -            start_val => $ts
>  -        }
>  -    );
>  -    $entry;
>  -}
>  -
>   # Adds an element to the rebuild queue when the plugin is enabled.
>   sub queue_build_file_filter {
>      my $mt = shift;
>
>
>  _______________________________________________
>  MTOS-commits mailing list
>  MTOS-commits at sixapart.com
>  http://www.sixapart.com/mailman/listinfo/mtos-commits
>



-- 
Hirotaka Ogawa makes no sense.
http://as-is.net/blog/


More information about the MTOS-dev mailing list