Changeset 24


Ignore:
Timestamp:
Jun 10, 2004, 7:47:57 PM (17 years ago)
Author:
kake
Message:

Added include_all_changes and between_days to list_recent_changes.

Location:
cgi-wiki/trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • cgi-wiki/trunk/Changes

    r21 r24  
     10.52    10 June 2004
     2        Add include_all_changes and between_days to list_recent_changes.
     3
    140.51    8 June 2004
    25        Time for a non-developer release.
  • cgi-wiki/trunk/lib/CGI/Wiki.pm

    r21 r24  
    44
    55use vars qw( $VERSION );
    6 $VERSION = '0.51';
     6$VERSION = '0.52';
    77
    88use Carp qw(croak carp);
     
    316316=item B<list_recent_changes>
    317317
    318   # Changes in last 7 days.
     318  # Nodes changed in last 7 days - each node listed only once.
    319319  my @nodes = $wiki->list_recent_changes( days => 7 );
     320
     321  # All changes in last 7 days - nodes changed more than once will
     322  # be listed more than once.
     323  my @nodes = $wiki->list_recent_changes(
     324                                          days => 7,
     325                                          include_all_changes => 1,
     326                                        );
     327
     328  # Nodes changed between 1 and 7 days ago.
     329  my @nodes = $wiki->list_recent_changes( between_days => [ 1, 7 ] );
    320330
    321331  # Changes since a given time.
     
    374384=back
    375385
    376 Unless you supply C<metadata_was> or C<metadata_wasnt>, each node will
    377 only be returned once, regardless of how many times it has been
    378 changed recently.
     386Unless you supply C<include_all_changes>, C<metadata_was> or
     387C<metadata_wasnt>, each node will only be returned once regardless of
     388how many times it has been changed recently.
    379389
    380390=cut
     
    817827=head1 COPYRIGHT
    818828
    819      Copyright (C) 2002-2003 Kake Pugh.  All Rights Reserved.
     829     Copyright (C) 2002-2004 Kake Pugh.  All Rights Reserved.
    820830
    821831This module is free software; you can redistribute it and/or modify it
  • cgi-wiki/trunk/lib/CGI/Wiki/Store/Database.pm

    r19 r24  
    532532=item B<list_recent_changes>
    533533
    534   # Changes in last 7 days.
     534  # Nodes changed in last 7 days - each node listed only once.
    535535  my @nodes = $store->list_recent_changes( days => 7 );
    536536
    537   # Changes since a given time.
     537  # All changes in last 7 days - nodes changed more than once will
     538  # be listed more than once.
     539  my @nodes = $store->list_recent_changes(
     540                                           days => 7,
     541                                           include_all_changes => 1,
     542                                         );
     543
     544  # Nodes changed between 1 and 7 days ago.
     545  my @nodes = $store->list_recent_changes( between_days => [ 1, 7 ] );
     546
     547  # Nodes changed since a given time.
    538548  my @nodes = $store->list_recent_changes( since => 1036235131 );
    539549
     
    591601=back
    592602
    593 Unless you supply C<metadata_was> or C<metadata_wasnt>, each node will
    594 only be returned once, regardless of how many times it has been
    595 changed recently.
     603Unless you supply C<include_all_changes>, C<metadata_was> or
     604C<metadata_wasnt>, each node will only be returned once regardless of
     605how many times it has been changed recently.
    596606
    597607B<Future plans and thoughts for list_recent_changes>
     
    623633    my %args = @_;
    624634    if ($args{since}) {
     635        return $self->_find_recent_changes_by_criteria( %args );
     636    } elsif ($args{between_days}) {
    625637        return $self->_find_recent_changes_by_criteria( %args );
    626638    } elsif ( $args{days} ) {
     
    634646        return $self->_find_recent_changes_by_criteria( %args );
    635647    } else {
    636         croak "Need to supply a parameter";
     648        croak "Need to supply some criteria to list_recent_changes.";
    637649    }
    638650}
     
    640652sub _find_recent_changes_by_criteria {
    641653    my ($self, %args) = @_;
    642     my ($since, $limit, $metadata_is,  $metadata_isnt,
    643                         $metadata_was, $metadata_wasnt ) =
    644                              @args{ qw( since limit metadata_is metadata_isnt
    645                                                 metadata_was metadata_wasnt) };
     654    my ($since, $limit, $between_days,
     655        $metadata_is,  $metadata_isnt, $metadata_was, $metadata_wasnt ) =
     656         @args{ qw( since limit between_days
     657                    metadata_is metadata_isnt metadata_was metadata_wasnt) };
    646658    my $dbh = $self->dbh;
    647659
    648660    my @where;
    649     my $main_table = "node";
     661    my $main_table = $args{include_all_changes} ? "content" : "node";
    650662    if ( $metadata_is ) {
    651663        if ( scalar keys %$metadata_is > 1 ) {
     
    694706        my @omits = $self->_find_recent_changes_by_criteria(
    695707            since        => $since,
     708            between_days => $between_days,
    696709            metadata_was => $metadata_wasnt,
    697710        );
     
    706719        my $timestamp = $self->_get_timestamp( $since );
    707720        push @where, "$main_table.modified >= " . $dbh->quote($timestamp);
     721    } elsif ( $between_days ) {
     722        my $now = localtime;
     723        # Start is the larger number of days ago.
     724        my ($start, $end) = @$between_days;
     725        ($start, $end) = ($end, $start) if $start < $end;
     726        my $ts_start = $self->_get_timestamp( $now - (ONE_DAY * $start) );
     727        my $ts_end = $self->_get_timestamp( $now - (ONE_DAY * $end) );
     728        push @where, "$main_table.modified >= " . $dbh->quote($ts_start);
     729        push @where, "$main_table.modified <= " . $dbh->quote($ts_end);
    708730    }
    709731
  • cgi-wiki/trunk/t/011_recent_changes.t

    r23 r24  
    66    plan skip_all => "no backends configured";
    77} else {
    8     plan tests => ( 25 * scalar @CGI::Wiki::TestLib::wiki_info );
     8    plan tests => ( 26 * scalar @CGI::Wiki::TestLib::wiki_info );
    99}
    1010
     
    144144    is( scalar @nodes, 3,
    145145        "By default each node returned only once however many times changed" );
     146
     147    @nodes = $wiki->list_recent_changes( days => 1, include_all_changes => 1 );
     148    is( scalar @nodes, 4,
     149        "...returned more than once when 'include_all_changes' set" );
    146150
    147151    @nodes = $wiki->list_recent_changes(
Note: See TracChangeset for help on using the changeset viewer.