source: server/trunk/web/lib/Sophie/Controller/Search/Rpms.pm @ 157

Last change on this file since 157 was 157, checked in by nanardon, 14 years ago
File size: 3.9 KB
Line 
1package Sophie::Controller::Search::Rpms;
2use Moose;
3use namespace::autoclean;
4
5BEGIN {extends 'Catalyst::Controller'; }
6
7=head1 NAME
8
9Sophie::Controller::Search::Rpms - 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 index :Path :Args(0) {
25    my ( $self, $c ) = @_;
26
27    $c->response->body('Matched Sophie::Controller::Search::Rpms in Search::Rpms.');
28}
29
30sub rpms_rs : Private {
31    my ( $self, $c, $searchspec) = @_;
32    $searchspec ||= {};
33
34    return $c->forward('/distrib/distrib_rs', [ $searchspec ])
35        ->search_related('MediasPaths')
36        ->search_related('Paths')
37        ->search_related('Rpmfiles',
38            {
39                pkgid => {
40                    IN => $c->model('Base::Rpms')->search(
41                        {
42                            (exists($searchspec->{name})
43                                ? (name => $searchspec->{name})
44                                : ()
45                            ),
46                            (exists($searchspec->{src})
47                                ? (issrc => $searchspec->{src} ? 1 : 0)
48                                : ()
49                            ),
50                        }
51                    )->get_column('pkgid')->as_query,
52                }
53            },
54            {
55                select => [qw(filename pkgid name shortname version arch label) ],
56                as => [qw(filename pkgid distribution dist release arch media) ],
57                rows => $searchspec->{rows} || 10000,
58                order_by => [ 'Rpmfiles.added desc' ],
59            },
60        );
61}
62
63=head2 search.rpms.bydate (SEARCHSPEC, TIMESTAMP)
64
65Return a list of rpms files added since TIMESTAMP.
66TIMESTAMP must the number of second since 1970-01-01 (eq UNIX epoch).
67
68SEARCHSPEC is a struct with following key/value:
69
70=over 4
71
72=item distribution
73
74Limit search to this distribution
75
76=item release
77
78Limit search to this release
79
80=item arch
81
82Limit search to distribution of this arch
83
84=item src
85
86If set to true, limit search to source package, If set to false, limit search to
87binary package.
88
89=item name
90
91Limit search to rpm having this name
92
93=item rows
94
95Set maximum of results, the default is 10000.
96
97=back
98
99Each elements of the output is a struct:
100
101=over 4
102
103=item filename
104
105the rpm filename
106
107=item pkgid
108
109the identifier of the package
110
111=item distribution
112
113the distribution containing this package
114
115=item release
116
117the release containing this package
118
119=item arch
120
121the arch containing this package
122
123=item media
124
125the media containing this package
126
127=back
128
129=cut
130
131sub bydate : Private {
132    my ( $self, $c, $searchspec, $date ) = @_;
133    $searchspec ||= {};
134
135    return $c->stash->{xmlrpc} = [
136        map {
137            { 
138            $_->get_columns
139            }
140        }
141        $c->forward('bydate_rpc', [ $searchspec, $date ])->all ];
142}
143
144sub bydate_rpc : XMLRPCPath('bydate') {
145    my ( $self, $c, $searchspec, $date ) = @_;
146    $searchspec ||= {};
147
148    $c->stash->{rs} =
149        $c->forward('rpms_rs')->search({
150            -nest => \[
151                "Rpmfiles.added > '1970-01-01'::date + ?::interval",
152                [ plain_text => "$date seconds" ],   
153            ],
154        });
155}
156
157sub byfilename : Private {
158    my ( $self, $c, $searchspec, $file ) = @_;
159    $searchspec ||= {};
160
161    return $c->stash->{xmlrpc} = [
162        map {
163            { 
164            $_->get_columns
165            }
166        }
167        $c->forward('byfilename_rpc', [ $searchspec, $file ])->all ];
168}
169
170sub byfilename_rpc : XMLRPCPath('byfilename') {
171    my ( $self, $c, $searchspec, $file ) = @_;
172    $searchspec ||= {};
173
174    $c->stash->{rs} =
175        $c->forward('rpms_rs')->search(
176        {
177            filename => { LIKE => $file },
178        },
179        {
180            order_by => [ qw(filename) ],
181        }
182    );
183}
184
185=head1 AUTHOR
186
187Olivier Thauvin
188
189=head1 LICENSE
190
191This library is free software. You can redistribute it and/or modify
192it under the same terms as Perl itself.
193
194=cut
195
196__PACKAGE__->meta->make_immutable;
197
1981;
Note: See TracBrowser for help on using the repository browser.