source: server/trunk/web/lib/Sophie/Controller/0Explorer.pm @ 107

Last change on this file since 107 was 107, checked in by nanardon, 14 years ago
  • process uniq and sort on perl side to ligth db server works
File size: 2.6 KB
Line 
1package Sophie::Controller::0Explorer;
2use Moose;
3use namespace::autoclean;
4
5BEGIN {extends 'Catalyst::Controller'; }
6
7=head1 NAME
8
9Sophie::Controller::0Explorer - Catalyst Controller
10
11=head1 DESCRIPTION
12
13Catalyst Controller.
14
15=head1 METHODS
16
17=cut
18
19
20=head2 index
21
22=cut
23
24sub dir :Local {
25    my ( $self, $c, @args ) = @_;
26    my $dir = join('/', map { "$_" } grep { $_ } @args);
27    $c->stash->{path} = $dir;
28    $c->stash->{explorerurl} = '/explorer' . ($dir ? "/$dir" : '');
29
30    my $rsdist = $c->forward('/search/distrib_search', [
31            $c->session->{__explorer}, 1 ]);
32    my %uniq;
33    foreach (
34        $c->model('Base')
35        ->resultset('Files')
36        ->search(
37            {
38                dirname => '/' . ($dir ? "$dir/" : ''),
39                ($rsdist 
40                    ? (pkgid => { IN => $rsdist->get_column('pkgid')->as_query, },)
41                    : ()),
42                ($c->req->param('filename')
43                    ? ( basename => { LIKE => $c->req->param('filename') . '%' } )
44                    : ()),
45            },
46            {
47                #order_by => [ 'basename' ],
48                #group_by => [ 'basename' ],
49                select => [ 'basename' ],
50            }
51        )->get_column('basename')->all) {
52        $uniq{$_} = 1;
53    }
54    $c->stash->{xmlrpc} = [ sort keys %uniq ]; 
55}
56
57sub file :Local {
58    my ( $self, $c, @args ) = @_;
59    my $basename = pop(@args);
60    my $dir = join('/', map { "$_" } grep { $_ } @args);
61    $c->stash->{path} = $dir;
62    $c->stash->{explorerurl} = '/explorer' . ($dir ? "/$dir" : '');
63
64    my $rsdist = $c->forward('/search/distrib_search', [
65            $c->session->{__explorer}, 1 ]);
66
67    my @col = qw(dirname basename md5 size pkgid count);
68    $c->stash->{xmlrpc} = [ 
69        map { {
70                $_->get_columns
71            } }
72        $c->model('Base')
73      ->resultset('Files')
74      ->search({
75              dirname => '/' . ($dir ? "$dir/" : ''), basename => $basename,
76              ($rsdist 
77                ? (pkgid => { IN => $rsdist->get_column('pkgid')->as_query, },)
78                : ())
79          },
80          { 
81              'select' => [ 'contents is NOT NULL as has_content', 'rpmfilesmode(mode) as perm', @col, '"group"',
82                  '"user"' ],
83              as => [ qw(has_content perm), @col, 'group', 'user' ],
84              order_by => [ 'pkgid' ],
85
86          },
87      )->all ];
88}
89
90=head1 AUTHOR
91
92Olivier Thauvin
93
94=head1 LICENSE
95
96This library is free software. You can redistribute it and/or modify
97it under the same terms as Perl itself.
98
99=cut
100
101__PACKAGE__->meta->make_immutable;
102
1031;
Note: See TracBrowser for help on using the repository browser.