Changeset 454

Show
Ignore:
Timestamp:
10/18/08 13:48:32 (4 years ago)
Author:
nick
Message:

Complete support for store->list_metadata_by_type, which returns a list of all the metadata values

Location:
wiki-toolkit/trunk
Files:
1 added
3 modified

Legend:

Unmodified
Added
Removed
  • wiki-toolkit/trunk/Changes

    r452 r454  
     10.77    ??? 
     2        Complete support for store->list_metadata_by_type, which 
     3          returns a list of all the metadata values 
     4 
    150.76    13 July 2008 
    26        Really add missing prereq of DBI! 
  • wiki-toolkit/trunk/MANIFEST

    r447 r454  
    6565t/052_sqlite_store.t 
    6666t/060_recent_changes_new_only.t 
     67t/061_list_metadata_by_type.t 
    6768t/100_formatting.t 
    6869t/101_default_formatter.t 
  • wiki-toolkit/trunk/lib/Wiki/Toolkit/Store/Database.pm

    r449 r454  
    19541954    List all the currently defined values of the given type of metadata. 
    19551955 
    1956     Will only work with the latest moderated version 
     1956    Will only return data from the latest moderated version of each node 
    19571957 
    19581958    # List all of the different metadata values with the type 'category' 
     
    19641964    my ($self, $type) = @_; 
    19651965 
    1966     return 0 unless $type; 
     1966    return undef unless $type; 
     1967    my $dbh = $self->dbh; 
     1968 
     1969    # Ideally we'd do this as one big query 
     1970    # However, this would need a temporary table on many 
     1971    #  database engines, so we cheat and do it as two 
     1972    my $nv_sql =  
     1973       "SELECT node_id, MAX(version) ". 
     1974       "FROM content ". 
     1975       "WHERE moderated ". 
     1976       "GROUP BY node_id "; 
     1977    my $sth = $dbh->prepare( $nv_sql ); 
     1978    $sth->execute(); 
     1979 
     1980    my @nv_where; 
     1981    while(my @results = $sth->fetchrow_array) { 
     1982        my ($node_id, $version) = @results; 
     1983        my $where = "(node_id=$node_id AND version=$version)"; 
     1984        push @nv_where, $where; 
     1985    } 
     1986 
     1987    # Now the metadata bit 
     1988    my $sql =  
     1989       "SELECT DISTINCT metadata_value ". 
     1990       "FROM metadata ". 
     1991       "WHERE metadata_type = ? ". 
     1992       "AND (". 
     1993       join(" OR ", @nv_where). 
     1994       ")"; 
     1995    $sth = $dbh->prepare( $sql ); 
     1996    $sth->execute($type); 
     1997 
     1998    my $values = $sth->fetchall_arrayref([0]); 
     1999    return ( map { $self->charset_decode( $_->[0] ) } (@$values) ); 
    19672000} 
    19682001