1 | package Sophie::Controller::Distrib; |
---|
2 | use Moose; |
---|
3 | use namespace::autoclean; |
---|
4 | |
---|
5 | BEGIN {extends 'Catalyst::Controller'; } |
---|
6 | |
---|
7 | =head1 NAME |
---|
8 | |
---|
9 | Sophie::Controller::Distrib - Catalyst Controller |
---|
10 | |
---|
11 | =head1 DESCRIPTION |
---|
12 | |
---|
13 | Catalyst Controller. |
---|
14 | |
---|
15 | =head1 METHODS |
---|
16 | |
---|
17 | =cut |
---|
18 | |
---|
19 | sub list :XMLRPC { |
---|
20 | my ( $self, $c, $distrib, $release, $arch ) = @_; |
---|
21 | |
---|
22 | my $distribution; |
---|
23 | if (ref $distrib) { |
---|
24 | ($distribution, $release, $arch) = ( |
---|
25 | $distrib->{distribution}, |
---|
26 | $distrib->{release}, |
---|
27 | $distrib->{arch}, |
---|
28 | ); |
---|
29 | } else { |
---|
30 | $distribution = $distrib; |
---|
31 | } |
---|
32 | |
---|
33 | my $rs = $c->model('Base')->resultset('Distribution'); |
---|
34 | if (!$distribution) { |
---|
35 | return $c->stash->{xmlrpc} = [ map { $_->name } |
---|
36 | $rs->search(undef, { order_by => ['name'] })->all ]; |
---|
37 | } |
---|
38 | $rs = $rs->search({ |
---|
39 | -or => [ |
---|
40 | { name => $distribution }, |
---|
41 | { shortname => $distribution }, |
---|
42 | ], |
---|
43 | })->search_related('Release'); |
---|
44 | if (!$release) { |
---|
45 | return $c->stash->{xmlrpc} = [ map { $_->version } |
---|
46 | $rs->search(undef, { order_by => ['version'] })->all ]; |
---|
47 | } |
---|
48 | $rs = $rs->search(version => $release)->search_related('Arch'); |
---|
49 | if (!$arch) { |
---|
50 | return $c->stash->{xmlrpc} = [ map { $_->arch } |
---|
51 | $rs->search(undef, { order_by => ['arch'] })->all ]; |
---|
52 | } |
---|
53 | $rs = $rs->search(arch => $arch)->search_related('Medias'); |
---|
54 | return $c->stash->{xmlrpc} = [ map { $_->label } |
---|
55 | $rs->search(undef, { order_by => ['label'] })->all ]; |
---|
56 | } |
---|
57 | |
---|
58 | sub struct :XMLRPC { |
---|
59 | my ( $self, $c, $distribution, $release, $arch ) = @_; |
---|
60 | |
---|
61 | if (!ref $distribution) { |
---|
62 | $distribution = { |
---|
63 | distribution => $distribution, |
---|
64 | release => $release, |
---|
65 | arch => $arch, |
---|
66 | } |
---|
67 | } |
---|
68 | |
---|
69 | my $rs = $c->forward('distrib_rs', [ $distribution ]) |
---|
70 | ->search({}, { order_by => 'label' }); |
---|
71 | $c->stash->{xmlrpc} = [ map { |
---|
72 | { |
---|
73 | label => $_->label, |
---|
74 | group_label => $_->group_label, |
---|
75 | } |
---|
76 | } $rs->all ]; |
---|
77 | } |
---|
78 | |
---|
79 | sub distrib_rs : Private { |
---|
80 | my ( $self, $c, $distrib, $asfilter ) = @_; |
---|
81 | if ($asfilter && !( |
---|
82 | $distrib->{distribution} || |
---|
83 | $distrib->{release} || |
---|
84 | $distrib->{arch} || |
---|
85 | $distrib->{media} || |
---|
86 | $distrib->{media_group})) { |
---|
87 | return; |
---|
88 | } |
---|
89 | |
---|
90 | return $c->model('Base')->resultset('Distribution') |
---|
91 | ->search( |
---|
92 | { |
---|
93 | $distrib->{distribution} |
---|
94 | ? (-or => [ |
---|
95 | { name => $distrib->{distribution} }, |
---|
96 | { shortname => $distrib->{distribution} }, |
---|
97 | ], |
---|
98 | ) |
---|
99 | : () |
---|
100 | }, |
---|
101 | { |
---|
102 | select => [ qw(name shortname) ], |
---|
103 | } |
---|
104 | )->search_related('Release', |
---|
105 | { |
---|
106 | $distrib->{release} |
---|
107 | ? (version => $distrib->{release}) |
---|
108 | : () |
---|
109 | }, |
---|
110 | { |
---|
111 | select => [ qw(version) ], |
---|
112 | } |
---|
113 | )->search_related('Arch', |
---|
114 | { |
---|
115 | $distrib->{arch} |
---|
116 | ? (arch => $distrib->{arch}) |
---|
117 | : () |
---|
118 | }, |
---|
119 | { |
---|
120 | select => [ qw(arch) ], |
---|
121 | } |
---|
122 | )->search_related('Medias', |
---|
123 | { |
---|
124 | ($distrib->{media} ? (label => $distrib->{media}) : ()), |
---|
125 | ($distrib->{media_group} |
---|
126 | ? (group_label => $distrib->{media_group}) |
---|
127 | : ()), |
---|
128 | }, |
---|
129 | { |
---|
130 | select => [ qw(label group_label) ], |
---|
131 | } |
---|
132 | ); |
---|
133 | } |
---|
134 | |
---|
135 | |
---|
136 | sub exists : XMLRPC { |
---|
137 | my ( $self, $c, $d ) = @_; |
---|
138 | |
---|
139 | my $rs = $c->forward('distrib_rs', [ $d ]); |
---|
140 | |
---|
141 | if ($rs->search({}, { rows => 1 })->next) { |
---|
142 | $c->stash->{xmlrpc} = 1; |
---|
143 | } else { |
---|
144 | $c->stash->{xmlrpc} = 0; |
---|
145 | } |
---|
146 | } |
---|
147 | |
---|
148 | =head2 index |
---|
149 | |
---|
150 | =cut |
---|
151 | |
---|
152 | sub index :Path :Chained :Args(0) { |
---|
153 | my ( $self, $c ) = @_; |
---|
154 | |
---|
155 | $c->forward('list'); |
---|
156 | } |
---|
157 | |
---|
158 | =head release |
---|
159 | |
---|
160 | =cut |
---|
161 | |
---|
162 | sub list_release :Path :Args(1) { |
---|
163 | my ( $self, $c, $distribution ) = @_; |
---|
164 | $c->stash->{dist}{distribution} = $distribution; |
---|
165 | if (!$c->forward('exists', [ $c->stash->{dist} ])) { |
---|
166 | $c->go('/404/index'); |
---|
167 | } |
---|
168 | $c->forward('list', [ $c->stash->{dist} ] ); |
---|
169 | } |
---|
170 | |
---|
171 | sub list_arch :Path :Args(2) { |
---|
172 | my ( $self, $c, $distribution, $release ) = @_; |
---|
173 | $c->stash->{dist}{distribution} = $distribution; |
---|
174 | $c->stash->{dist}{release} = $release; |
---|
175 | $c->forward('list', [ $c->stash->{dist} ] ); |
---|
176 | } |
---|
177 | |
---|
178 | |
---|
179 | sub distrib_view :PathPrefix :Chained :CaptureArgs(3) { |
---|
180 | my ( $self, $c, $distribution, $release, $arch ) = @_; |
---|
181 | $c->stash->{dist}{distribution} = $distribution; |
---|
182 | $c->stash->{dist}{release} = $release; |
---|
183 | $c->stash->{dist}{arch} = $arch; |
---|
184 | $c->stash->{distrib} = $c->stash->{dist}; |
---|
185 | } |
---|
186 | |
---|
187 | sub distrib :Chained('distrib_view') PathPart('') :Args(0) { |
---|
188 | my ( $self, $c ) = @_; |
---|
189 | $c->forward('list', [ $c->stash->{dist} ]); |
---|
190 | # TODO store properly results |
---|
191 | # No call from json here |
---|
192 | } |
---|
193 | |
---|
194 | sub media :Chained('/distrib/distrib_view') PathPart('media') :Args(0) { |
---|
195 | my ( $self, $c ) = @_; |
---|
196 | $c->forward('struct', [ $c->stash->{dist} ]); |
---|
197 | } |
---|
198 | |
---|
199 | sub anyrpms :XMLRPC { |
---|
200 | my ( $self, $c, $distribution, $release, $arch ) = @_; |
---|
201 | |
---|
202 | if (!ref $distribution) { |
---|
203 | $distribution = { |
---|
204 | distribution => $distribution, |
---|
205 | release => $release, |
---|
206 | arch => $arch, |
---|
207 | } |
---|
208 | } |
---|
209 | |
---|
210 | @{$c->stash->{rpm}} = map { |
---|
211 | { |
---|
212 | pkgid => $_->pkgid, |
---|
213 | filename => $_->filename, |
---|
214 | } |
---|
215 | } |
---|
216 | $c->forward('distrib_rs', [ $distribution ]) |
---|
217 | ->search_related('MediasPaths') |
---|
218 | ->search_related('Paths') |
---|
219 | ->search_related('Rpmfiles') |
---|
220 | ->all; |
---|
221 | |
---|
222 | $c->stash->{xmlrpc} = $c->stash->{rpm}; |
---|
223 | } |
---|
224 | |
---|
225 | sub rpms :XMLRPC { |
---|
226 | my ( $self, $c, $distribution, $release, $arch ) = @_; |
---|
227 | |
---|
228 | if (!ref $distribution) { |
---|
229 | $distribution = { |
---|
230 | distribution => $distribution, |
---|
231 | release => $release, |
---|
232 | arch => $arch, |
---|
233 | } |
---|
234 | } |
---|
235 | |
---|
236 | $c->stash->{rpm} = [ map { |
---|
237 | { |
---|
238 | pkgid => $_->pkgid, |
---|
239 | filename => $_->filename, |
---|
240 | } |
---|
241 | } |
---|
242 | $c->forward('distrib_rs', [ $distribution ]) |
---|
243 | ->search_related('MediasPaths') |
---|
244 | ->search_related('Paths') |
---|
245 | ->search_related('Rpmfiles', { |
---|
246 | pkgid => { |
---|
247 | IN => $c->model('Base')->resultset('Rpms') |
---|
248 | ->search({ issrc => 'false' })->get_column('pkgid') ->as_query } |
---|
249 | } )->all ]; |
---|
250 | |
---|
251 | $c->stash->{xmlrpc} = $c->stash->{rpm}; |
---|
252 | } |
---|
253 | |
---|
254 | sub srpms :XMLRPC { |
---|
255 | my ( $self, $c, $distribution, $release, $arch ) = @_; |
---|
256 | |
---|
257 | if (!ref $distribution) { |
---|
258 | $distribution = { |
---|
259 | distribution => $distribution, |
---|
260 | release => $release, |
---|
261 | arch => $arch, |
---|
262 | } |
---|
263 | } |
---|
264 | |
---|
265 | @{$c->stash->{rpm}} = map { |
---|
266 | { |
---|
267 | pkgid => $_->pkgid, |
---|
268 | filename => $_->filename, |
---|
269 | } |
---|
270 | } |
---|
271 | $c->forward('distrib_rs', [ $distribution ]) |
---|
272 | ->search_related('MediasPaths') |
---|
273 | ->search_related('Paths') |
---|
274 | ->search_related('Rpmfiles', { |
---|
275 | pkgid => { |
---|
276 | IN => $c->model('Base')->resultset('Rpms') |
---|
277 | ->search({ issrc => 'true' })->get_column('pkgid') ->as_query } |
---|
278 | } )->all; |
---|
279 | |
---|
280 | $c->stash->{xmlrpc} = $c->stash->{rpm}; |
---|
281 | } |
---|
282 | |
---|
283 | sub rpms_name :XMLRPC { |
---|
284 | my ( $self, $c, $distribution, $release, $arch ) = @_; |
---|
285 | |
---|
286 | if (!ref $distribution) { |
---|
287 | $distribution = { |
---|
288 | distribution => $distribution, |
---|
289 | release => $release, |
---|
290 | arch => $arch, |
---|
291 | } |
---|
292 | } |
---|
293 | |
---|
294 | $c->stash->{xmlrpc} = [ |
---|
295 | $c->model('Base')->resultset('Rpms')->search( |
---|
296 | { pkgid => { |
---|
297 | IN => |
---|
298 | $c->forward('distrib_rs', [ $distribution ]) |
---|
299 | ->search_related('MediasPaths') |
---|
300 | ->search_related('Paths') |
---|
301 | ->search_related('Rpmfiles')->get_column('pkgid')->as_query |
---|
302 | } }, |
---|
303 | { group_by => [ qw(name) ], order_by => [ qw(name) ] } |
---|
304 | )->get_column('name')->all ]; |
---|
305 | } |
---|
306 | |
---|
307 | sub list_rpms :Chained('distrib_view') PathPart('rpms') Args(0) { |
---|
308 | my ( $self, $c ) = @_; |
---|
309 | $c->forward('rpms', $c->stash->{dist}); |
---|
310 | } |
---|
311 | |
---|
312 | sub list_srpms :Chained('distrib_view') PathPart('srpms') Args(0) { |
---|
313 | my ( $self, $c ) = @_; |
---|
314 | $c->forward('srpms', $c->stash->{dist}); |
---|
315 | } |
---|
316 | |
---|
317 | sub srpm_by_name :Chained('distrib_view') PathPart('srpms') { |
---|
318 | my ($self, $c, $name, @subpart) = @_; |
---|
319 | $c->stash->{dist}{src} = 1; |
---|
320 | ($c->stash->{pkgid}) = @{ $c->forward('/search/bytag', |
---|
321 | [ $c->stash->{dist}, 'name', $name ])->{results} }; |
---|
322 | $c->go('/404/index') unless ($c->stash->{pkgid}); |
---|
323 | $c->go('/rpms/rpms', [ $c->stash->{pkgid}, @subpart ]); |
---|
324 | } |
---|
325 | |
---|
326 | sub rpm_by_name :Chained('distrib_view') PathPart('rpms') { |
---|
327 | my ($self, $c, $name, @subpart) = @_; |
---|
328 | $c->stash->{dist}{src} = 0; |
---|
329 | ($c->stash->{pkgid}) = @{ $c->forward('/search/bytag', |
---|
330 | [ $c->stash->{dist}, 'name', $name ])->{results} }; |
---|
331 | $c->go('/404/index') unless ($c->stash->{pkgid}); |
---|
332 | $c->go('/rpms/rpms', [ $c->stash->{pkgid}, @subpart ]); |
---|
333 | } |
---|
334 | |
---|
335 | sub rpm_bypkgid :Chained('distrib_view') PathPart('by-pkgid') { |
---|
336 | my ( $self, $c, $pkgid, @subpart ) = @_; |
---|
337 | if ($pkgid) { |
---|
338 | if (@{ $c->forward('/search/bypkgid', |
---|
339 | [ $c->stash->{dist}, $pkgid ])->{results} } ) { |
---|
340 | $c->go('/rpms/rpms', [ $pkgid, @subpart ]); |
---|
341 | } else { |
---|
342 | $c->go('/404/index'); |
---|
343 | } |
---|
344 | } else { |
---|
345 | $c->forward('anyrpms', [ $c->stash->{dist} ]); |
---|
346 | } |
---|
347 | } |
---|
348 | |
---|
349 | sub _media_list_rpms :Chained('distrib_view') PathPart('media') CaptureArgs(1) { |
---|
350 | my ( $self, $c, $media ) = @_; |
---|
351 | $c->stash->{dist}{media} = $media; |
---|
352 | } |
---|
353 | |
---|
354 | sub media_list_rpms :Chained('_media_list_rpms') PathPart('') :Args(0) { |
---|
355 | my ( $self, $c ) = @_; |
---|
356 | $c->forward('anyrpms', [ $c->stash->{dist} ]); |
---|
357 | } |
---|
358 | |
---|
359 | sub media_rpm_byname :Chained('_media_list_rpms') PathPart('rpms') { |
---|
360 | my ( $self, $c, $name ) = @_; |
---|
361 | } |
---|
362 | sub media_srpm_byname :Chained('_media_list_rpms') PathPart('srpms') { |
---|
363 | my ( $self, $c, $name ) = @_; |
---|
364 | } |
---|
365 | |
---|
366 | sub media_rpm_bypkgid :Chained('_media_list_rpms') PathPart('by-pkgid') { |
---|
367 | my ( $self, $c, $pkgid, @part ) = @_; |
---|
368 | if ($pkgid) { |
---|
369 | if (@{ $c->forward('/search/bypkgid', [ $c->stash->{dist}, $pkgid |
---|
370 | ])->{results} } ) { |
---|
371 | $c->stash->{pkgid} = $pkgid; |
---|
372 | $c->go('/rpms/rpms', [ $pkgid, @part ]); |
---|
373 | } else { |
---|
374 | $c->go('/404/index'); |
---|
375 | } |
---|
376 | } else { |
---|
377 | $c->forward('anyrpms', [ $c->stash->{dist} ]); |
---|
378 | } |
---|
379 | } |
---|
380 | |
---|
381 | =head1 AUTHOR |
---|
382 | |
---|
383 | Olivier Thauvin |
---|
384 | |
---|
385 | =head1 LICENSE |
---|
386 | |
---|
387 | This library is free software. You can redistribute it and/or modify |
---|
388 | it under the same terms as Perl itself. |
---|
389 | |
---|
390 | =cut |
---|
391 | |
---|
392 | __PACKAGE__->meta->make_immutable; |
---|
393 | |
---|
394 | 1; |
---|