Changeset 298

Show
Ignore:
Timestamp:
05/18/06 17:57:47 (6 years ago)
Author:
nick
Message:

Start on support for getting all the versions of a node out

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

Legend:

Unmodified
Added
Removed
  • wiki-toolkit/trunk/lib/Wiki/Toolkit.pm

    r258 r298  
    523523} 
    524524 
     525=item B<list_node_all_versions> 
     526 
     527  my @versions = $wiki->list_node_all_versions("HomePage"); 
     528 
     529  my @versions = $wiki->list_node_all_versions( 
     530                                                name => 'HomePage', 
     531                                                with_content => 1, 
     532                                                with_metadata => 0 
     533                 ); 
     534 
     535Returns all the versions of a node, optionally including the content 
     536and metadata, as an array of hashes (newest versions first). 
     537=cut 
     538sub list_node_all_versions { 
     539    my ($self,@argsarray) = @_; 
     540 
     541    my %args; 
     542    if(scalar @argsarray == 1) { 
     543        $args{'name'} = $argsarray[0]; 
     544    } else { 
     545        %args = @argsarray; 
     546    } 
     547 
     548    return $self->store->list_node_all_versions(%args); 
     549} 
     550 
    525551=item B<node_exists> 
    526552 
  • wiki-toolkit/trunk/lib/Wiki/Toolkit/Feed/Listing.pm

    r297 r298  
    6363} 
    6464 
     65 
     66=item B<fetch_node_all_versions> 
     67 
     68For a given node (name or ID), return all the versions there have been, 
     69including all metadata required for it to go into a "recent changes" 
     70style listing. 
     71 
     72=cut 
     73sub fetch_node_all_versions { 
     74    my ($self, %args) = @_; 
     75 
     76    # TODO. Will make use of store->list_node_all_versions() 
     77} 
     78 
    65791; 
  • wiki-toolkit/trunk/lib/Wiki/Toolkit/Store/Database.pm

    r235 r298  
    14151415} 
    14161416 
     1417=item B<list_node_all_versions> 
     1418 
     1419  my @all_versions = $store->list_node_all_versions( 
     1420                                                                                name => 'HomePage', 
     1421                                                                                with_content => 1, 
     1422                                                                                with_metadata => 0 
     1423                                         ); 
     1424 
     1425Returns all the versions of a node, optionally including the content 
     1426and metadata, as an array of hashes (newest versions first). 
     1427 
     1428=cut 
     1429 
     1430sub list_node_all_versions { 
     1431    my ($self, %args) = @_; 
     1432 
     1433        my ($node_id,$name,$with_content,$with_metadata) =  
     1434                        @args{ qw( node_id name with_content with_metadata ) }; 
     1435 
     1436    my $dbh = $self->dbh; 
     1437        my $sql; 
     1438 
     1439        # If they only gave us the node name, get the node id 
     1440    $sql = "SELECT id FROM node WHERE name=" . $dbh->quote($name); 
     1441    my ($node_id) = $dbh->selectrow_array($sql); 
     1442 
     1443        # If they didn't tell us what they wanted / we couldn't find it,  
     1444        #  return an empty array 
     1445        return () unless($node_id); 
     1446 
     1447 
     1448        # Build up our SQL 
     1449        my $sql = "SELECT id, name, content.version, content.modified "; 
     1450        if($with_content) { 
     1451                $sql .= ", content.text "; 
     1452        } 
     1453        if($with_metadata) { 
     1454                $sql .= ", metadata_type, metadata_value "; 
     1455        } 
     1456        $sql .= " FROM node INNER JOIN content ON (id = node_id) "; 
     1457        if($with_metadata) { 
     1458                $sql .= " LEFT OUTER JOIN metadata ON (id = node_id AND content.version = metadata.version) "; 
     1459        } 
     1460        $sql .= " WHERE id = ? ORDER BY content.version DESC"; 
     1461 
     1462        # Do the fetch 
     1463    my $sth = $dbh->prepare( $sql ); 
     1464    $sth->execute( $node_id ); 
     1465 
     1466        # Haul out the data 
     1467        my @versions; 
     1468        while(my @results = $sth->fetchrow_array) { 
     1469                # TODO: Support metadata multi-rows 
     1470                my %data; 
     1471                @data{ qw( node_id name version last_modified ) } = @results; 
     1472 
     1473                my $i = 4; 
     1474                if($with_content) { 
     1475                        $data{'content'} = $results[$i]; 
     1476                        $i++; 
     1477                } 
     1478                if($with_metadata) { 
     1479                        warn("Not supported properly yet"); 
     1480                } 
     1481 
     1482                push @versions, \%data; 
     1483        } 
     1484 
     1485        # Return 
     1486        return @versions; 
     1487} 
     1488 
    14171489=item B<list_nodes_by_metadata> 
    14181490