Changeset 1317


Ignore:
Timestamp:
Apr 2, 2012, 9:35:16 AM (10 years ago)
Author:
kake
Message:

Fixed bug where missing metadata search was picking up redirect pages.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/OpenGuides.pm

    r1309 r1317  
    20102010=item B<show_missing_metadata>
    20112011
    2012 Search for nodes which don't have a certain kind of metadata. Optionally
    2013 also excludes Locales and Categories
     2012Search for nodes which don't have a certain kind of metadata.  Excludes nodes
     2013which are pure redirects, and optionally also excludes locales and categories.
    20142014
    20152015=cut
     
    20332033    if($metadata_type) {
    20342034        $done_search = 1;
    2035         @nodes = $wiki->list_nodes_by_missing_metadata(
     2035        my @all_nodes = $wiki->list_nodes_by_missing_metadata(
    20362036                            metadata_type => $metadata_type,
    20372037                            metadata_value => $metadata_value,
     
    20392039        );
    20402040
    2041         # Do we need to filter some nodes out?
    2042         if($exclude_locales || $exclude_categories) {
    2043             my @all_nodes = @nodes;
    2044             @nodes = ();
    2045 
    2046             foreach my $node (@all_nodes) {
    2047                 if($exclude_locales && $node =~ /^Locale /) { next; }
    2048                 if($exclude_categories && $node =~ /^Category /) { next; }
    2049                 push @nodes, $node;
    2050             }
     2041        # Filter out redirects; also filter out locales/categories if required.
     2042        foreach my $node ( @all_nodes ) {
     2043            next if ( $exclude_locales && $node =~ /^Locale / );
     2044            next if ( $exclude_categories && $node =~ /^Category / );
     2045            my $content = $wiki->retrieve_node( $node );
     2046            next if OpenGuides::Utils->detect_redirect( content => $content );
     2047            push @nodes, $node;
    20512048        }
    20522049    }
  • trunk/t/71_missing_metadata.t

    r1273 r1317  
    2525
    2626
    27 # Add 3 different pages, one of which with two versions
     27# Add four different pages, one of which with two versions, one of which
     28# a redirect.  The redirect should not show up on any "missing metadata"
     29# searches, regardless of the condition of the page it points to.
    2830$wiki->write_node( "Test Page", "foo", undef,
    2931                   { category => "Alpha", lat=>"" } )
     
    4547                   { category => "Locales", lat=>"8.88" } )
    4648  or die "Couldn't write locale for the 2nd time";
    47 
     49OpenGuides::Test->write_data(
     50                              guide => $guide,
     51                              node  => "Redirect Test",
     52                              content => "#REDIRECT [[Test Page]]",
     53                              return_output => 1,
     54                            );
    4855
    4956# Try without search parameters
     
    113120    $guide->show_missing_metadata( return_output=>1 );
    114121};
    115 is( $@, "", "->how_missing_metadata doesn't die" );
     122is( $@, "", "->show_missing_metadata doesn't die" );
    116123
    117124like( $output, qr|Missing Metadata|, "Right page" );
     
    122129    $guide->show_missing_metadata( return_output=>1, metadata_type=>'lat' );
    123130};
    124 is( $@, "", "->how_missing_metadata doesn't die" );
     131is( $@, "", "->show_missing_metadata doesn't die" );
    125132like( $output, qr|<h3>Pages</h3>|, "searched" );
    126133like( $output, qr|Test Page|, "had node" );
Note: See TracChangeset for help on using the changeset viewer.