1 | package Sophie::Controller::Sources; |
---|
2 | use Moose; |
---|
3 | use namespace::autoclean; |
---|
4 | |
---|
5 | BEGIN {extends 'Catalyst::Controller'; } |
---|
6 | |
---|
7 | =head1 NAME |
---|
8 | |
---|
9 | Sophie::Controller::Sources - 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 | if ($c->req->param('search')) { |
---|
28 | $c->stash->{xmlrpc} = [ $c->model('Base::Rpms') |
---|
29 | ->search( |
---|
30 | { |
---|
31 | name => { 'LIKE' => $c->req->param('search') . '%' }, |
---|
32 | issrc => 1, |
---|
33 | }, |
---|
34 | { |
---|
35 | group_by => [ qw(name) ], |
---|
36 | select => [ qw(name) ], |
---|
37 | order_by => [ qw(name) ], |
---|
38 | } |
---|
39 | )->get_column('name')->all ]; |
---|
40 | } else { |
---|
41 | $c->stash->{xmlrpc} = []; |
---|
42 | } |
---|
43 | } |
---|
44 | |
---|
45 | sub srcfiles : XMLRPCLocal { |
---|
46 | my ($self, $c, $searchspec, $name) = @_; |
---|
47 | |
---|
48 | my $distrs = $c->forward('/search/distrib_search', [ $searchspec, 1 ]); |
---|
49 | my $rpmrs = ($distrs |
---|
50 | ? $distrs->search_related('RpmsFile') |
---|
51 | : undef); |
---|
52 | |
---|
53 | $c->stash->{xmlrpc} = [ |
---|
54 | map { |
---|
55 | { $_->get_columns } |
---|
56 | } |
---|
57 | |
---|
58 | $c->model('Base::Rpms') |
---|
59 | ->search( |
---|
60 | { |
---|
61 | name => $name, |
---|
62 | issrc => 1, |
---|
63 | $rpmrs |
---|
64 | ? (pkgid => { IN => $rpmrs->get_column('pkgid')->as_query },) |
---|
65 | : (), |
---|
66 | }, |
---|
67 | { |
---|
68 | select => [ 'evr' ], |
---|
69 | } |
---|
70 | )->search_related('SrcFiles')->search( |
---|
71 | { |
---|
72 | #has_content => 1, |
---|
73 | }, |
---|
74 | { |
---|
75 | select => [ 'basename', 'evr', 'SrcFiles.pkgid' ], |
---|
76 | group_by => [ 'basename', 'evr', 'SrcFiles.pkgid' ], |
---|
77 | order_by => [ 'evr using >>', 'basename' ], |
---|
78 | } |
---|
79 | )->all ]; |
---|
80 | } |
---|
81 | |
---|
82 | sub srcfilesbyfile : XMLRPCLocal { |
---|
83 | my ($self, $c, $searchspec, $name, $filename) = @_; |
---|
84 | |
---|
85 | my $distrs = $c->forward('/search/distrib_search', [ $searchspec, 1 ]); |
---|
86 | my $rpmrs = ($distrs |
---|
87 | ? $distrs->search_related('RpmsFile') |
---|
88 | : undef); |
---|
89 | |
---|
90 | $c->stash->{xmlrpc} = [ |
---|
91 | map { |
---|
92 | { $_->get_columns } |
---|
93 | } |
---|
94 | |
---|
95 | $c->model('Base::Rpms') |
---|
96 | ->search( |
---|
97 | { |
---|
98 | name => $name, |
---|
99 | issrc => 1, |
---|
100 | $rpmrs |
---|
101 | ? (pkgid => { IN => $rpmrs->get_column('pkgid')->as_query },) |
---|
102 | : (), |
---|
103 | }, |
---|
104 | { |
---|
105 | select => [ 'evr' ], |
---|
106 | } |
---|
107 | )->search_related('SrcFiles')->search( |
---|
108 | { |
---|
109 | has_content => 1, |
---|
110 | basename => $filename, |
---|
111 | }, |
---|
112 | { |
---|
113 | '+columns' => [ qw(me.evr) ], |
---|
114 | order_by => [ 'evr using >>' ], |
---|
115 | } |
---|
116 | )->all ]; |
---|
117 | |
---|
118 | } |
---|
119 | |
---|
120 | sub rpm_sources_ :PathPrefix :Chained :CaptureArgs(1) { |
---|
121 | my ($self, $c, $rpm) = @_; |
---|
122 | $c->stash->{rpm} = $rpm; |
---|
123 | } |
---|
124 | |
---|
125 | sub rpm_sources :Chained('rpm_sources_') :PathPart('') :Args(0) { |
---|
126 | my ($self, $c, $rpm) = @_; |
---|
127 | |
---|
128 | $c->forward('srcfiles', [ {}, $c->stash->{rpm} ]); |
---|
129 | |
---|
130 | } |
---|
131 | |
---|
132 | sub rpm_sources_file_ :Chained('rpm_sources_') :PathPart('') :CaptureArgs(1) { |
---|
133 | my ($self, $c, $filename) = @_; |
---|
134 | $c->stash->{filename} = $filename; |
---|
135 | |
---|
136 | $c->stash->{list} = $c->forward('srcfilesbyfile', [ {}, |
---|
137 | $c->stash->{rpm}, $c->stash->{filename} ] ); |
---|
138 | } |
---|
139 | |
---|
140 | sub rpm_sources_file :Chained('rpm_sources_file_') :PathPart('') :Args(0) { |
---|
141 | my ($self, $c ) = @_; |
---|
142 | |
---|
143 | #$c->forward('srcfilesbyfile', [ {}, |
---|
144 | # $c->stash->{rpm}, $c->stash->{filename} ] ); |
---|
145 | |
---|
146 | } |
---|
147 | |
---|
148 | sub rpm_sources_file_pkg_ :Chained('rpm_sources_file_') :PathPart('') :CaptureArgs(1) { |
---|
149 | my ($self, $c, $pkgid) = @_; |
---|
150 | $c->stash->{pkgid} = $pkgid; |
---|
151 | $c->stash->{xmlrpc} = { $c->model('Base::SrcFiles')->find( |
---|
152 | { |
---|
153 | |
---|
154 | pkgid => $c->stash->{pkgid}, |
---|
155 | basename => $c->stash->{filename}, |
---|
156 | }, |
---|
157 | { |
---|
158 | '+columns' => ['contents'], |
---|
159 | } |
---|
160 | )->get_columns }; |
---|
161 | } |
---|
162 | |
---|
163 | sub rpm_sources_file_pkg :Chained('rpm_sources_file_pkg_') :PathPart('') :Args(0) { |
---|
164 | my ($self, $c) = @_; |
---|
165 | |
---|
166 | } |
---|
167 | |
---|
168 | =head1 AUTHOR |
---|
169 | |
---|
170 | Olivier Thauvin |
---|
171 | |
---|
172 | =head1 LICENSE |
---|
173 | |
---|
174 | This library is free software. You can redistribute it and/or modify |
---|
175 | it under the same terms as Perl itself. |
---|
176 | |
---|
177 | =cut |
---|
178 | |
---|
179 | __PACKAGE__->meta->make_immutable; |
---|
180 | |
---|
181 | 1; |
---|