1 | package Sophie::Controller::Search::Rpms; |
---|
2 | use Moose; |
---|
3 | use namespace::autoclean; |
---|
4 | |
---|
5 | BEGIN {extends 'Catalyst::Controller'; } |
---|
6 | |
---|
7 | =head1 NAME |
---|
8 | |
---|
9 | Sophie::Controller::Search::Rpms - Catalyst Controller |
---|
10 | |
---|
11 | =head1 DESCRIPTION |
---|
12 | |
---|
13 | Catalyst Controller. |
---|
14 | |
---|
15 | =head1 METHODS |
---|
16 | |
---|
17 | =cut |
---|
18 | |
---|
19 | |
---|
20 | =head2 index |
---|
21 | |
---|
22 | =cut |
---|
23 | |
---|
24 | sub index :Path :Args(0) { |
---|
25 | my ( $self, $c ) = @_; |
---|
26 | |
---|
27 | $c->response->body('Matched Sophie::Controller::Search::Rpms in Search::Rpms.'); |
---|
28 | } |
---|
29 | |
---|
30 | sub 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 | |
---|
65 | Return a list of rpms files added since TIMESTAMP. |
---|
66 | TIMESTAMP must the number of second since 1970-01-01 (eq UNIX epoch). |
---|
67 | |
---|
68 | SEARCHSPEC is a struct with following key/value: |
---|
69 | |
---|
70 | =over 4 |
---|
71 | |
---|
72 | =item distribution |
---|
73 | |
---|
74 | Limit search to this distribution |
---|
75 | |
---|
76 | =item release |
---|
77 | |
---|
78 | Limit search to this release |
---|
79 | |
---|
80 | =item arch |
---|
81 | |
---|
82 | Limit search to distribution of this arch |
---|
83 | |
---|
84 | =item src |
---|
85 | |
---|
86 | If set to true, limit search to source package, If set to false, limit search to |
---|
87 | binary package. |
---|
88 | |
---|
89 | =item name |
---|
90 | |
---|
91 | Limit search to rpm having this name |
---|
92 | |
---|
93 | =item rows |
---|
94 | |
---|
95 | Set maximum of results, the default is 10000. |
---|
96 | |
---|
97 | =back |
---|
98 | |
---|
99 | Each elements of the output is a struct: |
---|
100 | |
---|
101 | =over 4 |
---|
102 | |
---|
103 | =item filename |
---|
104 | |
---|
105 | the rpm filename |
---|
106 | |
---|
107 | =item pkgid |
---|
108 | |
---|
109 | the identifier of the package |
---|
110 | |
---|
111 | =item distribution |
---|
112 | |
---|
113 | the distribution containing this package |
---|
114 | |
---|
115 | =item release |
---|
116 | |
---|
117 | the release containing this package |
---|
118 | |
---|
119 | =item arch |
---|
120 | |
---|
121 | the arch containing this package |
---|
122 | |
---|
123 | =item media |
---|
124 | |
---|
125 | the media containing this package |
---|
126 | |
---|
127 | =back |
---|
128 | |
---|
129 | =cut |
---|
130 | |
---|
131 | sub 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 | |
---|
144 | sub 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 | |
---|
157 | sub 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 | |
---|
170 | sub 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 | |
---|
187 | Olivier Thauvin |
---|
188 | |
---|
189 | =head1 LICENSE |
---|
190 | |
---|
191 | This library is free software. You can redistribute it and/or modify |
---|
192 | it under the same terms as Perl itself. |
---|
193 | |
---|
194 | =cut |
---|
195 | |
---|
196 | __PACKAGE__->meta->make_immutable; |
---|
197 | |
---|
198 | 1; |
---|