added only_increment param to all action=browse links
[BackupPC.git] / lib / BackupPC / Search.pm
index cbd8c84..1c3007f 100644 (file)
@@ -32,7 +32,7 @@ sub search_module {
        if ( $@ ) {
                warn "ERROR: $search_module: $!";
        } else {
-               warn "# using $search_module for full-text search";
+               #warn "# using $search_module for full-text search";
        }
 
        return $search_module->new( %Conf );
@@ -45,7 +45,7 @@ sub get_dbh {
        return $dbh;
 }
 
-sub getUnits() {
+sub getShares {
        my @ret;
 
        my $dbh = get_dbh();
@@ -61,6 +61,9 @@ sub getUnits() {
        push @ret, { 'id' => '', 'share' => '-'};       # dummy any
 
        while ( my $row = $sth->fetchrow_hashref() ) {
+               if ( my $hide = $Conf{SearchHideShare} ) {
+                       next if $row->{share} =~ m/$hide/;
+               }
                push @ret, $row;
        }
        return @ret;
@@ -227,24 +230,25 @@ sub getFiles($) {
 
        my $order = getSort('search', 'sql', $param->{'sort'});
 
+       # XXX LIMIT $on_page doesn't work since we don't get correct number of results
        my $sql_order = qq{
                ORDER BY $order
-               LIMIT $on_page
                OFFSET ?
        };
 
        my $sql_results = qq{ select $sql_cols $sql_from $sql_where $sql_order };
        my $sth = $dbh->prepare($sql_results);
-       $sth->execute( $offset );
+       my $rows = $sth->execute( $offset );
 
        my @ret;
-      
+
        while (my $row = $sth->fetchrow_hashref()) {
                push @ret, $row;
+               last if $#ret + 1 >= $on_page;
        }
      
        $sth->finish();
-       return ($sth->rows, \@ret);
+       return ($rows, \@ret);
 }
 
 sub getFilesHyperEstraier($) {
@@ -353,6 +357,45 @@ sub getGzipSize($$)
        );
 }
 
+sub host_backup_nums {
+       my $host = shift;
+       my $sth = get_dbh->prepare(qq{
+               select
+                       hosts.name as host, -- FIXME for debug
+                       backups.num as num,
+                       inc_size,
+                       size,
+                       inc_deleted
+               from backups
+               join hosts on hosts.id = hostid
+               where hosts.name = ?
+       });
+       $sth->execute($host);
+       # and inc_size < 0 and size > 0 and not inc_deleted
+
+       my $all_backup_numbers;
+       # pre-seed with on disk backups
+       $all_backup_numbers->{ $_->{num} }++ foreach $bpc->BackupInfoRead($host);
+
+       while( my $row = $sth->fetchrow_hashref ) {
+warn "# row ",dump $row;
+               $all_backup_numbers->{ $row->{num} } =
+               $row->{inc_deleted}  ? 0 :
+               $row->{size}    == 0 ? 0 :
+               $row->{inc_size}!= 0 ? 0 :
+               $row->{size}     > 0 ? 1 :
+               0;
+       }
+
+warn "# host $host all_backup_numbers = ",dump($all_backup_numbers);
+       my @backup_nums = 
+               sort { $a <=> $b }
+               grep { $all_backup_numbers->{$_} }
+               keys %$all_backup_numbers;
+
+       return @backup_nums;
+}
+
 
 sub getBackupsNotBurned($) {