Author: kake Date: 2012-04-02 09:35:16 +0100 (Mon, 02 Apr 2012) New Revision: 1317
Modified: trunk/lib/OpenGuides.pm trunk/t/71_missing_metadata.t Log: Fixed bug where missing metadata search was picking up redirect pages.
Modified: trunk/lib/OpenGuides.pm =================================================================== --- trunk/lib/OpenGuides.pm 2012-03-20 12:16:15 UTC (rev 1316) +++ trunk/lib/OpenGuides.pm 2012-04-02 08:35:16 UTC (rev 1317) @@ -2009,8 +2009,8 @@
=item B<show_missing_metadata>
-Search for nodes which don't have a certain kind of metadata. Optionally -also excludes Locales and Categories +Search for nodes which don't have a certain kind of metadata. Excludes nodes +which are pure redirects, and optionally also excludes locales and categories.
=cut
@@ -2032,22 +2032,19 @@ # Only search if they supplied at least a metadata type if($metadata_type) { $done_search = 1; - @nodes = $wiki->list_nodes_by_missing_metadata( + my @all_nodes = $wiki->list_nodes_by_missing_metadata( metadata_type => $metadata_type, metadata_value => $metadata_value, ignore_case => 1, );
- # Do we need to filter some nodes out? - if($exclude_locales || $exclude_categories) { - my @all_nodes = @nodes; - @nodes = (); - - foreach my $node (@all_nodes) { - if($exclude_locales && $node =~ /^Locale /) { next; } - if($exclude_categories && $node =~ /^Category /) { next; } - push @nodes, $node; - } + # Filter out redirects; also filter out locales/categories if required. + foreach my $node ( @all_nodes ) { + next if ( $exclude_locales && $node =~ /^Locale / ); + next if ( $exclude_categories && $node =~ /^Category / ); + my $content = $wiki->retrieve_node( $node ); + next if OpenGuides::Utils->detect_redirect( content => $content ); + push @nodes, $node; } }
Modified: trunk/t/71_missing_metadata.t =================================================================== --- trunk/t/71_missing_metadata.t 2012-03-20 12:16:15 UTC (rev 1316) +++ trunk/t/71_missing_metadata.t 2012-04-02 08:35:16 UTC (rev 1317) @@ -24,7 +24,9 @@
-# Add 3 different pages, one of which with two versions +# Add four different pages, one of which with two versions, one of which +# a redirect. The redirect should not show up on any "missing metadata" +# searches, regardless of the condition of the page it points to. $wiki->write_node( "Test Page", "foo", undef, { category => "Alpha", lat=>"" } ) or die "Couldn't write node"; @@ -44,8 +46,13 @@ $wiki->write_node( "Locale Bar", "foo version 2", $data{checksum}, { category => "Locales", lat=>"8.88" } ) or die "Couldn't write locale for the 2nd time"; +OpenGuides::Test->write_data( + guide => $guide, + node => "Redirect Test", + content => "#REDIRECT [[Test Page]]", + return_output => 1, + );
- # Try without search parameters my %ttvars = eval { $guide->show_missing_metadata( return_tt_vars=> 1 ); @@ -112,7 +119,7 @@ my $output = eval { $guide->show_missing_metadata( return_output=>1 ); }; -is( $@, "", "->how_missing_metadata doesn't die" ); +is( $@, "", "->show_missing_metadata doesn't die" );
like( $output, qr|Missing Metadata|, "Right page" ); like( $output, qr|Metadata Type|, "Has prompts" ); @@ -121,6 +128,6 @@ $output = eval { $guide->show_missing_metadata( return_output=>1, metadata_type=>'lat' ); }; -is( $@, "", "->how_missing_metadata doesn't die" ); +is( $@, "", "->show_missing_metadata doesn't die" ); like( $output, qr|<h3>Pages</h3>|, "searched" ); like( $output, qr|Test Page|, "had node" );
openguides-commits@lists.openguides.org